From 01c54269d878babb6c0c7838ca0cdca86e6cee4f Mon Sep 17 00:00:00 2001 From: hdunham <70401017+hdunham@users.noreply.github.com> Date: Fri, 24 Mar 2023 11:42:13 -0600 Subject: [PATCH 1/5] make max_outage_duration required --- resilience_stats/models.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/resilience_stats/models.py b/resilience_stats/models.py index 62b50f6ba..330f28a07 100644 --- a/resilience_stats/models.py +++ b/resilience_stats/models.py @@ -493,8 +493,6 @@ class ERPOutageInputs(BaseModel, models.Model): related_name="ERPOutageInputs" ) max_outage_duration = models.IntegerField( - blank=True, - default=336, validators=[ MinValueValidator(1), MaxValueValidator(672), From 527293c255b888bf18d8d6b4169d4b0a3a553692 Mon Sep 17 00:00:00 2001 From: hdunham <70401017+hdunham@users.noreply.github.com> Date: Fri, 24 Mar 2023 11:42:16 -0600 Subject: [PATCH 2/5] Create 0012_alter_erpoutageinputs_max_outage_duration.py --- ...ter_erpoutageinputs_max_outage_duration.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 resilience_stats/migrations/0012_alter_erpoutageinputs_max_outage_duration.py diff --git a/resilience_stats/migrations/0012_alter_erpoutageinputs_max_outage_duration.py b/resilience_stats/migrations/0012_alter_erpoutageinputs_max_outage_duration.py new file mode 100644 index 000000000..0d46cf305 --- /dev/null +++ b/resilience_stats/migrations/0012_alter_erpoutageinputs_max_outage_duration.py @@ -0,0 +1,19 @@ +# Generated by Django 4.0.4 on 2023-03-24 17:35 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('resilience_stats', '0011_alter_erpgeneratorinputs_electric_efficiency_half_load_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='erpoutageinputs', + name='max_outage_duration', + field=models.IntegerField(help_text='Maximum outage duration modeled', validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(672)]), + ), + ] From 6f4e9d0ad965058fa8abe00e882f0cafeb6199b2 Mon Sep 17 00:00:00 2001 From: hdunham <70401017+hdunham@users.noreply.github.com> Date: Fri, 24 Mar 2023 11:43:20 -0600 Subject: [PATCH 3/5] check outage_durations not empty before calc max --- resilience_stats/api.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/resilience_stats/api.py b/resilience_stats/api.py index 3fc8b9aba..40b18d35a 100644 --- a/resilience_stats/api.py +++ b/resilience_stats/api.py @@ -166,9 +166,10 @@ def update_user_dict_with_values_from_reopt(user_dict_key:str, reopt_dict:dict): ## Outage ## critical_loads_kw = reopt_run_meta.ElectricLoadOutputs.dict["critical_load_series_kw"] update_user_dict_with_values_from_reopt("Outage", {"critical_loads_kw": critical_loads_kw}) - update_user_dict_with_values_from_reopt("Outage", { - "max_outage_duration": max(reopt_run_meta.ElectricUtilityInputs.dict["outage_durations"]) - }) + if len(reopt_run_meta.ElectricUtilityInputs.dict["outage_durations"]) > 0: + update_user_dict_with_values_from_reopt("Outage", { + "max_outage_duration": max(reopt_run_meta.ElectricUtilityInputs.dict["outage_durations"]) + }) ## Generator ## try: From bf6c2950f2c510395031827905f605eb8ebbbcf9 Mon Sep 17 00:00:00 2001 From: hdunham <70401017+hdunham@users.noreply.github.com> Date: Fri, 24 Mar 2023 11:43:45 -0600 Subject: [PATCH 4/5] validation error if no max_outage_duration --- resilience_stats/api.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/resilience_stats/api.py b/resilience_stats/api.py index 40b18d35a..97ae92f7c 100644 --- a/resilience_stats/api.py +++ b/resilience_stats/api.py @@ -170,6 +170,11 @@ def update_user_dict_with_values_from_reopt(user_dict_key:str, reopt_dict:dict): update_user_dict_with_values_from_reopt("Outage", { "max_outage_duration": max(reopt_run_meta.ElectricUtilityInputs.dict["outage_durations"]) }) + if bundle.data.get("Outage", {}).get("max_outage_duration",None) is None: + add_validation_err_msg_and_raise_400_response( + meta_dict, + "You must provide Outage max_outage_duration or the reopt_run_uuid of an optimization where ElectricUtility outage_durations was provided." + ) ## Generator ## try: From bd75a17b7b8889526f54a4de96edcdf66865d279 Mon Sep 17 00:00:00 2001 From: hdunham <70401017+hdunham@users.noreply.github.com> Date: Fri, 24 Mar 2023 11:43:48 -0600 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52654d644..fe992a55b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,12 @@ Classify the change according to the following categories: ##### Removed ### Patches +## v2.10.1 +### Patches +- Make **ERPOutageInputs** field **max_outage_duration** required +- In ERP inputs processing, check that **ElectricUtility** **outage_durations** is not empty before calculating max +- Respond with validation error if **max_outage_duration** not provided and can't be calculated + ## v2.10.0 ### Minor Updates ##### Added