-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_structures.py
More file actions
118 lines (89 loc) · 2.84 KB
/
Copy pathdata_structures.py
File metadata and controls
118 lines (89 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
from dataclasses import dataclass
from enum import Enum
from typing import Iterator, Optional
class State(float, Enum):
"""Enum representation of the possible states of a refrigerator machine."""
NORMAL = 0
AGGREGATE_FAN_FAULT = 1
EVAPORATOR_FAN_FAULT = 2
COMPRESSOR_FAULT = 3
DEFROSTING = 6
@dataclass(frozen=True)
class Channel:
"""Helper channel representation class."""
name: str
code_name: str
def __repr__(self) -> str:
return self.code_name
@dataclass(frozen=True)
class DetectionRange:
"""Helper object which represents a detection range for RS classifiers."""
minimum: float
maximum: float
state: State
required_state: Optional[State] = None
def __repr__(self) -> str:
"""Debug representation of the object.
Returns:
str: String representation of the object
"""
return (
"DetectionRange("
f"state={self.state}, "
f"minimum={self.minimum}, "
f"maximum={self.maximum}, "
f"required_state={self.required_state}"
")"
)
def in_range(self, value: float) -> bool:
"""Check if given value is in the defined object's range."""
return self.minimum < value <= self.maximum
@dataclass(frozen=True)
class DetectionSet:
"""RS detection set representation helper class."""
channel: Channel
ranges: list[DetectionRange]
@dataclass(frozen=True)
class DetectionSets:
"""RS detection sets representation helper class."""
set_1: DetectionSet
set_2: Optional[DetectionSet] = None
set_3: Optional[DetectionSet] = None
set_4: Optional[DetectionSet] = None
set_5: Optional[DetectionSet] = None
@property
def _all_sets(self) -> list[DetectionSet]:
"""Property which allows to iterate over the detection sets.
Returns:
list[DetectionSet]: List of detection sets
"""
return [
_set
for _set in [
self.set_1,
self.set_2,
self.set_3,
self.set_4,
self.set_5,
]
if _set is not None
]
@property
def sets(self) -> Iterator[DetectionSet]:
"""Property which allows to iterate over the detection sets.
Returns:
Iterator[DetectionSet]: Iterator over detection sets
"""
return iter([detection_set for detection_set in self._all_sets])
@property
def channels(self) -> Iterator[str]:
"""Property which allows to iterate over channels used in sets.
Returns:
Iterator[str]: Iterator over channels used in sets
"""
return iter(
[
detection_set.channel.code_name
for detection_set in self._all_sets
]
)