diff --git a/cara/apps/calculator/__init__.py b/cara/apps/calculator/__init__.py index 9d7887f9..96f8bd83 100644 --- a/cara/apps/calculator/__init__.py +++ b/cara/apps/calculator/__init__.py @@ -4,7 +4,6 @@ import os from pathlib import Path import jinja2 -import mistune from tornado.web import Application, RequestHandler, StaticFileHandler from . import model_generator @@ -12,6 +11,16 @@ from .report_generator import build_report from .user import AuthenticatedUser, AnonymousUser +# The calculator version is based on a combination of the model version and the +# semantic version of the calculator itself. The version uses the terms +# "{MAJOR}.{MINOR}.{PATCH}" to describe the 3 distinct numbers constituing a version. +# Effectively, if the model increases its MAJOR version then so too should this +# 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 CARA version (found at ``cara.__version__``). +__version__ = "1.5.0" + + class BaseRequestHandler(RequestHandler): async def prepare(self): """Called at the beginning of a request before `get`/`post`/etc.""" @@ -81,6 +90,7 @@ class CalculatorForm(BaseRequestHandler): report = template.render( user=self.current_user, xsrf_form_html=self.xsrf_form_html(), + calculator_version=__version__, ) self.finish(report) diff --git a/cara/apps/calculator/model_generator.py b/cara/apps/calculator/model_generator.py index 14d30b45..baa164e1 100644 --- a/cara/apps/calculator/model_generator.py +++ b/cara/apps/calculator/model_generator.py @@ -7,6 +7,7 @@ import numpy as np from cara import models from cara import data +from .. import calculator LOG = logging.getLogger(__name__) @@ -551,7 +552,7 @@ def baseline_raw_form_data(): 'mask_type': 'Type I', 'mask_wearing_option': 'mask_off', 'mechanical_ventilation_type': '', - 'model_version': 'v1.2.0', + 'model_version': calculator.__version__, 'opening_distance': '0.2', 'event_month': 'January', 'room_number': '123', diff --git a/cara/apps/calculator/report_generator.py b/cara/apps/calculator/report_generator.py index 046d27cd..3eb65193 100644 --- a/cara/apps/calculator/report_generator.py +++ b/cara/apps/calculator/report_generator.py @@ -260,13 +260,11 @@ def comparison_report(scenarios: typing.Dict[str, models.ExposureModel]): def build_report(base_url: str, model: models.ExposureModel, form: FormData): - now = datetime.now() - time = now.strftime("%d/%m/%Y %H:%M:%S") - request = {"the": "form", "request": "data"} + now = datetime.utcnow().astimezone() + time = now.strftime("%Y-%m-%d %H:%M:%S UTC") context = { 'model': model, - 'request': request, 'form': form, 'creation_date': time, } diff --git a/cara/apps/calculator/templates/calculator.form.html.j2 b/cara/apps/calculator/templates/calculator.form.html.j2 index 9a281243..88993e2f 100644 --- a/cara/apps/calculator/templates/calculator.form.html.j2 +++ b/cara/apps/calculator/templates/calculator.form.html.j2 @@ -1,6 +1,5 @@ {% extends "layout.html.j2" %} -{% set MODEL_VERSION="v1.5.1" %} {% set DEBUG=False %} {% set active_page="calculator/" %} @@ -20,7 +19,7 @@
-{{ MODEL_VERSION }} Please send feedback to CARA-dev@cern.ch +v{{ calculator_version }} Please send feedback to CARA-dev@cern.ch

CARA - COVID Airborne Risk Assessment calculator

@@ -33,7 +32,7 @@ {% endif %} {{ xsrf_form_html }} - +
diff --git a/cara/apps/calculator/templates/report.html.j2 b/cara/apps/calculator/templates/report.html.j2 index 2b94d3e7..93996d71 100644 --- a/cara/apps/calculator/templates/report.html.j2 +++ b/cara/apps/calculator/templates/report.html.j2 @@ -17,7 +17,7 @@

Report

-

Created {{ creation_date }} using model version {{ form.model_version }}


+

Created {{ creation_date }} using model version v{{ form.model_version }}


Applicable rules:
Please ensure that this scenario conforms to current CERN HSE rules (minimum ventilation requirements, mask wearing and the maximum number of people permitted in a space).