diff --git a/caimira/apps/calculator/co2_model_generator.py b/caimira/apps/calculator/co2_model_generator.py
index 3544fe54..51a950b2 100644
--- a/caimira/apps/calculator/co2_model_generator.py
+++ b/caimira/apps/calculator/co2_model_generator.py
@@ -22,6 +22,7 @@ class CO2FormData(FormData):
CO2_data: dict
fitting_ventilation_states: list
fitting_ventilation_type: str
+ room_capacity: int
#: The default values for undefined fields. Note that the defaults here
#: and the defaults in the html form must not be contradictory.
@@ -45,6 +46,7 @@ class CO2FormData(FormData):
'infected_lunch_start': '12:30',
'infected_people': 1,
'infected_start': '08:30',
+ 'room_capacity': 10,
'room_volume': NO_DEFAULT,
'specific_breaks': '{}',
'total_people': NO_DEFAULT,
@@ -62,6 +64,14 @@ class CO2FormData(FormData):
# Validate population parameters
self.validate_population_parameters()
+ # Validate room capacity
+ if type(self.room_capacity) is not int:
+ raise TypeError(f'The room capacity should be a valid integer (> 0). Got {type(self.room_capacity)}.')
+ if self.room_capacity <= 0:
+ raise TypeError(f'The room capacity should be a valid integer (> 0). Got {self.room_capacity}.')
+ if self.room_capacity < self.total_people:
+ raise TypeError(f'The room capacity should be higher than the total people in the room. Got {self.room_capacity}.')
+
# Validate specific inputs - breaks (exposed and infected)
if self.specific_breaks != {}:
if type(self.specific_breaks) is not dict:
@@ -181,6 +191,7 @@ class CO2FormData(FormData):
return models.CO2DataModel(
data_registry=self.data_registry,
+ room_capacity=self.room_capacity,
room_volume=self.room_volume,
occupancy=models.IntPiecewiseConstant(transition_times=tuple(all_state_changes), values=tuple(total_people)),
ventilation_transition_times=self.ventilation_transition_times(),
diff --git a/caimira/apps/calculator/static/js/co2_form.js b/caimira/apps/calculator/static/js/co2_form.js
index fb45044b..5b8d4a2c 100644
--- a/caimira/apps/calculator/static/js/co2_form.js
+++ b/caimira/apps/calculator/static/js/co2_form.js
@@ -19,6 +19,7 @@ const CO2_data_form = [
"infected_lunch_start",
"infected_people",
"infected_start",
+ "room_capacity",
"room_volume",
"specific_breaks",
"total_people",
@@ -137,6 +138,7 @@ function generateJSONStructure(endpoint, jsonData) {
$("#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);
}
}
@@ -152,7 +154,9 @@ function validateFormInputs(obj) {
const $referenceNode = $("#DIVCO2_data_dialog");
for (let i = 0; i < CO2_data_form.length; i++) {
const $requiredElement = $(`[name=${CO2_data_form[i]}]`).first();
- if ($requiredElement.attr('name') !== "fitting_ventilation_states" && $requiredElement.val() === "") {
+ if ($requiredElement.attr('name') !== "fitting_ventilation_states" &&
+ $requiredElement.attr('name') !== "room_capacity" &&
+ $requiredElement.val() === "") {
insertErrorFor(
$referenceNode,
`'${$requiredElement.attr('name')}' must be defined.
`
@@ -236,6 +240,36 @@ function validateCO2Form() {
);
submit = false;
}
+ // Validate room capacity
+ const roomCapacity = $fittingToSubmit.find("input[name=room_capacity]");
+ const roomCapacityVal = roomCapacity.val();
+ if (roomCapacityVal !== "") {
+ const roomCapacityNumber = Number(roomCapacityVal);
+ const totalPeopleNumber = Number($("#total_people").val());
+ if (!Number.isInteger(roomCapacityNumber) || roomCapacityNumber <= 0) {
+ insertErrorFor(
+ $referenceNode,
+ `'${roomCapacity.attr('name')}' must be a valid integer (> 0).`
+ );
+ submit = false;
+ }
+ else if (roomCapacityNumber < totalPeopleNumber){
+ insertErrorFor(
+ $referenceNode,
+ `'${roomCapacity.attr('name')}' must be higher than the total people.`
+ );
+ submit = false;
+ }
+ console.log(roomCapacityNumber)
+ console.log(totalPeopleNumber)
+ }
+ else {
+ insertErrorFor(
+ $referenceNode,
+ `'${roomCapacity.attr('name')}' must be defined.`
+ );
+ submit = false;
+ }
}
return submit;
@@ -341,6 +375,11 @@ function submitFittingAlgorithm(url) {
"disabled",
true
);
+ // Disable room capacity input
+ $("#room_capacity").prop(
+ "disabled",
+ true
+ );
// Prepare data for submission
const CO2_mapping = formatCO2DataForm(CO2_data_form);
diff --git a/caimira/apps/templates/base/calculator.form.html.j2 b/caimira/apps/templates/base/calculator.form.html.j2
index 497bf33e..377f0433 100644
--- a/caimira/apps/templates/base/calculator.form.html.j2
+++ b/caimira/apps/templates/base/calculator.form.html.j2
@@ -363,6 +363,11 @@
+ Room data:
+