diff --git a/caimira/apps/calculator/report_generator.py b/caimira/apps/calculator/report_generator.py index 873d0c0c..b20bd259 100644 --- a/caimira/apps/calculator/report_generator.py +++ b/caimira/apps/calculator/report_generator.py @@ -307,13 +307,13 @@ def non_zero_percentage(percentage: int) -> str: def manufacture_viral_load_scenarios(model: mc.ExposureModel) -> typing.Dict[str, mc.ExposureModel]: viral_load = model.concentration_model.infected.virus.viral_load_in_sputum - viral_load_values = [np.quantile(viral_load, percentil) for percentil in (0.05, 0.5, 0.95)] + viral_load_values = [np.quantile(viral_load, percentil) for percentil in (0.01, 0.05, 0.5, 0.95, 0.99)] scenarios = {} for vl in viral_load_values: specific_vl_scenario = dataclass_utils.nested_replace(model, {'concentration_model.infected.virus.viral_load_in_sputum': vl} ) - scenarios[str(round(np.log10(vl), 1))] = specific_vl_scenario + scenarios[round(np.log10(vl))] = specific_vl_scenario return scenarios @@ -387,17 +387,7 @@ def scenario_statistics(mc_model: mc.ExposureModel, sample_times: typing.List[fl } -def comparison_report_viral_load( - report_data: typing.Dict[str, typing.Any], - scenarios: typing.Dict[str, mc.ExposureModel], -): - statistics = { - # 'Current scenario' : { - # 'probability_of_infection': report_data['prob_inf'], - # 'expected_new_cases': report_data['expected_new_cases'], - # } - } - +def comparison_report_viral_load(scenarios: typing.Dict[str, mc.ExposureModel]): results = [] for mc_model in scenarios.values(): results.append({ @@ -405,7 +395,8 @@ def comparison_report_viral_load( 'expected_new_cases': np.mean(mc_model.expected_new_cases()), }) - for (name, model), model_stats in zip(scenarios.items(), results): + statistics = {} + for (name, _), model_stats in zip(scenarios.items(), results): statistics[name] = model_stats return { @@ -488,11 +479,10 @@ class ReportGenerator: scenario_sample_times = interesting_times(model) report_data = calculate_report_data(form, model) context.update(report_data) + alternative_viral_loads = manufacture_viral_load_scenarios(model) alternative_scenarios = manufacture_alternative_scenarios(form) - context['alternative_viral_load'] = comparison_report_viral_load( - report_data, alternative_viral_loads - ) + context['alternative_viral_load'] = comparison_report_viral_load(alternative_viral_loads) context['alternative_scenarios'] = comparison_report( form, report_data, alternative_scenarios, scenario_sample_times, executor_factory=executor_factory, )