Skip to content

Commit

Permalink
Merge branch 'changes/form_data_schema_data' into 'master'
Browse files Browse the repository at this point in the history
Added placeholder for activity types

See merge request caimira/caimira!489
  • Loading branch information
lrdossan committed Apr 18, 2024
2 parents a843c47 + 6f537e1 commit 585dba5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
8 changes: 7 additions & 1 deletion caimira/apps/calculator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
# calculator version. If the calculator needs to make breaking changes (e.g. change
# form attributes) then it can also increase its MAJOR version without needing to
# increase the overall CAiMIRA version (found at ``caimira.__version__``).
__version__ = "4.15.0"
__version__ = "4.15.1"

LOG = logging.getLogger("Calculator")

Expand Down Expand Up @@ -294,6 +294,11 @@ def get(self):

class CalculatorForm(BaseRequestHandler):
def get(self):
data_registry: DataRegistry = self.settings["data_registry"]
data_service: typing.Optional[DataService] = self.settings.get("data_service", None)
if data_service:
data_service.update_registry(data_registry)

template_environment = self.settings["template_environment"]
template = template_environment.get_template(
"calculator.form.html.j2")
Expand All @@ -304,6 +309,7 @@ def get(self):
get_calculator_url = template.globals["get_calculator_url"],
calculator_version=__version__,
text_blocks=template_environment.globals["common_text"],
data_registry=data_registry.to_dict(),
)
self.finish(report)

Expand Down
18 changes: 6 additions & 12 deletions caimira/apps/templates/base/calculator.form.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -506,18 +506,12 @@
<div class="col-sm-4"><label class="col-form-label">Activity type:</label></div>
<div class="col-sm-6">
<select id="activity_type" name="activity_type" class="form-control">
<option value="office">Office</option>
<option value="smallmeeting">Small meeting (<10 occ.)</option>
<option value="largemeeting">Large meeting (>=10 occ.)</option>
<option value="callcentre">Call Centre</option>
<option value="controlroom-day">Control Room - Day shift</option>
<option value="controlroom-night">Control Room - Night shift</option>
<option value="library">Library</option>
<option value="lab">Laboratory</option>
<option value="workshop">Workshop</option>
<option value="training">Conference/Training (speaker infected)</option>
<option value="training_attendee">Conference/Training (attendee infected)</option>
<option value="gym">Gym</option>
{% for activity_type_key, activity_type_value in data_registry.population_scenario_activity.items() %}
{% if activity_type_key not in ["precise", "household-day", "household-night", "primary-school",
"secondary-school", "university", "restaurant"] %}
<option value="{{ activity_type_key }}">{{ activity_type_value['placeholder'] }}</option>
{% endif %}
{% endfor %}
</select>
</div>
</div>
Expand Down
35 changes: 28 additions & 7 deletions caimira/store/data_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,63 +389,84 @@ class DataRegistry:
}
monte_carlo_sample_size = 250000
population_scenario_activity = {
"office": {"activity": "Seated", "expiration": {"Speaking": 1, "Breathing": 2}},
"office": {"placeholder": "Office", "activity": "Seated", "expiration": {"Speaking": 1, "Breathing": 2}},
"smallmeeting": {
"placeholder": "Small meeting (<10 occ.)",
"activity": "Seated",
"expiration": {"Speaking": 1},
},
"largemeeting": {
"placeholder": "Large meeting (>= 10 occ.)",
"activity": "Standing",
"expiration": {"Speaking": 1, "Breathing": 2},
},
"callcenter": {"activity": "Seated", "expiration": {"Speaking": 1}},
"callcenter": {"placeholder": "Call Center", "activity": "Seated", "expiration": {"Speaking": 1}},
"controlroom-day": {
"placeholder": "Control Room - Day shift",
"activity": "Seated",
"expiration": {"Speaking": 1, "Breathing": 1},
},
"controlroom-night": {
"placeholder": "Control Room - Night shift",
"activity": "Seated",
"expiration": {"Speaking": 1, "Breathing": 9},
},
"library": {"activity": "Seated", "expiration": {"Breathing": 1}},
"library": {"placeholder": "Library", "activity": "Seated", "expiration": {"Breathing": 1}},
"lab": {
"placeholder": "Lab",
"activity": "Light activity",
"expiration": {"Speaking": 1, "Breathing": 1},
},
"workshop": {
"placeholder": "Workshop",
"activity": "Moderate activity",
"expiration": {"Speaking": 1, "Breathing": 1},
},
"training": {"activity": "Standing", "expiration": {"Speaking": 1}},
"training_attendee": {"activity": "Seated", "expiration": {"Breathing": 1}},
"gym": {"activity": "Heavy exercise", "expiration": {"Breathing": 1}},
"training": {"placeholder": "Conference/Training (speaker infected)", "activity": "Standing", "expiration": {"Speaking": 1}},
"training_attendee": {"placeholder": "Conference/Training (attendee infected)", "activity": "Seated", "expiration": {"Breathing": 1}},
"gym": {"placeholder": "Gym", "activity": "Heavy exercise", "expiration": {"Breathing": 1}},
"household-day": {
"placeholder": "Household (day time)",
"activity": "Light activity",
"expiration": {"Breathing": 5, "Speaking": 5},
},
"household-night": {
"placeholder": "Household (evening and night time)",
"activity": "Seated",
"expiration": {"Breathing": 7, "Speaking": 3},
},
"primary-school": {
"placeholder": "Primary school",
"activity": "Light activity",
"expiration": {"Breathing": 5, "Speaking": 5},
},
"secondary-school": {
"placeholder": "Primary school",
"activity": "Light activity",
"expiration": {"Breathing": 7, "Speaking": 3},
},
"university": {
"placeholder": "University",
"activity": "Seated",
"expiration": {"Breathing": 9, "Speaking": 1},
},
"restaurant": {
"placeholder": "Restaurant",
"activity": "Seated",
"expiration": {"Breathing": 1, "Speaking": 9},
},
"precise": {"activity": "", "expiration": {}},
"precise": {"placeholder": "Precise", "activity": "", "expiration": {}},
}

def to_dict(self):
# Filter out methods, special attributes, and non-serializable objects
data_dict = {
key: value
for key, value in self.__class__.__dict__.items()
if not key.startswith("__") and not callable(value) and not isinstance(value, (type, classmethod, staticmethod))
}
return data_dict

def update(self, data, version=None):
"""Update local cache with data provided as argument."""
for attr_name, value in data.items():
Expand Down

0 comments on commit 585dba5

Please sign in to comment.