From d4a0566782e016dbfef2ab8e5163730d1297e6c8 Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Fri, 6 Nov 2020 20:41:12 +0100 Subject: [PATCH 1/2] Don't reset the ventilation visibility when we hit back in the browser. --- cara/apps/calculator/static/form.html | 17 ++++---- cara/apps/calculator/static/js/form.js | 56 +++++++++++++++++--------- 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/cara/apps/calculator/static/form.html b/cara/apps/calculator/static/form.html index 01d2d7da..568466ff 100644 --- a/cara/apps/calculator/static/form.html +++ b/cara/apps/calculator/static/form.html @@ -37,29 +37,26 @@ Beta v1.0.0 Please send feedback to Ventilation type: - Mechanical - Natural
+ Mechanical + Natural
HEPA filtration: diff --git a/cara/apps/calculator/static/js/form.js b/cara/apps/calculator/static/js/form.js index fd1fcebb..22436fe9 100644 --- a/cara/apps/calculator/static/js/form.js +++ b/cara/apps/calculator/static/js/form.js @@ -11,30 +11,35 @@ function show(show, var_id, obj) { require_fields(obj); } -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 on_ventilation_type_change(){ + ventilation_types = $('input[type=radio][name=RADIO_ventilation_type]'); + ventilation_types.each(function( index ) { + if (this.checked) { + getChildElement($(this)).show(); + require_fields(this); + $('input[name=ventilation_type]').val(this.id); + } else { + getChildElement($(this)).hide(); + unrequire_fields(this); + // Clear the inputs for this newly hidden child element. + getChildElement($(this)).find('input').val(''); + } + }); +} + + +function getChildElement(elem) { + // Get the element named in the given element's data-enables attribute. + return $("#" + elem.data("enables")); +} function update_windows_open(obj) { var windows_open = document.getElementById("windows_open"); windows_open.value = obj.id; } + /* -------Required fields------- */ function require_fields(obj){ switch(obj.id) { @@ -224,7 +229,20 @@ 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=RADIO_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(); + // Setup the maximum number of people at page load (to handle back/forward), // and update it when total people is changed. setMaxInfectedPeople(); @@ -234,4 +252,4 @@ $(document).ready(function() { if(radioValue.val()){ require_fields(radioValue.get(0)); } -}) +}); From 4f2fb894fad624daad304014dbd83cefcb3bb4a0 Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Fri, 6 Nov 2020 22:26:32 +0100 Subject: [PATCH 2/2] Implement no-ventilation option in calculator. --- cara/apps/calculator/model_generator.py | 23 +++++++------- cara/apps/calculator/static/form.html | 6 ++-- cara/apps/calculator/static/js/form.js | 42 +++++++------------------ 3 files changed, 25 insertions(+), 46 deletions(-) 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 568466ff..98a3b23f 100644 --- a/cara/apps/calculator/static/form.html +++ b/cara/apps/calculator/static/form.html @@ -36,9 +36,9 @@ Beta v1.0.0 Please send feedback to Ventilation type: - - Mechanical - Natural
+ No ventilation + Mechanical + Natural