From 4ab95fcfaa11456608b7201c119355ac9ae46eee Mon Sep 17 00:00:00 2001 From: Luis Aleixo Date: Thu, 22 Sep 2022 11:37:31 +0200 Subject: [PATCH] added default values for vaccine types on tests --- caimira/apps/calculator/model_generator.py | 23 ++-- caimira/apps/calculator/report_generator.py | 5 + caimira/apps/calculator/static/js/form.js | 32 +++++- .../templates/base/calculator.form.html.j2 | 104 ++++++++++++------ .../templates/base/calculator.report.html.j2 | 15 +++ caimira/data/__init__.py | 86 +++++++++++---- 6 files changed, 190 insertions(+), 75 deletions(-) diff --git a/caimira/apps/calculator/model_generator.py b/caimira/apps/calculator/model_generator.py index 41cc4d07..fe062b0f 100644 --- a/caimira/apps/calculator/model_generator.py +++ b/caimira/apps/calculator/model_generator.py @@ -554,20 +554,22 @@ class FormData: # minus the number of infected occupants. exposed_occupants = self.total_people - infected_occupants - if self.vaccine_option == False: - HI = 0.0 - else: - if self.vaccine_booster_option == False: - HI = data.vaccine_host_immunity[self.vaccine_type] + if (self.vaccine_option): + if (self.vaccine_booster_option and self.vaccine_booster_type != 'Other'): + host_immunity = [vaccine['VE'] for vaccine in data.vaccine_booster_host_immunity if + vaccine['primary series vaccine'] == self.vaccine_type and + vaccine['booster vaccine'] == self.vaccine_booster_type][0] else: - HI = data.vaccine_booster_host_immunity[self.vaccine_booster_type] + host_immunity = data.vaccine_primary_host_immunity[self.vaccine_type] + else: + host_immunity = 0. exposed = mc.Population( number=exposed_occupants, presence=self.exposed_present_interval(), activity=activity, mask=self.mask(), - host_immunity=HI, + host_immunity=host_immunity, ) return exposed @@ -809,8 +811,8 @@ def baseline_raw_form_data() -> typing.Dict[str, typing.Union[str, float]]: 'total_people': '10', 'vaccine_option': '', 'vaccine_booster_option': '', - 'vaccine_type': '', - 'vaccine_booster_type': '', + 'vaccine_type': 'Ad26.COV2.S (Janssen)', + 'vaccine_booster_type': 'AZD1222 (AstraZeneca)', 'ventilation_type': 'natural_ventilation', 'virus_type': 'SARS_CoV_2', 'volume_type': 'room_volume_explicit', @@ -835,9 +837,6 @@ VIRUS_TYPES = {'SARS_CoV_2', 'SARS_CoV_2_ALPHA', 'SARS_CoV_2_BETA','SARS_CoV_2_G VOLUME_TYPES = {'room_volume_explicit', 'room_volume_from_dimensions'} WINDOWS_OPENING_REGIMES = {'windows_open_permanently', 'windows_open_periodically', 'not-applicable'} WINDOWS_TYPES = {'window_sliding', 'window_hinged', 'not-applicable'} -VACCINE_OPTIONS = {'janssen', 'any_mRNA', 'astraZeneca', 'astraZeneca_mRNA', 'astraZeneca_mRNA_pfizer', 'beijingCNBG', 'pfizer', - 'pfizer_moderna', 'sinovac', 'sinovac_astraZeneca', 'covishield', 'moderna', 'gamaleya', 'sinovac_pfizer'} -VACCINE_BOOSTER_OPTIONS = {'booster_janssen', 'booster_astraZeneca', 'booster_pfizer', 'booster_pfizer_moderna', 'booster_sinovac', 'booster_moderna'} COFFEE_OPTIONS_INT = {'coffee_break_0': 0, 'coffee_break_1': 1, 'coffee_break_2': 2, 'coffee_break_4': 4} CONFIDENCE_LEVEL_OPTIONS = {'confidence_low': 10, 'confidence_medium': 5, 'confidence_high': 2} MONTH_NAMES = [ diff --git a/caimira/apps/calculator/report_generator.py b/caimira/apps/calculator/report_generator.py index b2d5ff25..456a64be 100644 --- a/caimira/apps/calculator/report_generator.py +++ b/caimira/apps/calculator/report_generator.py @@ -214,6 +214,10 @@ def readable_minutes(minutes: int) -> str: return time_str + unit +def percentage(absolute: float) -> float: + return absolute * 100 + + def non_zero_percentage(percentage: int) -> str: if percentage < 0.01: return "<0.01%" @@ -389,6 +393,7 @@ class ReportGenerator: env.filters['minutes_to_time'] = minutes_to_time env.filters['float_format'] = "{0:.2f}".format env.filters['int_format'] = "{:0.0f}".format + env.filters['percentage'] = percentage env.filters['JSONify'] = json.dumps return env diff --git a/caimira/apps/calculator/static/js/form.js b/caimira/apps/calculator/static/js/form.js index 439daef7..5ce28dd1 100644 --- a/caimira/apps/calculator/static/js/form.js +++ b/caimira/apps/calculator/static/js/form.js @@ -328,7 +328,22 @@ function on_wearing_mask_change() { }) } -function on_vaccination_change() { +function update_booster_warning() { + // Check if "Other" is selected + $("#vaccine_booster_type").find(":selected").val() == "Other" ? $("#booster_warning").show() : $("#booster_warning").hide(); +} + +function update_booster_dropdown(url) { + let primary_vaccine_option = $("#vaccine_type").find(":selected").val(); + $($("#vaccine_booster_type > option").get().reverse()).each(function() { + if ($(this).attr('data-primary-vaccine') != primary_vaccine_option && $(this).val() != "Other") $(this).hide(); + else $(this).show().prop('selected', true); + }); + if (url.searchParams.has('vaccine_booster_type')) $("#vaccine_booster_type").val(url.searchParams.get('vaccine_booster_type')); + update_booster_warning(); +} + +function on_vaccination_change(url) { vaccination_option = $('input[type=radio][name=vaccine_option]'); vaccination_option.each(function (index) { if (this.checked) { @@ -339,7 +354,8 @@ function on_vaccination_change() { getChildElement($(this)).hide(); require_fields(this); } - }) + }); + update_booster_dropdown(url); } function on_vaccination_booster_change() { @@ -347,7 +363,7 @@ function on_vaccination_booster_change() { vaccination_booster_option.each(function (index) { if (this.checked) getChildElement($(this)).show(); else getChildElement($(this)).hide(); - }) + }); } function populate_temp_hum_values(data, index) { @@ -840,6 +856,7 @@ window.onpagehide = function(){ $(document).ready(function () { var url = new URL(decodeURIComponent(window.location.href)); //Pre-fill form with known values + url.searchParams.forEach((value, name) => { //If element exists if(document.getElementsByName(name).length > 0) { @@ -955,9 +972,14 @@ $(document).ready(function () { // When the vaccinated_option_option changes we want to make its respective // children show/hide. - $("input[type=radio][name=vaccine_option]").change(on_vaccination_change); + $("input[type=radio][name=vaccine_option]").change(() => on_vaccination_change(url)); // Call the function now to handle forward/back button presses in the browser. - on_vaccination_change(); + on_vaccination_change(url); + + // When the vaccine_type dropdown selected option changes we want to update + // the booster vaccine dropdown. + $("#vaccine_type").change(() => update_booster_dropdown(url)); + $("#vaccine_booster_type").change(update_booster_warning); // When the vaccinated_booster_option changes we want to make its respective // children show/hide. diff --git a/caimira/apps/templates/base/calculator.form.html.j2 b/caimira/apps/templates/base/calculator.form.html.j2 index bc8ac04f..1723e7d8 100644 --- a/caimira/apps/templates/base/calculator.form.html.j2 +++ b/caimira/apps/templates/base/calculator.form.html.j2 @@ -368,55 +368,91 @@ - - + {% if form.vaccine_option %} +
+
+
Vaccination data:
+
+
    +
  • Primary vaccine: {{ form.vaccine_type | replace("_", " ") }} + {% if form.vaccine_booster_option %} +
  • Booster vaccine: {{ form.vaccine_booster_type | replace("_", " ")}}
  • + {% endif %} +
  • Vaccine effectiveness: {{ model.exposed.host_immunity | percentage | non_zero_percentage }}
  • +
