forked from russss/covidtracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscore.py
57 lines (52 loc) · 1.84 KB
/
score.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import pandas as pd
PROVISIONAL_DAYS = 5
def calculate_score(cases, triage_online, triage_pathways, admissions):
cases_change = (
cases["cases_rolling"][:, :-PROVISIONAL_DAYS]
/ cases["cases_rolling"][:, :-PROVISIONAL_DAYS].shift(date=7)
).dropna("date") - 1
online_change = (
(
triage_online["count_rolling_7"]
/ triage_online["count_rolling_7"].shift(date=7)
).dropna("date")
- 1
if triage_online
else None
)
pathways_change = (
(
triage_pathways["count_rolling_7"]
/ triage_pathways["count_rolling_7"].shift(date=7)
).dropna("date")
- 1
if triage_pathways
else None
)
admissions_change = (
admissions["admissions_rolling"]
/ admissions["admissions_rolling"].shift(date=7)
).dropna("date") - 1
data = {"scores": {}}
for loc in [loc.item() for loc in cases_change["location"]]:
data["scores"][loc] = {
"cases": cases_change[:, -1].sel(location=loc).item() * 100,
"triage_online": online_change[:, -1].sel(region=loc).item() * 100
if triage_online
else None,
"triage_pathways": pathways_change[:, -1].sel(region=loc).item() * 100
if triage_pathways
else None,
"admissions": admissions_change[:, -1].sel(location=loc).item() * 100,
}
data["dates"] = {
"cases": pd.to_datetime(cases_change[:, -1]["date"].data),
"triage_online": pd.to_datetime(online_change[:, -1]["date"].data)
if triage_online
else None,
"triage_pathways": pd.to_datetime(pathways_change[:, -1]["date"].data)
if triage_pathways
else None,
"admissions": pd.to_datetime(admissions_change[:, -1]["date"].data),
}
return data