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 diff --git a/resilience_stats/api.py b/resilience_stats/api.py index 3fc8b9aba..97ae92f7c 100644 --- a/resilience_stats/api.py +++ b/resilience_stats/api.py @@ -166,9 +166,15 @@ 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"]) + }) + 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: 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)]), + ), + ] 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),