-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactorings, bugfixes and parse improvements
- Loading branch information
Showing
20 changed files
with
550 additions
and
242 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,106 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
@project: HsPyLib-AskAI | ||
@package: askai.core.enums.acc_response | ||
@file: acc_color.py | ||
@created: thu, 26 Sep 2024 | ||
@author: <B>H</B>ugo <B>S</B>aporetti <B>J</B>unior | ||
@site: https://github.com/yorevs/askai | ||
@license: MIT - Please refer to <https://opensource.org/licenses/MIT> | ||
Copyright (c) 2024, HomeSetup | ||
""" | ||
from typing import Literal, TypeAlias | ||
|
||
from hspylib.core.enums.enumeration import Enumeration | ||
|
||
AccuracyColors: TypeAlias = Literal["Blue", "Green", "Yellow", "Orange", "Red"] | ||
|
||
|
||
class AccColor(Enumeration): | ||
"""TODO""" | ||
|
||
# fmt: off | ||
|
||
INTERRUPT = 'Black', -1 | ||
|
||
EXCELLENT = 'Blue', 0 | ||
|
||
GOOD = 'Green', 1 | ||
|
||
MODERATE = 'Yellow', 2 | ||
|
||
INCOMPLETE = 'Orange', 3 | ||
|
||
BAD = 'Red', 4 | ||
|
||
def __init__(self, color: AccuracyColors, weight: int): | ||
self._color: AccuracyColors = color | ||
self._weight: int = weight | ||
|
||
def __eq__(self, other: "AccColor") -> bool: | ||
return self.val == other.val | ||
|
||
def __lt__(self, other) -> bool: | ||
return self.val < other.val | ||
|
||
def __le__(self, other) -> bool: | ||
return self.val <= other.val | ||
|
||
def __gt__(self, other) -> bool: | ||
return self.val > other.val | ||
|
||
def __ge__(self, other) -> bool: | ||
return self.val >= other.val | ||
|
||
def __str__(self) -> str: | ||
return self.color | ||
|
||
@classmethod | ||
def of_color(cls, color_str: AccuracyColors) -> 'AccColor': | ||
"""Create an AccResponse instance based on status and optional reasoning. | ||
:param color_str: The color as a string. | ||
:return: An instance of AccColor with the given color. | ||
""" | ||
acc_color: tuple[str, int] = next((c for c in cls.values() if c[0] == color_str.title()), None) | ||
if acc_color and isinstance(acc_color, tuple): | ||
return cls.of_value(acc_color) | ||
raise ValueError(f"'{color_str}'is not a valid AccColor") | ||
|
||
@property | ||
def color(self) -> AccuracyColors: | ||
return self.value[0] | ||
|
||
@property | ||
def val(self) -> int: | ||
"""Gets the integer value of the verbosity level. | ||
:return: The integer representation of the verbosity level. | ||
""" | ||
return int(self.value[1]) | ||
|
||
@property | ||
def is_bad(self) -> bool: | ||
return self in [self.BAD, self.INCOMPLETE] | ||
|
||
@property | ||
def is_moderate(self) -> bool: | ||
return self == self.MODERATE | ||
|
||
@property | ||
def is_good(self) -> bool: | ||
return self in [self.GOOD, self.EXCELLENT] | ||
|
||
@property | ||
def is_interrupt(self) -> bool: | ||
return self == self.INTERRUPT | ||
|
||
def passed(self, threshold: "AccColor") -> bool: | ||
"""Determine whether the response matches a 'PASS' classification. | ||
:param threshold: The threshold or criteria used to determine a 'PASS' classification. | ||
:return: True if the response meets or exceeds the 'PASS' threshold, otherwise False. | ||
""" | ||
if isinstance(threshold, AccColor): | ||
return self.val <= threshold.val | ||
return False |
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.