-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import pandas as pd | ||
|
||
|
||
def report_contiguous_dates( | ||
failed: pd.DataFrame, succeeded: pd.DataFrame | ||
) -> pd.DataFrame: | ||
return ( | ||
pd.concat( | ||
[ | ||
failed.assign(task_state="failed").rename( | ||
columns={"fail_date": "task_date"} | ||
), | ||
succeeded.assign(task_state="succeeded").rename( | ||
columns={"success_date": "task_date"} | ||
), | ||
] | ||
) | ||
.query("task_date.between('2019-01-01', '2019-12-31')") | ||
.sort_values(by="task_date") | ||
.assign(num=lambda x: x.task_date.rank() - x.index) | ||
.groupby(by=["num", "task_state"]) | ||
.agg( | ||
start_date=("task_date", "min"), | ||
end_date=("task_date", "max"), | ||
) | ||
.reset_index(names=["num", "period_state"]) | ||
.drop(columns="num") | ||
.sort_values(by="start_date") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
WITH TasksStates AS ( | ||
SELECT fail_date AS task_date, | ||
"failed" AS task_state, | ||
ROW_NUMBER() OVER (ORDER BY fail_date) AS num | ||
FROM Failed | ||
WHERE fail_date BETWEEN '2019-01-01' AND '2019-12-31' | ||
UNION ALL | ||
SELECT success_date AS task_date, | ||
"succeeded" AS task_state, | ||
ROW_NUMBER() OVER (ORDER BY success_date) AS num | ||
FROM Succeeded | ||
WHERE success_date BETWEEN '2019-01-01' AND '2019-12-31' | ||
), Tasks AS ( | ||
SELECT task_state, task_date, | ||
ROW_NUMBER() OVER (ORDER BY task_date) - num AS num | ||
FROM TasksStates | ||
) | ||
SELECT task_state AS period_state, | ||
MIN(task_date) AS start_date, | ||
MAX(task_date) AS end_date | ||
FROM Tasks | ||
GROUP BY num, task_state | ||
ORDER BY start_date; |