Tidy up the month handling.
This commit is contained in:
parent
44a701ce5b
commit
e9456e10e5
2 changed files with 20 additions and 8 deletions
|
|
@ -105,9 +105,9 @@ class FormData:
|
|||
'infected_lunch_start': '12:30',
|
||||
'infected_people': _NO_DEFAULT,
|
||||
'infected_start': '08:30',
|
||||
'location_latitude': 46.20833,
|
||||
'location_longitude': 6.14275,
|
||||
'location_name': 'Geneva',
|
||||
'location_latitude': _NO_DEFAULT,
|
||||
'location_longitude': _NO_DEFAULT,
|
||||
'location_name': _NO_DEFAULT,
|
||||
'mask_type': 'Type I',
|
||||
'mask_wearing_option': 'mask_off',
|
||||
'mechanical_ventilation_type': 'not-applicable',
|
||||
|
|
@ -205,7 +205,8 @@ class FormData:
|
|||
('virus_type', VIRUS_TYPES),
|
||||
('volume_type', VOLUME_TYPES),
|
||||
('window_opening_regime', WINDOWS_OPENING_REGIMES),
|
||||
('window_type', WINDOWS_TYPES)]
|
||||
('window_type', WINDOWS_TYPES),
|
||||
('event_month', MONTH_NAMES)]
|
||||
for attr_name, valid_set in validation_tuples:
|
||||
if getattr(self, attr_name) not in valid_set:
|
||||
raise ValueError(f"{getattr(self, attr_name)} is not a valid value for {attr_name}")
|
||||
|
|
@ -261,11 +262,8 @@ class FormData:
|
|||
else:
|
||||
window_interval = always_on
|
||||
|
||||
#month = self.event_month[:3]
|
||||
datetime_object = datetime.datetime.strptime(self.event_month[:3], "%b")
|
||||
month = datetime_object.month
|
||||
month = MONTH_NAMES.index(self.event_month) + 1
|
||||
|
||||
# set location
|
||||
wx_station = self.nearest_weather_station()
|
||||
temp_profile = cara.data.weather.mean_hourly_temperatures(wx_station[0], month)
|
||||
|
||||
|
|
@ -622,6 +620,9 @@ def baseline_raw_form_data():
|
|||
'infected_lunch_start': '12:30',
|
||||
'infected_people': '1',
|
||||
'infected_start': '09:00',
|
||||
'location_latitude': 46.20833,
|
||||
'location_longitude': 6.14275,
|
||||
'location_name': 'Geneva',
|
||||
'mask_type': 'Type I',
|
||||
'mask_wearing_option': 'mask_off',
|
||||
'mechanical_ventilation_type': '',
|
||||
|
|
@ -658,6 +659,11 @@ WINDOWS_TYPES = {'window_sliding', 'window_hinged', 'not-applicable'}
|
|||
|
||||
COFFEE_OPTIONS_INT = {'coffee_break_0': 0, 'coffee_break_1': 1, 'coffee_break_2': 2, 'coffee_break_4': 4}
|
||||
|
||||
MONTH_NAMES = [
|
||||
'January', 'February', 'March', 'April', 'May', 'June', 'July',
|
||||
'August', 'September', 'October', 'November', 'December',
|
||||
]
|
||||
|
||||
|
||||
def _hours2timestring(hours: float):
|
||||
# Convert times like 14.5 to strings, like "14:30"
|
||||
|
|
|
|||
|
|
@ -434,6 +434,12 @@ def test_key_validation_mech_ventilation_type_na(baseline_form_data):
|
|||
model_generator.FormData.from_dict(baseline_form_data)
|
||||
|
||||
|
||||
def test_key_validation_event_month(baseline_form_data):
|
||||
baseline_form_data['event_month'] = 'invalid month'
|
||||
with pytest.raises(ValueError, match='invalid month is not a valid value for event_month'):
|
||||
model_generator.FormData.from_dict(baseline_form_data)
|
||||
|
||||
|
||||
def test_default_types():
|
||||
# Validate that FormData._DEFAULTS are complete and of the correct type.
|
||||
# Validate that we have the right types and matching attributes to the DEFAULTS.
|
||||
|
|
|
|||
Loading…
Reference in a new issue