Skip to content

Commit eff8a7d

Browse files
author
PJ Hoberman
committed
#179 chart tests
- Added test_admitted_patients_chart - Moved projection_admits and census_df to csv files to avoid using constants from settings.py or app.py
1 parent d621775 commit eff8a7d

File tree

3 files changed

+145
-4
lines changed

3 files changed

+145
-4
lines changed

src/test_app.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
import pandas as pd
55
import numpy as np
66

7-
from app import (projection_admits, alt)
7+
from app import alt
88
from penn_chime.models import sir, sim_sir, sim_sir_df
99
from penn_chime.parameters import Parameters
10-
from penn_chime.presentation import display_header, new_admissions_chart
10+
from penn_chime.presentation import display_header, new_admissions_chart, admitted_patients_chart
1111
from penn_chime.settings import DEFAULTS
1212
from penn_chime.defaults import RateLos
1313

@@ -145,7 +145,6 @@ def test_sim_sir():
145145
assert isinstance(v, np.ndarray)
146146

147147

148-
149148
def test_sim_sir_df():
150149
"""
151150
Rounding to move fast past decimal place issues
@@ -163,17 +162,35 @@ def test_sim_sir_df():
163162

164163

165164
def test_new_admissions_chart():
165+
projection_admits = pd.read_csv('src/tests/projection_admits.csv')
166166
chart = new_admissions_chart(alt, projection_admits, 60 - 10)
167167
assert isinstance(chart, alt.Chart)
168168
assert chart.data.iloc[1].Hospitalized < 1
169-
# assert round(chart.data.iloc[49].ICU, 0) == 43
169+
assert round(chart.data.iloc[40].ICU, 0) == 25
170+
171+
# test fx call with no params
170172
with pytest.raises(TypeError):
171173
new_admissions_chart()
172174

173175
empty_chart = new_admissions_chart(alt, pd.DataFrame(), -1)
174176
assert empty_chart.data.empty
175177

176178

179+
def test_admitted_patients_chart():
180+
census_df = pd.read_csv('src/tests/census_df.csv')
181+
chart = admitted_patients_chart(alt, census_df, 60 - 10)
182+
assert isinstance(chart, alt.Chart)
183+
assert chart.data.iloc[1]['Hospital Census'] == 1
184+
assert chart.data.iloc[49]['Ventilated Census'] == 203
185+
186+
# test fx call with no params
187+
with pytest.raises(TypeError):
188+
admitted_patients_chart()
189+
190+
empty_chart = admitted_patients_chart(alt, pd.DataFrame(), -1)
191+
assert empty_chart.data.empty
192+
193+
177194
def test_parameters():
178195
param = Parameters(
179196
current_hospitalized=100,

src/tests/census_df.csv

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
,day,hosp,icu,vent
2+
0,0,,,
3+
1,1,1.0,1.0,1.0
4+
2,2,2.0,1.0,1.0
5+
3,3,3.0,1.0,1.0
6+
4,4,4.0,2.0,1.0
7+
5,5,5.0,2.0,1.0
8+
6,6,6.0,3.0,2.0
9+
7,7,8.0,3.0,2.0
10+
8,8,9.0,4.0,2.0
11+
9,9,10.0,5.0,3.0
12+
10,10,11.0,5.0,3.0
13+
11,11,12.0,6.0,3.0
14+
12,12,14.0,7.0,4.0
15+
13,13,15.0,7.0,4.0
16+
14,14,17.0,8.0,5.0
17+
15,15,19.0,9.0,5.0
18+
16,16,22.0,10.0,6.0
19+
17,17,24.0,12.0,6.0
20+
18,18,27.0,13.0,7.0
21+
19,19,30.0,14.0,8.0
22+
20,20,34.0,16.0,9.0
23+
21,21,38.0,18.0,10.0
24+
22,22,42.0,20.0,11.0
25+
23,23,48.0,22.0,12.0
26+
24,24,53.0,25.0,14.0
27+
25,25,60.0,28.0,15.0
28+
26,26,67.0,31.0,17.0
29+
27,27,75.0,35.0,19.0
30+
28,28,84.0,39.0,21.0
31+
29,29,94.0,44.0,24.0
32+
30,30,105.0,49.0,26.0
33+
31,31,118.0,55.0,29.0
34+
32,32,132.0,62.0,33.0
35+
33,33,147.0,69.0,37.0
36+
34,34,165.0,77.0,41.0
37+
35,35,184.0,86.0,46.0
38+
36,36,206.0,96.0,51.0
39+
37,37,230.0,108.0,57.0
40+
38,38,256.0,120.0,64.0
41+
39,39,286.0,134.0,71.0
42+
40,40,319.0,149.0,80.0
43+
41,41,355.0,167.0,89.0
44+
42,42,395.0,185.0,99.0
45+
43,43,439.0,206.0,110.0
46+
44,44,488.0,229.0,122.0
47+
45,45,541.0,254.0,135.0
48+
46,46,599.0,282.0,150.0
49+
47,47,662.0,312.0,166.0
50+
48,48,731.0,345.0,184.0
51+
49,49,806.0,380.0,203.0
52+
50,50,886.0,418.0,223.0
53+
51,51,971.0,460.0,
54+
52,52,1062.0,,
55+
53,53,1159.0,,
56+
54,54,,,
57+
55,55,,,
58+
56,56,,,
59+
57,57,,,
60+
58,58,,,
61+
59,59,,,
62+
60,60,,,

src/tests/projection_admits.csv

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
,day,hosp,icu,vent
2+
0,0,,,
3+
1,1,0.7347722898562381,0.29390891594249524,0.14695445797124762
4+
2,2,0.8247048404412878,0.3298819361765153,0.16494096808825764
5+
3,3,0.925631917053221,0.37025276682128805,0.18512638341064402
6+
4,4,1.0388943119331255,0.4155577247732505,0.20777886238662524
7+
5,5,1.1659954645505692,0.4663981858202275,0.23319909291011376
8+
6,6,1.3086209670885331,0.5234483868354127,0.26172419341770636
9+
7,7,1.4686603504707918,0.5874641401883167,0.29373207009415836
10+
8,8,1.6482314021401603,0.6592925608560645,0.32964628042803223
11+
9,9,1.8497072903287552,0.7398829161315037,0.36994145806575185
12+
10,10,2.075746794129696,0.8302987176518766,0.4151493588259383
13+
11,11,2.329327963945971,0.9317311855783883,0.46586559278919415
14+
12,12,2.61378556236113,1.0455142249444513,0.5227571124722257
15+
13,13,2.932852660451122,1.1731410641804523,0.5865705320902261
16+
14,14,3.2907067880796568,1.3162827152318588,0.6581413576159294
17+
15,15,3.692021057497506,1.476808422999003,0.7384042114995015
18+
16,16,4.142020695886615,1.6568082783546476,0.8284041391773238
19+
17,17,4.646545432100844,1.8586181728403375,0.9293090864201687
20+
18,18,5.212118182837166,2.0848472731348657,1.0424236365674329
21+
19,19,5.846020470068794,2.3384081880275147,1.1692040940137574
22+
20,20,6.556374969989172,2.622549987995672,1.311274993997836
23+
21,21,7.352235537885861,2.9408942151543442,1.4704471075771721
24+
22,22,8.243684965656087,3.2974739862624354,1.6487369931312177
25+
23,23,9.24194059957226,3.6967762398288997,1.8483881199144498
26+
24,24,10.35946776360953,4.143787105443813,2.0718935527219067
27+
25,25,11.610100683671433,4.644040273468569,2.3220201367342845
28+
26,26,13.009170272720908,5.203668109088369,2.6018340545441845
29+
27,27,14.57363769481826,5.8294550779272996,2.9147275389636498
30+
28,28,16.32223205189976,6.528892820759907,3.2644464103799535
31+
29,29,18.275589800725783,7.310235920290317,3.6551179601451587
32+
30,30,20.45639257382453,8.182557029529804,4.091278514764902
33+
31,31,22.889498907537188,9.155799563014867,4.577899781507433
34+
32,32,25.602063927916674,10.240825571166681,5.120412785583341
35+
33,33,28.623639263122044,11.449455705248809,5.7247278526244045
36+
34,34,31.986243289314473,12.794497315725806,6.397248657862903
37+
35,35,35.72438922785608,14.289755691142432,7.144877845571216
38+
36,36,39.875055553763275,15.950022221505293,7.9750111107526465
39+
37,37,44.47757962283373,17.79103184913353,8.895515924566766
40+
38,38,49.573451377900426,19.829380551160142,9.914690275580071
41+
39,39,55.20597949586033,22.082391798344105,11.041195899172052
42+
40,40,61.41979749256973,24.56791899702793,12.283959498513966
43+
41,41,68.26017230956847,27.304068923827344,13.652034461913672
44+
42,42,75.77207308773609,30.308829235094493,15.154414617547246
45+
43,43,83.9989536775131,33.599581471005195,16.799790735502597
46+
44,44,92.98119964480816,37.192479857923274,18.596239928961637
47+
45,45,102.75419006634718,41.10167602653888,20.55083801326944
48+
46,46,113.34592752723552,45.33837101089421,22.669185505447103
49+
47,47,124.77419801601036,49.90967920640412,24.95483960320206
50+
48,48,137.04323774220597,54.81729509688239,27.408647548441195
51+
49,49,150.13990838845984,60.05596335538394,30.02798167769197
52+
50,50,164.02941811859068,65.61176724743632,32.80588362371816
53+
51,51,178.65067471298744,71.46026988519498,35.73013494259749
54+
52,52,193.91142069932403,77.56456827972954,38.78228413986477
55+
53,53,209.6833781349851,83.87335125399409,41.936675626997044
56+
54,54,225.79772044013316,90.31908817605324,45.15954408802662
57+
55,55,242.04128493041298,96.81651397216513,48.40825698608256
58+
56,56,258.15403301982815,103.2616132079313,51.63080660396565
59+
57,57,273.828341452579,109.53133658103161,54.765668290515805
60+
58,58,288.71074888939893,115.48429955575966,57.74214977787983
61+
59,59,302.40676593155194,120.96270637262069,60.48135318631034
62+
60,60,,,

0 commit comments

Comments
 (0)