From 84ffcb5e2374107ad761b1af21d516465b388561 Mon Sep 17 00:00:00 2001 From: lrdossan Date: Thu, 27 Jun 2024 16:00:20 +0100 Subject: [PATCH] removed fitting ventilation type input (not needed) --- .../apps/calculator/co2_model_generator.py | 16 +-- caimira/apps/calculator/model_generator.py | 11 +- caimira/apps/calculator/static/js/co2_form.js | 105 +++++++----------- caimira/apps/calculator/static/js/form.js | 20 ---- .../templates/base/calculator.form.html.j2 | 13 +-- 5 files changed, 54 insertions(+), 111 deletions(-) diff --git a/caimira/apps/calculator/co2_model_generator.py b/caimira/apps/calculator/co2_model_generator.py index 440a2b1c..4e238ce4 100644 --- a/caimira/apps/calculator/co2_model_generator.py +++ b/caimira/apps/calculator/co2_model_generator.py @@ -21,13 +21,13 @@ LOG = logging.getLogger(__name__) class CO2FormData(FormData): CO2_data: dict fitting_ventilation_states: list - fitting_ventilation_type: str room_capacity: typing.Optional[int] #: The default values for undefined fields. Note that the defaults here #: and the defaults in the html form must not be contradictory. _DEFAULTS: typing.ClassVar[typing.Dict[str, typing.Any]] = { 'CO2_data': '{}', + 'fitting_ventilation_states': '[]', 'exposed_coffee_break_option': 'coffee_break_0', 'exposed_coffee_duration': 5, 'exposed_finish': '17:30', @@ -35,8 +35,6 @@ class CO2FormData(FormData): 'exposed_lunch_option': True, 'exposed_lunch_start': '12:30', 'exposed_start': '08:30', - 'fitting_ventilation_states': '[]', - 'fitting_ventilation_type': 'fitting_natural_ventilation', 'infected_coffee_break_option': 'coffee_break_0', 'infected_coffee_duration': 5, 'infected_dont_have_breaks_with_exposed': False, @@ -173,14 +171,10 @@ class CO2FormData(FormData): state_change_times.update(exposed_presence.transition_times()) return sorted(state_change_times) - def ventilation_transition_times(self) -> typing.Tuple[float, ...]: - # Check what type of ventilation is considered for the fitting - if self.fitting_ventilation_type == 'fitting_natural_ventilation': - vent_states = self.fitting_ventilation_states - vent_states.append(self.CO2_data['times'][-1]) - return tuple(vent_states) - else: - return tuple((self.CO2_data['times'][0], self.CO2_data['times'][-1])) + def ventilation_transition_times(self) -> typing.List[float]: + vent_states = self.fitting_ventilation_states + vent_states.append(self.CO2_data['times'][-1]) # The last time value is always needed for the last ACH interval. + return vent_states def build_model(self, size=None) -> models.CO2DataModel: # type: ignore size = size or self.data_registry.monte_carlo['sample_size'] diff --git a/caimira/apps/calculator/model_generator.py b/caimira/apps/calculator/model_generator.py index d1895848..b0656851 100644 --- a/caimira/apps/calculator/model_generator.py +++ b/caimira/apps/calculator/model_generator.py @@ -330,13 +330,10 @@ class VirusFormData(FormData): min(self.infected_start, self.exposed_start)/60) if self.ventilation_type == 'from_fitting': ventilations = [] - if self.CO2_fitting_result['fitting_ventilation_type'] == 'fitting_natural_ventilation': - transition_times = self.CO2_fitting_result['transition_times'] - for index, (start, stop) in enumerate(zip(transition_times[:-1], transition_times[1:])): - ventilations.append(models.AirChange(active=models.SpecificInterval(present_times=((start, stop), )), - air_exch=self.CO2_fitting_result['ventilation_values'][index])) - else: - ventilations.append(models.AirChange(active=always_on, air_exch=self.CO2_fitting_result['ventilation_values'][0])) + transition_times = self.CO2_fitting_result['transition_times'] + for index, (start, stop) in enumerate(zip(transition_times[:-1], transition_times[1:])): + ventilations.append(models.AirChange(active=models.SpecificInterval(present_times=((start, stop), )), + air_exch=self.CO2_fitting_result['ventilation_values'][index])) return models.MultipleVentilation(tuple(ventilations)) # Initializes a ventilation instance as a window if 'natural_ventilation' is selected, or as a HEPA-filter otherwise diff --git a/caimira/apps/calculator/static/js/co2_form.js b/caimira/apps/calculator/static/js/co2_form.js index 77b0b756..5f6ff406 100644 --- a/caimira/apps/calculator/static/js/co2_form.js +++ b/caimira/apps/calculator/static/js/co2_form.js @@ -9,7 +9,6 @@ const CO2_data_form = [ "exposed_lunch_start", "exposed_start", "fitting_ventilation_states", - "fitting_ventilation_type", "infected_coffee_break_option", "infected_coffee_duration", "infected_dont_have_breaks_with_exposed", @@ -137,7 +136,6 @@ function generateJSONStructure(endpoint, jsonData) { inputToPopulate.val(JSON.stringify(finalStructure)); $("#generate_fitting_data").prop("disabled", false); $("#fitting_ventilation_states").prop("disabled", false); - $("[name=fitting_ventilation_type]").prop("disabled", false); $("#room_capacity").prop("disabled", false); plotCO2Data(endpoint); } @@ -177,66 +175,54 @@ function validateCO2Form() { if (validateFormInputs($("#button_fit_data"))) submit = true; const $fittingToSubmit = $('#DIVCO2_fitting_to_submit'); - // Check if natural ventilation is selected - if ( - $fittingToSubmit.find('input[name="fitting_ventilation_type"]:checked').val() == - "fitting_natural_ventilation" - ) { - // Validate ventilation scheme - const $ventilationStates = $fittingToSubmit.find("input[name=fitting_ventilation_states]"); - const $referenceNode = $("#DIVCO2_fitting_result"); - if ($ventilationStates.val() !== "") { - // validate input format - try { - const parsedValue = JSON.parse($ventilationStates.val()); - if (Array.isArray(parsedValue)) { - if (parsedValue.length <= 1) { - insertErrorFor( - $referenceNode, - `'${$ventilationStates.attr('name')}' must have more than one $ventilationStates.
` - ); - submit = false; - } - else { - const infected_finish = $(`[name=infected_finish]`).first().val(); - const exposed_finish = $(`[name=exposed_finish]`).first().val(); - - const [hours_infected, minutes_infected] = infected_finish.split(":").map(Number); - const elapsed_time_infected = hours_infected * 60 + minutes_infected; - - const [hours_exposed, minutes_exposed] = exposed_finish.split(":").map(Number); - const elapsed_time_exposed = hours_exposed * 60 + minutes_exposed; - - const max_presence_time = Math.max(elapsed_time_infected, elapsed_time_exposed); - const max_transition_time = parsedValue[parsedValue.length - 1] * 60; - - if (max_transition_time > max_presence_time) { - insertErrorFor( - $referenceNode, - `The last transition time (${parsedValue[parsedValue.length - 1]}) should be before the last presence time (${max_presence_time / 60}).
` - ); - submit = false; - } - } - } - else { + // Validate ventilation scheme + const $ventilationStates = $fittingToSubmit.find("input[name=fitting_ventilation_states]"); + const $referenceNode = $("#DIVCO2_fitting_result"); + if ($ventilationStates.val() !== "") { + // validate input format + try { + const parsedValue = JSON.parse($ventilationStates.val()); + if (Array.isArray(parsedValue)) { + if (parsedValue.length <= 1) { insertErrorFor( $referenceNode, - `'${$ventilationStates.attr('name')}' must be a list.
` + `'${$ventilationStates.attr('name')}' must have more than one ventilation state change (at least the beggining and end of simulation time).
` ); submit = false; } - } catch { + else { + const infected_finish = $(`[name=infected_finish]`).first().val(); + const exposed_finish = $(`[name=exposed_finish]`).first().val(); + + const [hours_infected, minutes_infected] = infected_finish.split(":").map(Number); + const elapsed_time_infected = hours_infected * 60 + minutes_infected; + + const [hours_exposed, minutes_exposed] = exposed_finish.split(":").map(Number); + const elapsed_time_exposed = hours_exposed * 60 + minutes_exposed; + + const max_presence_time = Math.max(elapsed_time_infected, elapsed_time_exposed); + const max_transition_time = parsedValue[parsedValue.length - 1] * 60; + + if (max_transition_time > max_presence_time) { + insertErrorFor( + $referenceNode, + `The last transition time (${parsedValue[parsedValue.length - 1]}) should be before the last presence time (${max_presence_time / 60}).
` + ); + submit = false; + } + } + } + else { insertErrorFor( $referenceNode, - `'${$ventilationStates.attr('name')}' must be a list of numbers.
` + `'${$ventilationStates.attr('name')}' must be a list.
` ); submit = false; } - } else { + } catch { insertErrorFor( $referenceNode, - `'${$ventilationStates.attr('name')}' must be defined.
` + `'${$ventilationStates.attr('name')}' must be a list of numbers.
` ); submit = false; } @@ -253,8 +239,13 @@ function validateCO2Form() { submit = false; } } + } else { + insertErrorFor( + $referenceNode, + `'${$ventilationStates.attr('name')}' must be defined.
` + ); + submit = false; } - return submit; } @@ -369,17 +360,11 @@ function plotCO2Data(url) { function submitFittingAlgorithm(url) { if (validateCO2Form()) { - // Disable all the ventilation inputs - $("#fitting_ventilation_states, [name=fitting_ventilation_type]").prop( - "disabled", - true - ); // Disable room capacity input $("#room_capacity").prop( "disabled", true ); - // Prepare data for submission const CO2_mapping = formatCO2DataForm(CO2_data_form); $("#CO2_input_data_div").show(); @@ -423,12 +408,6 @@ function clearFittingResultComponent() { $referenceNode.find("#DIVCO2_fitting_to_submit").hide(); $referenceNode.find("#CO2_data_plot").attr("src", ""); - // Update the ventilation scheme components - $referenceNode.find("#fitting_ventilation_states, [name=fitting_ventilation_type]").prop( - "disabled", - false - ); - // Update the bottom right buttons $referenceNode.find("#generate_fitting_data").show(); $referenceNode.find("#save_and_dismiss_dialog").hide(); diff --git a/caimira/apps/calculator/static/js/form.js b/caimira/apps/calculator/static/js/form.js index e63bbb45..631be3cc 100644 --- a/caimira/apps/calculator/static/js/form.js +++ b/caimira/apps/calculator/static/js/form.js @@ -479,20 +479,6 @@ function on_coffee_break_option_change() { } } -function on_CO2_fitting_ventilation_change() { - ventilation_options = $('input[type=radio][name=fitting_ventilation_type]'); - ventilation_options.each(function (index) { - if (this.checked) { - getChildElement($(this)).show(); - require_fields(this); - } - else { - getChildElement($(this)).hide(); - require_fields(this); - } - }) -} - /* -------UI------- */ function show_disclaimer() { @@ -1070,12 +1056,6 @@ $(document).ready(function () { // Call the function now to handle forward/back button presses in the browser. on_coffee_break_option_change(); - // When the ventilation on the fitting changes we want to make its respective - // children show/hide. - $("input[type=radio][name=fitting_ventilation_type]").change(on_CO2_fitting_ventilation_change); - // Call the function now to handle forward/back button presses in the browser. - on_CO2_fitting_ventilation_change(); - // Setup the maximum number of people at page load (to handle back/forward), // and update it when total people is changed. validateMaxInfectedPeople(); diff --git a/caimira/apps/templates/base/calculator.form.html.j2 b/caimira/apps/templates/base/calculator.form.html.j2 index fa97661e..40fc6d90 100644 --- a/caimira/apps/templates/base/calculator.form.html.j2 +++ b/caimira/apps/templates/base/calculator.form.html.j2 @@ -347,16 +347,9 @@

The dashed lines are suggestions for the ventilation transition times
- (generated from the input data using the Pelt algorithm).

- Ventilation scheme: -
- - - - -
- -