|
15 | 15 | RateLos = namedtuple('RateLos', ('rate', 'length_of_stay'))
|
16 | 16 |
|
17 | 17 |
|
18 |
| -def build_admissions_df(p) -> pd.DataFrame: |
19 |
| - """Build admissions dataframe from Parameters.""" |
20 |
| - days = np.array(range(0, p.n_days + 1)) |
21 |
| - data_dict = dict(zip(["day", "Hospitalized", "ICU", "Ventilated"], |
22 |
| - [days] + [disposition for disposition in p.dispositions] |
23 |
| - )) |
24 |
| - projection = pd.DataFrame.from_dict(data_dict) |
25 |
| - # New cases |
26 |
| - projection_admits = projection.iloc[:-1, :] - projection.shift(1) |
27 |
| - projection_admits[projection_admits < 0] = 0 |
28 |
| - projection_admits["day"] = range(projection_admits.shape[0]) |
29 |
| - return projection_admits |
30 |
| - |
31 |
| - |
32 |
| -def build_census_df( |
33 |
| - projection_admits: pd.DataFrame, |
34 |
| - parameters |
35 |
| -) -> pd.DataFrame: |
36 |
| - """ALOS for each category of COVID-19 case (total guesses)""" |
37 |
| - n_days = np.shape(projection_admits)[0] |
38 |
| - hosp_los, icu_los, vent_los = parameters.lengths_of_stay |
39 |
| - los_dict = { |
40 |
| - "Hospitalized": hosp_los, |
41 |
| - "ICU": icu_los, |
42 |
| - "Ventilated": vent_los, |
43 |
| - } |
44 |
| - |
45 |
| - census_dict = dict() |
46 |
| - for k, los in los_dict.items(): |
47 |
| - census = ( |
48 |
| - projection_admits.cumsum().iloc[:-los, :] |
49 |
| - - projection_admits.cumsum().shift(los).fillna(0) |
50 |
| - ).apply(np.ceil) |
51 |
| - census_dict[k] = census[k] |
52 |
| - |
53 |
| - census_df = pd.DataFrame(census_dict) |
54 |
| - census_df["day"] = census_df.index |
55 |
| - census_df = census_df[["day", "Hospitalized", "ICU", "Ventilated"]] |
56 |
| - census_df = census_df.head(n_days) |
57 |
| - census_df = census_df.rename( |
58 |
| - columns={disposition: f"{disposition} Census" |
59 |
| - for disposition |
60 |
| - in ("Hospitalized", "ICU", "Ventilated")} |
61 |
| - ) |
62 |
| - return census_df |
63 |
| - |
64 | 18 |
|
65 | 19 | def add_date_column(
|
66 | 20 | df: pd.DataFrame,
|
|
0 commit comments