added results with different viral load values
This commit is contained in:
parent
3c139fb62d
commit
ca786d7e7f
2 changed files with 62 additions and 0 deletions
|
|
@ -139,6 +139,7 @@ def calculate_report_data(form: FormData, model: models.ExposureModel) -> typing
|
|||
expected_new_cases = np.array(model.expected_new_cases()).mean()
|
||||
uncertainties_plot_src = img2base64(_figure2bytes(uncertainties_plot(model))) if form.conditional_probability_plot else None
|
||||
exposed_presence_intervals = [list(interval) for interval in model.exposed.presence_interval().boundaries()]
|
||||
manufacture_viral_load_scenarios(model)
|
||||
|
||||
return {
|
||||
"model_repr": repr(model),
|
||||
|
|
@ -302,6 +303,18 @@ def non_zero_percentage(percentage: int) -> str:
|
|||
return "99.9%"
|
||||
else:
|
||||
return "{:0.1f}%".format(percentage)
|
||||
|
||||
|
||||
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)]
|
||||
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
|
||||
return scenarios
|
||||
|
||||
|
||||
def manufacture_alternative_scenarios(form: FormData) -> typing.Dict[str, mc.ExposureModel]:
|
||||
|
|
@ -374,6 +387,32 @@ 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'],
|
||||
# }
|
||||
}
|
||||
|
||||
results = []
|
||||
for mc_model in scenarios.values():
|
||||
results.append({
|
||||
'probability_of_infection': np.mean(mc_model.infection_probability()),
|
||||
'expected_new_cases': np.mean(mc_model.expected_new_cases()),
|
||||
})
|
||||
|
||||
for (name, model), model_stats in zip(scenarios.items(), results):
|
||||
statistics[name] = model_stats
|
||||
|
||||
return {
|
||||
'stats': statistics,
|
||||
}
|
||||
|
||||
|
||||
def comparison_report(
|
||||
form: FormData,
|
||||
report_data: typing.Dict[str, typing.Any],
|
||||
|
|
@ -449,7 +488,11 @@ 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_scenarios'] = comparison_report(
|
||||
form, report_data, alternative_scenarios, scenario_sample_times, executor_factory=executor_factory,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -161,6 +161,25 @@
|
|||
{% block report_summary_footnote %}
|
||||
{% endblock report_summary_footnote %}
|
||||
</div>
|
||||
<br>
|
||||
<table class="table w-auto">
|
||||
<thead class="thead-light">
|
||||
<tr>
|
||||
<th>Scenario</th>
|
||||
<th>P(I)</th>
|
||||
<th>Expected new cases</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for scenario_name, scenario_stats in alternative_viral_load.stats.items() %}
|
||||
<tr>
|
||||
<td> Viral load: 10<sup>{{ scenario_name }}</sup></td>
|
||||
<td> {{ scenario_stats.probability_of_infection | non_zero_percentage }}</td>
|
||||
<td style="text-align:right">{{ scenario_stats.expected_new_cases | float_format }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<br><p id="section1">* The results are based on the parameters and assumptions published in the CARA publication: <a href="https://doi.org/10.1098/rsfs.2021.0076"> doi.org/10.1098/rsfs.2021.0076</a>.</p><br>
|
||||
{% if form.short_range_option == "short_range_yes" %}
|
||||
{% if 'Speaking' in form.short_range_interactions|string or 'Shouting' in form.short_range_interactions|string %}
|
||||
|
|
|
|||
Loading…
Reference in a new issue