Skip to content

Commit 4b00672

Browse files
authored
Merge pull request #154 from The-Strategy-Unit/add-cost-values-to-outputs
Add cost values to outputs
2 parents ab4394f + 7725481 commit 4b00672

File tree

7 files changed

+45
-13
lines changed

7 files changed

+45
-13
lines changed

renal_capacity_model/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,5 @@ def __init__(
8888
self.time_to_event_curves = load_time_to_event_curves(
8989
path_to_time_to_event_curves
9090
)
91+
self.daily_costs = config_dict["daily_costs"]
9192
logger.info("🔧 Config loaded successfully")

renal_capacity_model/config_values.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,12 @@
246246
"pre_emptive_transplant_cadaver_donor_dist": {
247247
y: {"early": 0.22, "late": 0.05} for y in range(1, 14)
248248
},
249+
"daily_costs": {
250+
"ichd": 62842 / 365,
251+
"hhd": 51122 / 365,
252+
"pd": 39391 / 365,
253+
"transplant": 9005 / 365,
254+
},
249255
}
250256

251257
# Time to death: conservative care

renal_capacity_model/load_scenario.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,7 @@ def load_scenario_from_excel(
901901
"ichd": input_scenario.iat[36, 1],
902902
"hhd": input_scenario.iat[37, 1],
903903
"pd": input_scenario.iat[38, 1],
904-
"living_with_transplant": input_scenario.iat[39, 1],
904+
"transplant": input_scenario.iat[39, 1],
905905
}
906906

907907
return config_from_excel

renal_capacity_model/main.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ def main(
6060
)
6161
for excel_file in [path_to_inputs_file, path_to_outputs_file]:
6262
filepaths.append(copy_excel_files(excel_file, run_start_time))
63-
write_results_to_excel(
64-
filepaths[1], combined_results, trial.yearly_activity_duration
65-
)
63+
write_results_to_excel(filepaths[1], combined_results, trial.costs_dfs)
6664

6765

6866
if __name__ == "__main__":

renal_capacity_model/process_outputs.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,14 @@ def copy_excel_files(path_to_file: str, run_start_time: str) -> str:
194194
def 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

renal_capacity_model/trial.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
create_results_folder,
1111
save_result_files,
1212
calculate_activity_duration_per_year,
13+
convert_activity_to_costs,
1314
)
1415
import numpy as np
1516
from tqdm import tqdm
@@ -96,6 +97,9 @@ def run_trial(self):
9697
self.yearly_activity_duration = calculate_activity_duration_per_year(
9798
self.event_log_dfs
9899
)
100+
self.costs_dfs = convert_activity_to_costs(
101+
self.yearly_activity_duration, self.config.daily_costs
102+
)
99103
logger.info("💾 Saving full trial results")
100104
self.save_trial_results(
101105
self.process_eventlog_dfs(self.activity_change_dfs), "activity_change"

uv.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)