-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENG-1675] Add validation to check residual_capacity < capacity_gross…
…_max (#144) * Add validation to check residual_capacity < capacity_gross_max * Move technology validation to model class so it's done post-composition
- Loading branch information
Showing
4 changed files
with
121 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 60 additions & 60 deletions
120
tz/osemosys/schemas/validation/technology_validation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,69 @@ | ||
from tz.osemosys.schemas.validation.validation_utils import check_min_vals_lower_max | ||
|
||
|
||
def min_activity_lower_than_max(values): | ||
""" | ||
Check minimum activity constraints are lower than maximum activity constraints | ||
""" | ||
id = values.get("id") | ||
activity_annual_max = values.get("activity_annual_max") | ||
activity_annual_min = values.get("activity_annual_min") | ||
activity_total_max = values.get("activity_total_max") | ||
activity_total_min = values.get("activity_total_min") | ||
def validate_min_lt_max(technologies): | ||
|
||
if activity_annual_min is not None and activity_annual_max is not None: | ||
check_min_vals_lower_max( | ||
activity_annual_min, | ||
activity_annual_max, | ||
["REGION", "YEAR", "VALUE"], | ||
( | ||
f"Technology {id} values in activity_annual_min should be lower than " | ||
"or equal to the corresponding values in activity_annual_max" | ||
), | ||
) | ||
if activity_total_min is not None and activity_total_max is not None: | ||
check_min_vals_lower_max( | ||
activity_total_min, | ||
activity_total_max, | ||
["REGION", "VALUE"], | ||
( | ||
f"Technology {id} values in activity_total_min should be lower than " | ||
"or equal to the corresponding values in activity_total_max" | ||
), | ||
) | ||
for technology in technologies: | ||
|
||
return values | ||
if technology.capacity_gross_min is not None and technology.capacity_gross_max is not None: | ||
if not check_min_vals_lower_max( | ||
technology.capacity_gross_min, | ||
technology.capacity_gross_max, | ||
["REGION", "YEAR", "VALUE"], | ||
): | ||
raise ValueError( | ||
f"Minimum gross capacity (capacity_gross_min) is not less than maximum gross " | ||
f"capacity (capacity_gross_max) for technology '{technology.id}'." | ||
) | ||
|
||
if ( | ||
technology.capacity_additional_min is not None | ||
and technology.capacity_additional_max is not None | ||
): | ||
if not check_min_vals_lower_max( | ||
technology.capacity_additional_min, | ||
technology.capacity_additional_max, | ||
["REGION", "YEAR", "VALUE"], | ||
): | ||
raise ValueError( | ||
f"Minimum additional capacity (capacity_additional_min) is not less than " | ||
f"maximum additional capacity (capacity_additional_max) for technology " | ||
f"'{technology.id}'." | ||
) | ||
|
||
def min_capacity_lower_than_max(values): | ||
""" | ||
Check minimum capacity constraints are lower than maximum capacity constraints | ||
""" | ||
id = values.get("id") | ||
capacity_gross_max = values.get("capacity_gross_max") | ||
capacity_gross_min = values.get("capacity_gross_min") | ||
capacity_additional_max = values.get("capacity_additional_max") | ||
capacity_additional_min = values.get("capacity_additional_min") | ||
if ( | ||
technology.activity_annual_min is not None | ||
and technology.activity_annual_max is not None | ||
): | ||
if not check_min_vals_lower_max( | ||
technology.activity_annual_min, | ||
technology.activity_annual_max, | ||
["REGION", "YEAR", "VALUE"], | ||
): | ||
raise ValueError( | ||
f"Minimum annual activity (activity_annual_min) is not less than maximum annual" | ||
f" activity (activity_annual_max) for technology '{technology.id}'." | ||
) | ||
|
||
if capacity_additional_min is not None and capacity_additional_max is not None: | ||
check_min_vals_lower_max( | ||
capacity_additional_min, | ||
capacity_additional_max, | ||
["REGION", "YEAR", "VALUE"], | ||
( | ||
f"Technology {id} values in capacity_additional_min should be lower than " | ||
"or equal to the corresponding values in capacity_additional_max" | ||
), | ||
) | ||
if capacity_gross_min is not None and capacity_gross_max is not None: | ||
check_min_vals_lower_max( | ||
capacity_gross_min, | ||
capacity_gross_max, | ||
["REGION", "YEAR", "VALUE"], | ||
( | ||
f"Technology {id} values in capacity_gross_min should be lower than " | ||
"or equal to the corresponding values in capacity_gross_max" | ||
), | ||
) | ||
if technology.activity_total_min is not None and technology.activity_total_max is not None: | ||
if not check_min_vals_lower_max( | ||
technology.activity_total_min, | ||
technology.activity_total_max, | ||
["REGION", "VALUE"], | ||
): | ||
raise ValueError( | ||
f"Minimum total activity (activity_total_min) is not less than maximum total " | ||
f"activity (activity_total_max) for technology '{technology.id}'." | ||
) | ||
|
||
return values | ||
if technology.residual_capacity is not None and technology.capacity_gross_max is not None: | ||
|
||
if not check_min_vals_lower_max( | ||
technology.residual_capacity, | ||
technology.capacity_gross_max, | ||
["REGION", "YEAR", "VALUE"], | ||
): | ||
raise ValueError( | ||
f"Residual capacity is greater than the allowed total installed capacity " | ||
f"defined in capacity_gross_max for technology '{technology.id}'." | ||
) |