-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: improve error message for extra pfs columns (#541)
* chore: improve error message for extra pfs columns ECALC-1342
- Loading branch information
Showing
4 changed files
with
69 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from datetime import datetime | ||
from typing import Union | ||
|
||
from libecalc.dto.base import ConsumerUserDefinedCategoryType | ||
from libecalc.dto.utils.validators import ExpressionType | ||
|
||
|
||
def validate_generator_set_power_from_shore( | ||
cable_loss: ExpressionType, | ||
max_usage_from_shore: ExpressionType, | ||
model_fields: dict, | ||
category: Union[dict, ConsumerUserDefinedCategoryType], | ||
): | ||
if cable_loss is not None or max_usage_from_shore is not None: | ||
feedback_text = ( | ||
f"{model_fields['cable_loss'].title} and " f"{model_fields['max_usage_from_shore'].title} are only valid" | ||
) | ||
if cable_loss is None: | ||
feedback_text = f"{model_fields['max_usage_from_shore'].title} is only valid" | ||
if max_usage_from_shore is None: | ||
feedback_text = f"{model_fields['cable_loss'].title} is only valid" | ||
|
||
if isinstance(category, ConsumerUserDefinedCategoryType): | ||
if category is not ConsumerUserDefinedCategoryType.POWER_FROM_SHORE: | ||
message = f"{feedback_text} for the category {ConsumerUserDefinedCategoryType.POWER_FROM_SHORE.value}, not for {category}." | ||
raise ValueError(message) | ||
else: | ||
if ConsumerUserDefinedCategoryType.POWER_FROM_SHORE not in category.values(): | ||
message = ( | ||
f"{feedback_text} for the category {ConsumerUserDefinedCategoryType.POWER_FROM_SHORE.value}" | ||
f", not for {category[datetime(1900, 1, 1)].value}." | ||
) | ||
raise ValueError(message) |
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