1
-
2
1
from datetime import datetime
3
2
from math import ceil
4
3
from typing import Dict , Optional
12
11
13
12
14
13
def build_admits_chart (
15
- * ,
16
- alt ,
17
- admits_floor_df : pd .DataFrame ,
18
- max_y_axis : Optional [int ] = None ,
14
+ * , alt , admits_floor_df : pd .DataFrame , max_y_axis : Optional [int ] = None
19
15
) -> Chart :
20
16
"""Build admits chart."""
21
17
y_scale = alt .Scale ()
@@ -25,14 +21,26 @@ def build_admits_chart(
25
21
x = dict (shorthand = "date:T" , title = "Date" , axis = alt .Axis (format = (DATE_FORMAT )))
26
22
y = dict (shorthand = "value:Q" , title = "Daily admissions" , scale = y_scale )
27
23
color = "key:N"
28
- tooltip = ["date:T" , alt .Tooltip ("value:Q" , format = ".0f" , title = "Admit" ), "key:N" ]
24
+ tooltip = ["date:T" , alt .Tooltip ("value:Q" , format = ".0f" , title = "Admit" ), "key:N" ]
29
25
30
26
# TODO fix the fold to allow any number of dispositions
31
27
points = (
32
28
alt .Chart ()
33
29
.transform_fold (fold = ["hospitalized" , "icu" , "ventilated" ])
34
30
.encode (x = alt .X (** x ), y = alt .Y (** y ), color = color , tooltip = tooltip )
35
31
.mark_line (point = True )
32
+ .encode (
33
+ x = alt .X (** x_kwargs ),
34
+ y = alt .Y ("value:Q" , title = "Daily admissions" , scale = y_scale ),
35
+ color = "key:N" ,
36
+ tooltip = [
37
+ tooltip_dict [as_date ],
38
+ alt .Tooltip ("value:Q" , format = ".0f" , title = "Admissions" ),
39
+ "key:N" ,
40
+ ],
41
+ )
42
+ .configure_legend (orient = "bottom" )
43
+ .interactive ()
36
44
)
37
45
bar = (
38
46
alt .Chart ()
@@ -43,12 +51,8 @@ def build_admits_chart(
43
51
return alt .layer (points , bar , data = admits_floor_df )
44
52
45
53
46
-
47
54
def build_census_chart (
48
- * ,
49
- alt ,
50
- census_floor_df : pd .DataFrame ,
51
- max_y_axis : Optional [int ] = None ,
55
+ * , alt , census_floor_df : pd .DataFrame , max_y_axis : Optional [int ] = None
52
56
) -> Chart :
53
57
"""Build census chart."""
54
58
y_scale = alt .Scale ()
@@ -66,6 +70,18 @@ def build_census_chart(
66
70
.transform_fold (fold = ["hospitalized" , "icu" , "ventilated" ])
67
71
.encode (x = alt .X (** x ), y = alt .Y (** y ), color = color , tooltip = tooltip )
68
72
.mark_line (point = True )
73
+ .encode (
74
+ x = alt .X (** x_kwargs ),
75
+ y = alt .Y ("value:Q" , title = "Census" , scale = y_scale ),
76
+ color = "key:N" ,
77
+ tooltip = [
78
+ idx ,
79
+ alt .Tooltip ("value:Q" , format = ".0f" , title = "Census" ),
80
+ "key:N" ,
81
+ ],
82
+ )
83
+ .configure_legend (orient = "bottom" )
84
+ .interactive ()
69
85
)
70
86
bar = (
71
87
alt .Chart ()
@@ -77,10 +93,7 @@ def build_census_chart(
77
93
78
94
79
95
def build_sim_sir_w_date_chart (
80
- * ,
81
- alt ,
82
- sim_sir_w_date_floor_df : pd .DataFrame ,
83
- max_y_axis : Optional [int ] = None ,
96
+ * , alt , sim_sir_w_date_floor_df : pd .DataFrame , max_y_axis : Optional [int ] = None
84
97
) -> Chart :
85
98
"""Build sim sir w date chart."""
86
99
y_scale = alt .Scale ()
@@ -98,6 +111,14 @@ def build_sim_sir_w_date_chart(
98
111
.transform_fold (fold = ["susceptible" , "infected" , "recovered" ])
99
112
.encode (x = alt .X (** x ), y = alt .Y (** y ), color = color , tooltip = tooltip )
100
113
.mark_line ()
114
+ .encode (
115
+ x = alt .X (** x_kwargs ),
116
+ y = alt .Y ("value:Q" , title = "Case Volume" , scale = y_scale ),
117
+ tooltip = ["key:N" , "value:Q" ],
118
+ color = "key:N" ,
119
+ )
120
+ .configure_legend (orient = "bottom" )
121
+ .interactive ()
101
122
)
102
123
bar = (
103
124
alt .Chart ()
@@ -109,10 +130,7 @@ def build_sim_sir_w_date_chart(
109
130
110
131
111
132
def build_descriptions (
112
- * ,
113
- chart : Chart ,
114
- labels : Dict [str , str ],
115
- suffix : str = ""
133
+ * , chart : Chart , labels : Dict [str , str ], suffix : str = ""
116
134
) -> str :
117
135
"""
118
136
@@ -146,15 +164,14 @@ def build_descriptions(
146
164
)
147
165
148
166
if asterisk :
149
- messages .append ("_* The max is at the upper bound of the data, and therefore may not be the actual max_" )
167
+ messages .append (
168
+ "_* The max is at the upper bound of the data, and therefore may not be the actual max_"
169
+ )
150
170
return "\n \n " .join (messages )
151
171
152
172
153
173
def build_table (
154
- * ,
155
- df : pd .DataFrame ,
156
- labels : Dict [str , str ],
157
- modulo : int = 1 ,
174
+ * , df : pd .DataFrame , labels : Dict [str , str ], modulo : int = 1
158
175
) -> pd .DataFrame :
159
176
table_df = df [np .mod (df .day , modulo ) == 0 ].copy ()
160
177
table_df .date = table_df .date .dt .strftime (DATE_FORMAT )
0 commit comments