From 6a69f91c90b9d28434315113a002461c304c210e Mon Sep 17 00:00:00 2001 From: Luis Aleixo Date: Mon, 11 Mar 2024 10:33:49 +0100 Subject: [PATCH 1/2] added placeholder for activity types and fetched this data directly in form calculator --- caimira/apps/calculator/__init__.py | 6 ++++ .../templates/base/calculator.form.html.j2 | 18 ++++------ caimira/store/data_registry.py | 35 +++++++++++++++---- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/caimira/apps/calculator/__init__.py b/caimira/apps/calculator/__init__.py index b2a0e051..03543373 100644 --- a/caimira/apps/calculator/__init__.py +++ b/caimira/apps/calculator/__init__.py @@ -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") @@ -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) diff --git a/caimira/apps/templates/base/calculator.form.html.j2 b/caimira/apps/templates/base/calculator.form.html.j2 index 3344183b..6842ea63 100644 --- a/caimira/apps/templates/base/calculator.form.html.j2 +++ b/caimira/apps/templates/base/calculator.form.html.j2 @@ -506,18 +506,12 @@
diff --git a/caimira/store/data_registry.py b/caimira/store/data_registry.py index 5e708fd2..e1074587 100644 --- a/caimira/store/data_registry.py +++ b/caimira/store/data_registry.py @@ -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(): From 6f537e1df36207f4e6fedee61927611d6244accd Mon Sep 17 00:00:00 2001 From: Luis Aleixo Date: Thu, 18 Apr 2024 10:35:22 +0200 Subject: [PATCH 2/2] updated patch version --- caimira/apps/calculator/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/caimira/apps/calculator/__init__.py b/caimira/apps/calculator/__init__.py index 03543373..be8de7ab 100644 --- a/caimira/apps/calculator/__init__.py +++ b/caimira/apps/calculator/__init__.py @@ -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")