|
1 | | -from enum import Enum |
2 | | -from typing import Optional, Dict |
3 | | - |
4 | | - |
5 | | -class AnalyserResultCodeType(Enum): |
6 | | - """ |
7 | | - Enum for analyser result code types, mapped to valid value IDs and descriptions. |
8 | | - """ |
9 | | - |
10 | | - ABOVE_DILUTION_RANGE = (309030, "Above dilution range") |
11 | | - BELOW_MEASURING_RANGE = (309028, "Below measuring range") |
12 | | - SPOILT = (309026, "Spoilt") |
13 | | - TECHNICAL_FAIL = (309027, "Technical Fail") |
14 | | - |
15 | | - def __init__(self, valid_value_id: int, description: str) -> None: |
16 | | - self._valid_value_id = valid_value_id |
17 | | - self._description = description |
18 | | - |
19 | | - @property |
20 | | - def valid_value_id(self) -> int: |
21 | | - """ |
22 | | - Returns the valid value ID for the analyser result code type. |
23 | | - """ |
24 | | - return self._valid_value_id |
25 | | - |
26 | | - @property |
27 | | - def description(self) -> str: |
28 | | - """ |
29 | | - Returns the description for the analyser result code type. |
30 | | - """ |
31 | | - return self._description |
32 | | - |
33 | | - @classmethod |
34 | | - def by_description(cls, description: str) -> Optional["AnalyserResultCodeType"]: |
35 | | - """ |
36 | | - Returns the enum member matching the given description (case-sensitive). |
37 | | - """ |
38 | | - for member in cls: |
39 | | - if member.description == description: |
40 | | - return member |
41 | | - return None |
42 | | - |
43 | | - @classmethod |
44 | | - def by_description_case_insensitive( |
45 | | - cls, description: str |
46 | | - ) -> Optional["AnalyserResultCodeType"]: |
47 | | - """ |
48 | | - Returns the enum member matching the given description (case-insensitive). |
49 | | - """ |
50 | | - desc_lower = description.lower() |
51 | | - for member in cls: |
52 | | - if member.description.lower() == desc_lower: |
53 | | - return member |
54 | | - return None |
55 | | - |
56 | | - @classmethod |
57 | | - def by_valid_value_id( |
58 | | - cls, valid_value_id: int |
59 | | - ) -> Optional["AnalyserResultCodeType"]: |
60 | | - """ |
61 | | - Returns the enum member matching the given valid value ID. |
62 | | - """ |
63 | | - for member in cls: |
64 | | - if member.valid_value_id == valid_value_id: |
65 | | - return member |
66 | | - return None |
| 1 | +from enum import Enum |
| 2 | +from typing import Optional, Dict |
| 3 | + |
| 4 | + |
| 5 | +class AnalyserResultCodeType(Enum): |
| 6 | + """ |
| 7 | + Enum for analyser result code types, mapped to valid value IDs and descriptions. |
| 8 | + """ |
| 9 | + |
| 10 | + ABOVE_DILUTION_RANGE = (309030, "Above dilution range") |
| 11 | + BELOW_MEASURING_RANGE = (309028, "Below measuring range") |
| 12 | + SPOILT = (309026, "Spoilt") |
| 13 | + TECHNICAL_FAIL = (309027, "Technical Fail") |
| 14 | + |
| 15 | + def __init__(self, valid_value_id: int, description: str) -> None: |
| 16 | + self._valid_value_id = valid_value_id |
| 17 | + self._description = description |
| 18 | + |
| 19 | + @property |
| 20 | + def valid_value_id(self) -> int: |
| 21 | + """ |
| 22 | + Returns the valid value ID for the analyser result code type. |
| 23 | + """ |
| 24 | + return self._valid_value_id |
| 25 | + |
| 26 | + @property |
| 27 | + def description(self) -> str: |
| 28 | + """ |
| 29 | + Returns the description for the analyser result code type. |
| 30 | + """ |
| 31 | + return self._description |
| 32 | + |
| 33 | + @classmethod |
| 34 | + def by_description(cls, description: str) -> Optional["AnalyserResultCodeType"]: |
| 35 | + """ |
| 36 | + Returns the enum member matching the given description (case-sensitive). |
| 37 | + """ |
| 38 | + for member in cls: |
| 39 | + if member.description == description: |
| 40 | + return member |
| 41 | + return None |
| 42 | + |
| 43 | + @classmethod |
| 44 | + def by_description_case_insensitive( |
| 45 | + cls, description: str |
| 46 | + ) -> Optional["AnalyserResultCodeType"]: |
| 47 | + """ |
| 48 | + Returns the enum member matching the given description (case-insensitive). |
| 49 | + """ |
| 50 | + desc_lower = description.lower() |
| 51 | + for member in cls: |
| 52 | + if member.description.lower() == desc_lower: |
| 53 | + return member |
| 54 | + return None |
| 55 | + |
| 56 | + @classmethod |
| 57 | + def by_valid_value_id( |
| 58 | + cls, valid_value_id: int |
| 59 | + ) -> Optional["AnalyserResultCodeType"]: |
| 60 | + """ |
| 61 | + Returns the enum member matching the given valid value ID. |
| 62 | + """ |
| 63 | + for member in cls: |
| 64 | + if member.valid_value_id == valid_value_id: |
| 65 | + return member |
| 66 | + return None |
0 commit comments