-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.py
More file actions
66 lines (49 loc) · 1.61 KB
/
Copy pathcommon.py
File metadata and controls
66 lines (49 loc) · 1.61 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
from enum import Enum
class Phase(Enum):
"""Represents a phase"""
Unknown = 0
P1 = 1
P2 = 2
P3 = 3
class Currents:
"""Represents the currents on each phase"""
def __init__(self, p1: float, p2: float, p3: float):
self._currents = {
Phase.P1: p1,
Phase.P2: p2,
Phase.P3: p3
}
@property
def p1(self):
"""Phase 1 current"""
return self._currents[Phase.P1]
@property
def p2(self):
"""Phase 2 current"""
return self._currents[Phase.P2]
@property
def p3(self):
"""Phase 3 current"""
return self._currents[Phase.P3]
def min(self):
"""Returns the minimum current"""
return min(self._currents.values())
def max(self):
"""Returns the maximum current"""
return max(self._currents.values())
def min_phase(self) -> Phase:
"""Returns the phase with the minimum current"""
return min(self._currents, key=self._currents.get)
def max_phase(self) -> Phase:
"""Returns the phase with the maximum current"""
return max(self._currents, key=self._currents.get)
def __getitem__(self, item: Phase):
return self._currents[item]
def __setitem__(self, key: Phase, value: float):
self._currents[key] = value
def __eq__(self, other):
return self.p1 == other.p1 and self.p2 == other.p2 and self.p3 == other.p3
def __str__(self):
return f"P1: {self.p1} A, P2: {self.p2} A, P3: {self.p3} A"
def __repr__(self):
return f"Currents(p1={self.p1}, p2={self.p2}, p3={self.p3})"