diff --git a/cara/apps/calculator/model_generator.py b/cara/apps/calculator/model_generator.py index 100b02da..ef4e74fa 100644 --- a/cara/apps/calculator/model_generator.py +++ b/cara/apps/calculator/model_generator.py @@ -1,4 +1,3 @@ -from cara.models import Model from dataclasses import dataclass import html import typing @@ -46,7 +45,7 @@ class FormData: @classmethod def from_dict(cls, form_data: typing.Dict) -> "FormData": - valid_na_values = ['windows_open', 'ventilation_type', 'mechanical_ventilation_type'] + valid_na_values = ['windows_open', 'mechanical_ventilation_type'] for name in valid_na_values: if not form_data.get(name, ''): form_data[name] = 'not-applicable' @@ -113,10 +112,11 @@ class FormData: infected_finish=time_string_to_minutes(form_data['infected_finish']), ) - def build_model(self) -> Model: + def build_model(self) -> models.Model: return model_from_form(self) def ventilation(self) -> models.Ventilation: + always_on = models.PeriodicInterval(period=120, duration=120) # Initializes a ventilation instance as a window if 'natural' is selected, or as a HEPA-filter otherwise if self.ventilation_type == 'natural': if self.windows_open == 'interval': @@ -141,17 +141,17 @@ class FormData: inside_temp=inside_temp, outside_temp=outside_temp, cd_b=0.6, window_height=self.window_height, opening_length=self.opening_distance * self.windows_number) + elif self.ventilation_type == "no-ventilation": + ventilation = models.AirChange(active=always_on, air_exch=0.) else: if self.mechanical_ventilation_type == 'air_changes': - ventilation = models.AirChange(active=models.PeriodicInterval(period=120, duration=120), - air_exch=self.air_changes) + ventilation = models.AirChange(active=always_on, air_exch=self.air_changes) else: - ventilation = models.HVACMechanical(active=models.PeriodicInterval(period=120, duration=120), - q_air_mech=self.air_supply) + ventilation = models.HVACMechanical( + active=always_on, q_air_mech=self.air_supply) if self.hepa_option: - hepa = models.HEPAFilter(active=models.PeriodicInterval(period=120, duration=120), - q_air_mech=250.) + hepa = models.HEPAFilter(active=always_on, q_air_mech=250.) return models.MultipleVentilation((ventilation,hepa)) else: return ventilation @@ -269,7 +269,6 @@ def model_from_form(form: FormData) -> models.Model: def baseline_raw_form_data(): # Note: This isn't a special "baseline". It can be updated as required. return { - 'RADIO_ventilation_type': 'natural', 'activity_finish': '18:00', 'activity_start': '09:00', 'activity_type': 'office', @@ -296,7 +295,7 @@ def baseline_raw_form_data(): 'simulation_name': 'Test', 'single_event_date': '', 'total_people': '10', - 'ventilation_type': '', + 'ventilation_type': 'natural', 'volume_type': 'room_volume', 'window_height': '2', 'window_width': '2', @@ -309,7 +308,7 @@ ACTIVITY_TYPES = {'office', 'training', 'workshop'} EVENT_TYPES = {'single_event', 'recurrent_event'} MECHANICAL_VENTILATION_TYPES = {'air_changes', 'air_supply', 'not-applicable'} MASK_WEARING = {'continuous', 'removed'} -VENTILATION_TYPES = {'natural', 'mechanical', 'not-applicable'} +VENTILATION_TYPES = {'natural', 'mechanical', 'no-ventilation'} VOLUME_TYPES = {'room_volume', 'room_dimensions'} WINDOWS_OPEN = {'always', 'interval', 'breaks', 'not-applicable'} diff --git a/cara/apps/calculator/static/form.html b/cara/apps/calculator/static/form.html index 01d2d7da..98a3b23f 100644 --- a/cara/apps/calculator/static/form.html +++ b/cara/apps/calculator/static/form.html @@ -36,30 +36,27 @@ Beta v1.0.0 Please send feedback to Ventilation type: - - Mechanical - Natural
+ No ventilation + Mechanical + Natural
HEPA filtration: diff --git a/cara/apps/calculator/static/js/form.js b/cara/apps/calculator/static/js/form.js index fd1fcebb..6dbc57c2 100644 --- a/cara/apps/calculator/static/js/form.js +++ b/cara/apps/calculator/static/js/form.js @@ -1,40 +1,27 @@ -/* -------Show/Hide DIVs------- */ -function show(show, var_id, obj) { - var show = document.getElementById(show); - if (show.style.display === "none") { - show.style.display = "block"; - document.getElementById(var_id).value = 1; - } else { - show.style.display = "none"; - document.getElementById(var_id).value = 0; - } - require_fields(obj); +function on_ventilation_type_change(){ + ventilation_types = $('input[type=radio][name=ventilation_type]'); + ventilation_types.each(function( index ) { + if (this.checked) { + getChildElement($(this)).show(); + require_fields(this); + } else { + getChildElement($(this)).hide(); + unrequire_fields(this); + // Clear the inputs for this newly hidden child element. + getChildElement($(this)).find('input').not('input[type=radio]').val(''); + getChildElement($(this)).find('input[type=radio]').prop("checked", false); + getChildElement($(this)).find('input').prop("required", false); + } + }); } -function show_hide(show, hide, obj) { - var show = document.getElementById(show); - var hide = document.getElementById(hide); - var ventilation_type = document.getElementById("ventilation_type"); - var mechanical_ventilation_type = document.getElementById("mechanical_ventilation_type"); - if (show.style.display === "block") { - show.style.display = "none"; - obj.checked = false; - ventilation_type.value = ""; - mechanical_ventilation_type.value = ""; - unrequire_fields(obj); - } else if (show.style.display === "none") { - show.style.display = "block"; - hide.style.display = "none"; - ventilation_type.value = obj.id; - require_fields(obj); -} } - -function update_windows_open(obj) { - var windows_open = document.getElementById("windows_open"); - windows_open.value = obj.id; +function getChildElement(elem) { + // Get the element named in the given element's data-enables attribute. + return $("#" + elem.data("enables")); } + /* -------Required fields------- */ function require_fields(obj){ switch(obj.id) { @@ -119,17 +106,11 @@ function require_natural_ventilation(option) { function require_air_changes(option) { $("#air_changes").prop('required',option); - if (option) { - var mechanical_ventilation_type = document.getElementById("mechanical_ventilation_type"); - mechanical_ventilation_type.value = "air_changes"; -} } +} function require_air_supply(option) { $("#air_supply").prop('required',option); - if (option) { - var mechanical_ventilation_type = document.getElementById("mechanical_ventilation_type"); - mechanical_ventilation_type.value = "air_supply"; -} } +} function require_single_event(option) { $("#single_event_date").prop('required',option); @@ -224,7 +205,24 @@ function objectifyForm(formArray) { return returnArray; } -$(document).ready(function() { +/* ------ On Load ---------- */ + +$( document ).ready(function() { + // When the document is ready, deal with the fact that we may be here + // as a result of a forward/back browser action. If that is the case, update + // the visibility of some of our inputs. + + // When the ventilation_type changes we want to make its respective + // children show/hide. + ventilation_types = $("input[type=radio][name=ventilation_type]"); + ventilation_types.change(on_ventilation_type_change); + // Call the function now to handle forward/back button presses in the browser. + on_ventilation_type_change(); + + $("input[name=mechanical_ventilation_type]").change(function(){ + console.log('Changed!'); + }) + // Setup the maximum number of people at page load (to handle back/forward), // and update it when total people is changed. setMaxInfectedPeople(); @@ -234,4 +232,4 @@ $(document).ready(function() { if(radioValue.val()){ require_fields(radioValue.get(0)); } -}) +});