+
+
+ {% endif %}
Ventilation data:
diff --git a/caimira/data/__init__.py b/caimira/data/__init__.py index b244a17b..7ca7fb70 100644 --- a/caimira/data/__init__.py +++ b/caimira/data/__init__.py @@ -42,30 +42,68 @@ GenevaTemperatures = { } +# ------- VACCINATION DATA ------- + # From data available in Results of COVID-19 Vaccine Effectiveness # Studies: An Ongoing Systematic Review - Updated September 8, 2022. # https://view-hub.org/resources -vaccine_host_immunity = { - 'janssen': 0.551277778, - 'any_mRNA': 0.93875, - 'astraZeneca': 0.55921875, - 'astraZeneca_mRNA': 0.718571429, - 'astraZeneca_mRNA_pfizer': 0.7865, - 'beijingCNBG': 0.4325, - 'pfizer': 0.62503012, - 'pfizer_moderna': 0.567126761, - 'sinovac': 0.286884615, - 'sinovac_astraZeneca': 0.561333333, - 'covishield': 0.98, - 'moderna': 0.683255814, - 'gamaleya': 0.696, - 'sinovac_pfizer': 0.7965, - } -vaccine_booster_host_immunity = { - 'booster_janssen': 0.492666667, - 'booster_astraZeneca': 0.672166667, - 'booster_pfizer': 0.612971831, - 'booster_pfizer_moderna': 0.645, - 'booster_sinovac': 0.427857143, - 'booster_moderna': 0.632442105, -} \ No newline at end of file +vaccine_primary_host_immunity = { + 'Ad26.COV2.S_(Janssen)': 0.551277778, + 'Any_mRNA_-_heterologous': 0.93875, + 'AZD1222_(AstraZeneca)': 0.55921875, + 'AZD1222_(AstraZeneca)_and_any_mRNA_-_heterologous': 0.718571429, + 'AZD1222_(AstraZeneca)_and_BNT162b2_(Pfizer)': 0.7865, + 'BBIBP-CorV_(Beijing_CNBG)': 0.4325, + 'BNT162b2_(Pfizer)': 0.62503012, + 'BNT162b2_(Pfizer)_and_mRNA-1273_(Moderna)': 0.567126761, + 'CoronaVac_(Sinovac)': 0.286884615, + 'CoronaVac_(Sinovac)_and_AZD1222_(AstraZeneca)': 0.561333333, + 'Covishield': 0.98, + 'mRNA-1273_(Moderna)': 0.683255814, + 'Sputnik_V_(Gamaleya)': 0.696, + 'CoronaVac_(Sinovac)_and_BNT162b2_(Pfizer)': 0.7965, +} + +vaccine_booster_host_immunity = [ + {'primary series vaccine': 'AZD1222_(AstraZeneca)', 'booster vaccine': 'AZD1222_(AstraZeneca)', 'VE': 0.6353636363636364}, + {'primary series vaccine': 'AZD1222_(AstraZeneca)', 'booster vaccine': 'BNT162b2_(Pfizer)', 'VE': 0.7389019607843137}, + {'primary series vaccine': 'AZD1222_(AstraZeneca)', 'booster vaccine': 'BNT162b2_(Pfizer)_and_mRNA-1273_(Moderna)', 'VE': 0.26}, + {'primary series vaccine': 'AZD1222_(AstraZeneca)', 'booster vaccine': 'BNT162b2_(Pfizer)_or_mRNA-1273_(Moderna)', 'VE': 0.3846666666666667}, + {'primary series vaccine': 'AZD1222_(AstraZeneca)', 'booster vaccine': 'Sinopharm', 'VE': 0.7346666666666666}, + {'primary series vaccine': 'AZD1222_(AstraZeneca)', 'booster vaccine': 'mRNA-1273_(Moderna)', 'VE': 0.8642399999999999}, + {'primary series vaccine': 'Ad26.COV2.S_(Janssen)', 'booster vaccine': 'Ad26.COV2.S_(Janssen)', 'VE': 0.615}, + {'primary series vaccine': 'Ad26.COV2.S_(Janssen)', 'booster vaccine': 'BNT162b2_(Pfizer)', 'VE': 0.9155000000000001}, + {'primary series vaccine': 'Ad26.COV2.S_(Janssen)', 'booster vaccine': 'BNT162b2_(Pfizer)_or_mRNA-1273_(Moderna)', 'VE': 0.6725}, + {'primary series vaccine': 'BBIBP-CorV_(Beijing_CNBG)', 'booster vaccine': 'Ad26.COV2.S_(Janssen)', 'VE': 0.8973333333333333}, + {'primary series vaccine': 'BBIBP-CorV_(Beijing_CNBG)', 'booster vaccine': 'BNT162b2_(Pfizer)', 'VE': 0.9283333333333332}, + {'primary series vaccine': 'BBIBP-CorV_(Beijing_CNBG)', 'booster vaccine': 'Sinopharm', 'VE': 0.7639999999999999}, + {'primary series vaccine': 'BBIBP-CorV_(Beijing_CNBG)', 'booster vaccine': 'mRNA-1273_(Moderna)', 'VE': 0.9526666666666667}, + {'primary series vaccine': 'BNT162b2_(Pfizer)', 'booster vaccine': 'AZD1222_(AstraZeneca)', 'VE': 0.8960000000000001}, + {'primary series vaccine': 'BNT162b2_(Pfizer)', 'booster vaccine': 'Ad26.COV2.S_(Janssen)', 'VE': 0.9306666666666666}, + {'primary series vaccine': 'BNT162b2_(Pfizer)', 'booster vaccine': 'BNT162b2_(Pfizer)', 'VE': 0.7413183520599251}, + {'primary series vaccine': 'BNT162b2_(Pfizer)', 'booster vaccine': 'BNT162b2_(Pfizer)_or_mRNA-1273_(Moderna)', 'VE': 0.6004285714285714}, + {'primary series vaccine': 'BNT162b2_(Pfizer)', 'booster vaccine': 'CoronaVac_(Sinovac)', 'VE': 0.121}, + {'primary series vaccine': 'BNT162b2_(Pfizer)', 'booster vaccine': 'Sinopharm', 'VE': 0.6683333333333333}, + {'primary series vaccine': 'BNT162b2_(Pfizer)', 'booster vaccine': 'mRNA-1273_(Moderna)', 'VE': 0.7530214285714285}, + {'primary series vaccine': 'BNT162b2_(Pfizer)_and_mRNA-1273_(Moderna)', 'booster vaccine': 'BNT162b2_(Pfizer)_and_mRNA-1273_(Moderna)', 'VE': 0.645}, + {'primary series vaccine': 'BNT162b2_(Pfizer)_(2_doses)_+_mRNA-1273_(Moderna)_(3rd_dose)', 'booster vaccine': 'mRNA-1273_(Moderna)_(4th_dose)', 'VE': 0.6466666666666667}, + {'primary series vaccine': 'BNT162b2_(Pfizer)_(3_doses)', 'booster vaccine': 'BNT162b2_(Pfizer)_(4th_dose)', 'VE': 0.6068333333333333}, + {'primary series vaccine': 'BNT162b2_(Pfizer)_(3_doses)', 'booster vaccine': 'mRNA-1273_(Moderna)_(4th_dose)', 'VE': 0.498}, + {'primary series vaccine': 'BNT162b2_(Pfizer)_or_mRNA-1273_(Moderna)', 'booster vaccine': 'BNT162b2_(Pfizer)', 'VE': 0.7564285714285713}, + {'primary series vaccine': 'BNT162b2_(Pfizer)_or_mRNA-1273_(Moderna)', 'booster vaccine': 'BNT162b2_(Pfizer)_or_mRNA-1273_(Moderna)', 'VE': 0.7541721854304636}, + {'primary series vaccine': 'BNT162b2_(Pfizer)_or_mRNA-1273_(Moderna)', 'booster vaccine': 'mRNA-1273_(Moderna)', 'VE': 0.7538571428571429}, + {'primary series vaccine': 'BNT162b2_(Pfizer)_or_mRNA-1273_(Moderna)_(3_doses)', 'booster vaccine': 'BNT162b2_(Pfizer)_or_mRNA-1273_(Moderna)_(4th_dose)', 'VE': 0.5788888888888889}, + {'primary series vaccine': 'CoronaVac_(Sinovac)', 'booster vaccine': 'AZD1222_(AstraZeneca)', 'VE': 0.9584285714285714}, + {'primary series vaccine': 'CoronaVac_(Sinovac)', 'booster vaccine': 'BNT162b2_(Pfizer)', 'VE': 0.7631960784313726}, + {'primary series vaccine': 'CoronaVac_(Sinovac)', 'booster vaccine': 'CoronaVac_(Sinovac)', 'VE': 0.7141851851851851}, + {'primary series vaccine': 'CoronaVac_(Sinovac)', 'booster vaccine': 'Coronavac_(Sinovac)', 'VE': 0.5107647058823529}, + {'primary series vaccine': 'Sputnik_V_(Gamaleya)', 'booster vaccine': 'Ad26.COV2.S_(Janssen)', 'VE': 0.8076666666666666}, + {'primary series vaccine': 'Sputnik_V_(Gamaleya)', 'booster vaccine': 'BNT162b2_(Pfizer)', 'VE': 0.936}, + {'primary series vaccine': 'Sputnik_V_(Gamaleya)', 'booster vaccine': 'Sinopharm', 'VE': 0.5285}, + {'primary series vaccine': 'Sputnik_V_(Gamaleya)', 'booster vaccine': 'mRNA-1273_(Moderna)', 'VE': 0.9366666666666668}, + {'primary series vaccine': 'mRNA-1273_(Moderna)', 'booster vaccine': 'Ad26.COV2.S_(Janssen)', 'VE': 0.8873333333333333}, + {'primary series vaccine': 'mRNA-1273_(Moderna)', 'booster vaccine': 'BNT162b2_(Pfizer)', 'VE': 0.8068636363636363}, + {'primary series vaccine': 'mRNA-1273_(Moderna)', 'booster vaccine': 'BNT162b2_(Pfizer)_or_mRNA-1273_(Moderna)', 'VE': 0.5692499999999999}, + {'primary series vaccine': 'mRNA-1273_(Moderna)', 'booster vaccine': 'Sinopharm', 'VE': 0.7739999999999999}, + {'primary series vaccine': 'mRNA-1273_(Moderna)', 'booster vaccine': 'mRNA-1273_(Moderna)', 'VE': 0.7141650485436892}, + {'primary series vaccine': 'mRNA-1273_(Moderna)_(3_doses)', 'booster vaccine': 'mRNA-1273_(Moderna)_(4th_dose)', 'VE': 0.7066666666666667}] \ No newline at end of file