From 12fadae372c29da1bf5f1f6c9193df8482e8b5fa Mon Sep 17 00:00:00 2001 From: Phil Elson Date: Fri, 6 Nov 2020 16:59:17 +0100 Subject: [PATCH] Make the data from the form optional to avoid some of the common failures we're seeing. --- cara/apps/calculator/model_generator.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cara/apps/calculator/model_generator.py b/cara/apps/calculator/model_generator.py index 56b5161c..1a68a4d5 100644 --- a/cara/apps/calculator/model_generator.py +++ b/cara/apps/calculator/model_generator.py @@ -44,6 +44,12 @@ class FormData: @classmethod def from_dict(cls, form_data: typing.Dict) -> "FormData": + + valid_na_values = ['windows_open', 'ventilation_type', 'mechanical_ventilation_type'] + for name in valid_na_values: + if not form_data.get(name, ''): + form_data[name] = 'not-applicable' + validation_tuples = [('activity_type', ACTIVITY_TYPES), ('event_type', EVENT_TYPES), ('mechanical_ventilation_type', MECHANICAL_VENTILATION_TYPES), @@ -295,11 +301,11 @@ def baseline_raw_form_data(): ACTIVITY_TYPES = {'office', 'training', 'workshop'} EVENT_TYPES = {'single_event', 'recurrent_event'} -MECHANICAL_VENTILATION_TYPES = {'air_changes', 'air_supply', ''} +MECHANICAL_VENTILATION_TYPES = {'air_changes', 'air_supply', 'not-applicable'} MASK_WEARING = {'continuous', 'removed'} -VENTILATION_TYPES = {'natural', 'mechanical', ''} +VENTILATION_TYPES = {'natural', 'mechanical', 'not-applicable'} VOLUME_TYPES = {'room_volume', 'room_dimensions'} -WINDOWS_OPEN = {'always', 'interval', 'breaks'} +WINDOWS_OPEN = {'always', 'interval', 'breaks', 'not-applicable'} def time_string_to_minutes(time: str) -> int: