|
1 | 1 | """Tests."""
|
2 | 2 |
|
| 3 | +from math import ceil # type: ignore |
| 4 | +import datetime # type: ignore |
3 | 5 | import pytest # type: ignore
|
4 | 6 | import pandas as pd # type: ignore
|
5 | 7 | import numpy as np # type: ignore
|
6 | 8 | import altair as alt # type: ignore
|
7 | 9 |
|
8 |
| -from src.penn_chime.charts import new_admissions_chart, admitted_patients_chart |
| 10 | +from src.penn_chime.charts import new_admissions_chart, admitted_patients_chart, chart_descriptions |
9 | 11 | from src.penn_chime.models import sir, sim_sir, build_admissions_df
|
10 | 12 | from src.penn_chime.parameters import Parameters
|
11 | 13 | from src.penn_chime.presentation import display_header
|
@@ -254,3 +256,41 @@ def test_parameters():
|
254 | 256 | 0.05 * 0.05 * (param.infected_v[1:-1] + param.recovered_v[1:-1]) - 100
|
255 | 257 | )
|
256 | 258 | assert (diff.abs() < 0.1).all()
|
| 259 | + assert len(param.susceptible_v) == len(param.infected_v) == len(param.recovered_v) == param.n_days + 1 == 3 |
| 260 | + |
| 261 | + |
| 262 | +def test_chart_descriptions(): |
| 263 | + # new admissions chart |
| 264 | + projection_admits = pd.read_csv('tests/projection_admits.csv') |
| 265 | + projection_admits = projection_admits.rename(columns={'hosp': 'Hospitalized', 'icu': 'ICU', 'vent': 'Ventilated'}) |
| 266 | + chart = new_admissions_chart(alt, projection_admits, PARAM) |
| 267 | + description = chart_descriptions(chart) |
| 268 | + |
| 269 | + hosp, icu, vent, asterisk = description.split("\n\n") # break out the description into lines |
| 270 | + |
| 271 | + max_hosp = chart.data['Hospitalized'].max() |
| 272 | + assert str(ceil(max_hosp)) in hosp |
| 273 | + |
| 274 | + max_icu_ix = chart.data['ICU'].idxmax() |
| 275 | + assert max_icu_ix + 1 == len(chart.data) |
| 276 | + assert "*" in icu |
| 277 | + |
| 278 | + # test asterisk |
| 279 | + param = PARAM |
| 280 | + param.n_days = 600 |
| 281 | + |
| 282 | + projection_admits = pd.read_csv('tests/projection_admits.csv') |
| 283 | + projection_admits = projection_admits.rename(columns={'hosp': 'Hospitalized', 'icu': 'ICU', 'vent': 'Ventilated'}) |
| 284 | + chart = new_admissions_chart(alt, projection_admits, PARAM) |
| 285 | + description = chart_descriptions(chart) |
| 286 | + assert "*" not in description |
| 287 | + |
| 288 | + # census chart |
| 289 | + census_df = pd.read_csv('tests/census_df.csv') |
| 290 | + census_df = census_df.rename(columns={'hosp': 'Hospitalized', 'icu': 'ICU', 'vent': 'Ventilated'}) |
| 291 | + chart = admitted_patients_chart(alt, census_df, PARAM, as_date=True) |
| 292 | + description = chart_descriptions(chart) |
| 293 | + |
| 294 | + assert str(ceil(chart.data['Ventilated'].max())) in description |
| 295 | + assert str(chart.data['ICU'].idxmax()) not in description |
| 296 | + assert datetime.datetime.strftime(chart.data.iloc[chart.data['ICU'].idxmax()].date, '%b %d') in description |
0 commit comments