@@ -76,16 +76,18 @@ def __init__(self, p: Parameters) -> SimSirModel:
76
76
for key , d in p .dispositions .items ()
77
77
}
78
78
79
- i_dict_v = get_dispositions (raw_df .infected , rates , p .market_share )
80
- r_dict_v = get_dispositions (raw_df .recovered , rates , p .market_share )
79
+ # i_dict_v = get_dispositions(raw_df.infected, rates, p.market_share)
80
+ # r_dict_v = get_dispositions(raw_df.recovered, rates, p.market_share)
81
81
82
- self .dispositions = {
83
- key : value + r_dict_v [key ]
84
- for key , value in i_dict_v .items ()
85
- }
82
+ #self.dispositions = {
83
+ # key: value + r_dict_v[key]
84
+ # for key, value in i_dict_v.items()
85
+ #}
86
+
87
+ #self.dispositions_df = pd.DataFrame(self.dispositions)
86
88
87
- self .dispositions_df = pd . DataFrame ( self . dispositions )
88
- self .admits_df = admits_df = build_admits_df (p . n_days , self . dispositions )
89
+ self .dispositions_df = dispositions_df = build_dispositions_df ( raw_df , rates , p . market_share )
90
+ self .admits_df = admits_df = build_admits_df (dispositions_df )
89
91
self .census_df = build_census_df (admits_df , lengths_of_stay )
90
92
91
93
@@ -119,55 +121,49 @@ def gen_sir(
119
121
120
122
121
123
def sim_sir_df (
122
- s : float , i : float , r : float , beta : float , gamma : float , n_days
124
+ s : float , i : float , r : float , beta : float , gamma : float , n_days : int
123
125
) -> pd .DataFrame :
124
126
"""Simulate the SIR model forward in time."""
125
127
return pd .DataFrame (
126
128
data = gen_sir (s , i , r , beta , gamma , n_days ),
127
129
columns = ("day" , "susceptible" , "infected" , "recovered" ),
128
130
)
129
131
130
-
131
- def get_dispositions (
132
- patients : np .ndarray ,
132
+ def build_dispositions_df (
133
+ sim_sir_df : pd .DataFrame ,
133
134
rates : Dict [str , float ],
134
135
market_share : float ,
135
- ) -> Dict [ str , np . ndarray ] :
136
+ ) -> pd . DataFrame :
136
137
"""Get dispositions of patients adjusted by rate and market_share."""
137
- return {
138
- key : patients * rate * market_share
139
- for key , rate in rates .items ()
140
- }
138
+ patients = sim_sir_df .infected + sim_sir_df .recovered
139
+ return pd .DataFrame ({
140
+ "day" : sim_sir_df .day ,
141
+ ** {
142
+ key : patients * rate * market_share
143
+ for key , rate in rates .items ()
144
+ }
145
+ })
141
146
142
147
143
- def build_admits_df (n_days , dispositions ) -> pd .DataFrame :
148
+ def build_admits_df (dispositions_df : pd . DataFrame ) -> pd .DataFrame :
144
149
"""Build admits dataframe from Parameters and Model."""
145
- days = np .arange (0 , n_days + 1 )
146
- projection = pd .DataFrame ({
147
- "day" : days ,
148
- ** dispositions ,
149
- })
150
- # New cases
151
- admits_df = projection .iloc [:- 1 , :] - projection .shift (1 )
152
- admits_df ["day" ] = range (admits_df .shape [0 ])
150
+ admits_df = dispositions_df .iloc [:- 1 , :] - dispositions_df .shift (1 )
151
+ admits_df .day = dispositions_df .day
153
152
return admits_df
154
153
155
154
156
155
def build_census_df (
157
- admits_df : pd .DataFrame , lengths_of_stay
156
+ admits_df : pd .DataFrame ,
157
+ lengths_of_stay : Dict [str , int ],
158
158
) -> pd .DataFrame :
159
159
"""ALOS for each category of COVID-19 case (total guesses)"""
160
- n_days = np .shape (admits_df )[0 ]
161
- census_dict = {}
162
- for key , los in lengths_of_stay .items ():
163
- census = (
164
- admits_df .cumsum ().iloc [:- los , :]
165
- - admits_df .cumsum ().shift (los ).fillna (0 )
166
- ).apply (np .ceil )
167
- census_dict [key ] = census [key ]
168
-
169
- census_df = pd .DataFrame (census_dict )
170
- census_df ["day" ] = census_df .index
171
- census_df = census_df [["day" , * lengths_of_stay .keys ()]]
172
- census_df = census_df .head (n_days )
173
- return census_df
160
+ return pd .DataFrame ({
161
+ 'day' : admits_df .day ,
162
+ ** {
163
+ key : (
164
+ admits_df [key ].cumsum ().iloc [:- los ]
165
+ - admits_df [key ].cumsum ().shift (los ).fillna (0 )
166
+ ).apply (np .ceil )
167
+ for key , los in lengths_of_stay .items ()
168
+ }
169
+ })
0 commit comments