Skip to content

Commit

Permalink
add checks for mismatched length and new ASHP validator tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zolanaj committed Sep 25, 2024
1 parent 718fff7 commit b6dee5b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions reoptjl/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5494,6 +5494,12 @@ def clean(self):
if self.dict.get("min_allowable_ton") not in [None, "", []] and self.dict.get("min_allowable_peak_capacity_fraction") not in [None, "", []]:
error_messages["bad inputs"] = "At most one of min_allowable_ton and min_allowable_peak_capacity_fraction may be input to model {}".format(self.key)

if len(self.dict.get("heating_cop_reference")) != len(self.dict.get("heating_cf_reference")) or len(self.dict.get("heating_cop_reference")) != len(self.dict.get("heating_reference_temps_degF")):
error_messages["mismatched length"] = "Model {} inputs heating_cop_reference, heating_cf_reference, and heating_reference_temps_degF must all have the same length.".format(self.key)

if len(self.dict.get("cooling_cop_reference")) != len(self.dict.get("cooling_cf_reference")) or len(self.dict.get("cooling_cop_reference")) != len(self.dict.get("cooling_reference_temps_degF")):
error_messages["mismatched length"] = "Model {} inputs cooling_cop_reference, cooling_cf_reference, and cooling_reference_temps_degF must all have the same length.".format(self.key)

if error_messages:
raise ValidationError(error_messages)

Expand Down Expand Up @@ -5756,6 +5762,9 @@ def clean(self):
if self.dict.get("min_allowable_ton") not in [None, "", []] and self.dict.get("min_allowable_peak_capacity_fraction") not in [None, "", []]:
error_messages["bad inputs"] = "At most one of min_allowable_ton and min_allowable_peak_capacity_fraction may be input to model {}".format(self.key)

if len(self.dict.get("heating_cop_reference")) != len(self.dict.get("heating_cf_reference")) or len(self.dict.get("heating_cop_reference")) != len(self.dict.get("heating_reference_temps_degF")):
error_messages["mismatched length"] = "Model {} inputs heating_cop_reference, heating_cf_reference, and heating_reference_temps_degF must all have the same length.".format(self.key)

if error_messages:
raise ValidationError(error_messages)

Expand Down
27 changes: 27 additions & 0 deletions reoptjl/test/test_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,30 @@ def boiler_validation(self):
# self.assertAlmostEqual(len(validator.models["ExistingBoiler"].fuel_cost_per_mmbtu), 8760)
# self.assertAlmostEqual(sum(validator.models["ExistingBoiler"].fuel_cost_per_mmbtu), 8760*0.5)

def ashp_validation(self):
"""
Ensure that bad inputs are caught by clean() for ASHP systems.
"""
post_file = os.path.join('job', 'test', 'posts', 'all_inputs_test.json')
post = json.load(open(post_file, 'r'))

post["APIMeta"]["run_uuid"] = uuid.uuid4()
post["ASHPSpaceHeater"]["cooling_cf_reference"] = []

validator = InputValidator(post)
validator.clean_fields()
validator.clean()
validator.cross_clean()
assert("mismatched length" in validator.validation_errors["ASHPSpaceHeater"].keys())

post = json.load(open(post_file, 'r'))
post["APIMeta"]["run_uuid"] = uuid.uuid4()
post["ASHPWaterHeater"]["min_allowable_ton"] = 1000
post["ASHPWaterHeater"]["min_allowable_peak_capacity_fraction"] = 0.9

validator = InputValidator(post)
validator.clean_fields()
validator.clean()
validator.cross_clean()
assert("bad inputs" in validator.validation_errors["ASHPWaterHeater"].keys())

0 comments on commit b6dee5b

Please sign in to comment.