@@ -194,14 +194,14 @@ def copy_excel_files(path_to_file: str, run_start_time: str) -> str:
194194def write_results_to_excel (
195195 path_to_results_excel_file : str ,
196196 combined_df : pd .DataFrame ,
197- yearly_activity_duration : pd .DataFrame ,
197+ costs_dfs : dict [ str , pd .DataFrame ] ,
198198):
199199 """Write combined model results from all model runs to Excel file
200200
201201 Args:
202202 path_to_excel_file (str): Path to Excel file
203203 combined_df (pd.DataFrame): Dataframe of all model results combined and processed
204- yearly_activity_duration (pd.DataFrame): Dataframe of counts of activity for each year of
204+ costs_dfs (pd.DataFrame): Dataframe of costs of activity for each year of
205205 model simulation, for each model run
206206 """
207207 with pd .ExcelWriter (
@@ -214,10 +214,33 @@ def write_results_to_excel(
214214 combined_df .loc [outcome ].to_excel (
215215 writer , sheet_name = outcome .replace ("waiting_for_transplant" , "wft" )
216216 )
217- for activity in ["ichd" , "hhd" , "pd" , "transplant" ]:
218- yearly_activity_duration .pivot (
219- index = "model_run" , columns = "year" , values = activity
220- ).sort_index (axis = 1 ).to_excel (writer , sheet_name = f"{ activity } _yearly" )
217+ for activity , df in costs_dfs .items ():
218+ df .to_excel (writer , sheet_name = f"{ activity } _yearly" )
221219 logger .info (
222220 f"✅ 💾 Excel format model results written to: \n { path_to_results_excel_file } "
223221 )
222+
223+
224+ def convert_activity_to_costs (
225+ yearly_activity_duration : pd .DataFrame , daily_costs : dict [str , float ]
226+ ) -> dict [str , pd .DataFrame ]:
227+ """Converts yearly activity duration dataframe into costs for each type of activity
228+
229+ Args:
230+ yearly_activity_duration (pd.DataFrame): Dataframe with yearly activity durations
231+ for each of the activity types
232+ daily_costs (dict[str, float]): Daily costs dictionary, set in config
233+
234+ Returns:
235+ dict[str, pd.DataFrame]: Dictionary where keys are treatment modality and
236+ values are a DataFrame with the yearly costs for each across each of the model runs
237+ """
238+ costs_dfs = {}
239+ for activity in ["ichd" , "hhd" , "pd" , "transplant" ]:
240+ costs_dfs [activity ] = (
241+ yearly_activity_duration .pivot (
242+ index = "model_run" , columns = "year" , values = activity
243+ ).sort_index (axis = 1 )
244+ * daily_costs [activity ]
245+ )
246+ return costs_dfs
0 commit comments