removed fitting ventilation type input (not needed)

This commit is contained in:
lrdossan 2024-06-27 16:00:20 +01:00
parent f83a886928
commit 84ffcb5e23
5 changed files with 54 additions and 111 deletions

View file

@ -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']

View file

@ -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

View file

@ -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.<br />`
);
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}).<br />`
);
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.</br>`
`'${$ventilationStates.attr('name')}' must have more than one ventilation state change (at least the beggining and end of simulation time).<br />`
);
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}).<br />`
);
submit = false;
}
}
}
else {
insertErrorFor(
$referenceNode,
`'${$ventilationStates.attr('name')}' must be a list of numbers.</br>`
`'${$ventilationStates.attr('name')}' must be a list.</br>`
);
submit = false;
}
} else {
} catch {
insertErrorFor(
$referenceNode,
`'${$ventilationStates.attr('name')}' must be defined.</br>`
`'${$ventilationStates.attr('name')}' must be a list of numbers.</br>`
);
submit = false;
}
@ -253,8 +239,13 @@ function validateCO2Form() {
submit = false;
}
}
} else {
insertErrorFor(
$referenceNode,
`'${$ventilationStates.attr('name')}' must be defined.</br>`
);
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();

View file

@ -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();

View file

@ -347,16 +347,9 @@
<img id="CO2_data_plot"/><br>
<p id="suggestion_lines_txt" class="text-danger text-center">
The dashed lines are suggestions for the ventilation transition times<br>
(generated from the input data using the Pelt algorithm).</p>
<strong>Ventilation scheme:</strong>
<div>
<input class="ml-2" type="radio" id="fitting_natural_ventilation" name="fitting_ventilation_type" value='fitting_natural_ventilation' checked="checked" data-enables="#DIVfitting_natural_ventilation" form="not-submitted" >
<label for="fitting_natural_ventilation">Natural</label>
<input class="ml-2" type="radio" id="fitting_mechanical_ventilation" name="fitting_ventilation_type" value='fitting_mechanical_ventilation' form="not-submitted">
<label for="fitting_mechanical_ventilation">Mechanical</label>
</div>
<div id="DIVfitting_natural_ventilation" class="form-group mb-0" style="display: none">
(generated from the input data using the Pelt algorithm).
</p>
<div id="DIVfitting_ventilation" class="form-group mb-0">
<label for="fitting_ventilation_states">Please enter the ventilation state change times, separated by comma - e.g. [8.5, 10, 11.5, 17]. </label>
<div data-tooltip="Default values indicated below correspond to the dashed lines in the above plot - these are only suggestions and can be changed.">
<span class="tooltip_text">?</span>