generated from dataforgoodfr/d4g-project-template
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: change alerts to status messages and split impacts and output
- Loading branch information
1 parent
0bb7acf
commit 59452e2
Showing
15 changed files
with
156 additions
and
130 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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from pydantic import BaseModel | ||
|
||
STATUS_DOCS_URL = "https://ecologits/tutorial/warnings_and_errors/#{code}" | ||
|
||
|
||
class _StatusMessage(BaseModel): | ||
""" | ||
Base status message used for warnings or errors. | ||
Attributes: | ||
code: Status code. | ||
message: Message explaining the issue. | ||
""" | ||
code: str | ||
message: str | ||
|
||
def __str__(self) -> str: | ||
return f"{self.message}\n\nFor further information visit {STATUS_DOCS_URL.format(code=self.code)}" | ||
|
||
@classmethod | ||
def from_code(cls, code: str) -> type["_StatusMessage"]: | ||
raise NotImplementedError("Should be called from WarningMessage or ErrorMessage.") | ||
|
||
|
||
class WarningMessage(_StatusMessage): | ||
|
||
@classmethod | ||
def from_code(cls, code: str) -> "WarningMessage": | ||
if code in _warning_codes: | ||
return _warning_codes[code]() | ||
else: | ||
raise ValueError(f"Warning code `{code}` does not exist.") | ||
|
||
|
||
class ErrorMessage(_StatusMessage): | ||
|
||
@classmethod | ||
def from_code(cls, code: str) -> "ErrorMessage": | ||
if code in _error_codes: | ||
return _error_codes[code]() | ||
else: | ||
raise ValueError(f"Error code `{code}` does not exist.") | ||
|
||
|
||
class ModelArchNotReleasedWarning(WarningMessage): | ||
code: str = "model-arch-not-released" | ||
message: str = "The model architecture has not been released, expect lower precision." | ||
|
||
|
||
class ModelArchMultimodalWarning(WarningMessage): | ||
code: str = "model-arch-multimodal" | ||
message: str = "The model architecture is multimodal, expect lower precision." | ||
|
||
|
||
class ModelNotRegisteredError(ErrorMessage): | ||
code: str = "model-not-registered" | ||
message: str = "The model is not registered in the model repository." | ||
|
||
|
||
class ZoneNotRegisteredError(ErrorMessage): | ||
code: str = "zone-not-registered" | ||
message: str = "The zone is not registered." | ||
|
||
|
||
_warning_codes: dict[str, type[WarningMessage]] = { | ||
"model-arch-not-released": ModelArchNotReleasedWarning, | ||
"model-arch-multimodal": ModelArchMultimodalWarning | ||
} | ||
|
||
_error_codes: dict[str, type[ErrorMessage]] = { | ||
"model-not-registered": ModelNotRegisteredError, | ||
"zone-not-registered": ZoneNotRegisteredError | ||
} |
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
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
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
Oops, something went wrong.