From 5771b6c5156f70e5583fcd11c5f185cd689af41c Mon Sep 17 00:00:00 2001 From: Maciej Urban Date: Tue, 7 Jun 2022 03:10:16 +0200 Subject: [PATCH] Showing message for when vaccinations finish, minor validation fix --- model.pyw | 18 +++++++++++++++++- utils/validation.py | 4 ++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/model.pyw b/model.pyw index 8f59f8f..4f14026 100644 --- a/model.pyw +++ b/model.pyw @@ -243,7 +243,7 @@ def show_param_window(): validate_params_vac(vac_parameters) except ValueError: sg.popup_error( - "Vaccination eff must be a value between 0 and 1, rate, start and end parameters must all be non negative, whole numbers.", + "Vaccination eff must be a value between 0 and 1, rate, start and end parameters must all be non negative, whole numbers. Start parameter must also be less than or equal to the end parameter for all age groups.", title="Invalid vaccination parameters", icon=icon, ) @@ -584,6 +584,22 @@ while True: fig_agg = draw_fig( window["-CANVAS-"].TKCanvas, fig, window["-TOOLBAR-"].TKCanvas ) + msg = "" + for k, v in vac_parameters.items(): + if k != "eff" and vac_E and v[0]: + indexes = np.where( + y[ + 1, + np.searchsorted(t, v[1]) : np.searchsorted(t, v[2]), + int(k[-1]) - 1, + ] + == 0 + ) + if indexes[0].size > 0: + first_zero = t[indexes[0][0]] + msg += f"Age group {k[-1]} fully vaccinated on day: {int(first_zero+v[1])}\n" + if msg: + sg.popup_ok(msg, title="Vaccination", icon=icon) except ValueError as e: sg.popup_error( "Invalid parameters: " + str(e), title="Invalid parameters", icon=icon diff --git a/utils/validation.py b/utils/validation.py index 9b59f90..e775816 100644 --- a/utils/validation.py +++ b/utils/validation.py @@ -45,6 +45,10 @@ def validate_params_vac(vac_params): raise ValueError( "All values like vaccination rate, start day, end day must be positive integers." ) + if vac_params[grp][1] > vac_params[grp][2]: + raise ValueError( + "Start day must be less than or equal to end day for all age groups." + ) if vac_params[grp][0] < 0 or vac_params[grp][1] < 0 or vac_params[grp][2] < 0: raise ValueError( "All values like vaccination rate, start day, end day must be positive numbers."