GeneralManager 0.4.3__py3-none-any.whl → 0.4.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- general_manager/measurement/measurement.py +49 -2
- {generalmanager-0.4.3.dist-info → generalmanager-0.4.5.dist-info}/METADATA +1 -1
- {generalmanager-0.4.3.dist-info → generalmanager-0.4.5.dist-info}/RECORD +6 -6
- {generalmanager-0.4.3.dist-info → generalmanager-0.4.5.dist-info}/WHEEL +0 -0
- {generalmanager-0.4.3.dist-info → generalmanager-0.4.5.dist-info}/licenses/LICENSE +0 -0
- {generalmanager-0.4.3.dist-info → generalmanager-0.4.5.dist-info}/top_level.txt +0 -0
@@ -56,7 +56,22 @@ class Measurement:
|
|
56
56
|
|
57
57
|
@classmethod
|
58
58
|
def from_string(cls, value: str) -> Measurement:
|
59
|
-
|
59
|
+
"""
|
60
|
+
Creates a Measurement instance from a string in the format 'value unit'.
|
61
|
+
|
62
|
+
Args:
|
63
|
+
value: A string containing a numeric value and a unit separated by a space (e.g., '10.5 kg').
|
64
|
+
|
65
|
+
Returns:
|
66
|
+
A Measurement instance representing the parsed value and unit.
|
67
|
+
|
68
|
+
Raises:
|
69
|
+
ValueError: If the input string does not contain exactly two parts separated by a space.
|
70
|
+
"""
|
71
|
+
splitted = value.split(" ")
|
72
|
+
if len(splitted) != 2:
|
73
|
+
raise ValueError("String must be in the format 'value unit'.")
|
74
|
+
value, unit = splitted
|
60
75
|
return cls(value, unit)
|
61
76
|
|
62
77
|
@staticmethod
|
@@ -202,12 +217,31 @@ class Measurement:
|
|
202
217
|
return f"Measurement({self.quantity.magnitude}, '{self.quantity.units}')"
|
203
218
|
|
204
219
|
def _compare(self, other: Any, operation: Callable[..., bool]) -> bool:
|
220
|
+
"""
|
221
|
+
Compares this Measurement with another using the specified comparison operation.
|
222
|
+
|
223
|
+
If `other` is a string, it is parsed into a Measurement. Raises a TypeError if
|
224
|
+
`other` is not a Measurement instance. Converts `other` to this instance's unit
|
225
|
+
before applying the comparison. Raises a ValueError if the measurements have
|
226
|
+
incompatible dimensions.
|
227
|
+
|
228
|
+
Args:
|
229
|
+
other: The object to compare with, either a Measurement or a string in the format "value unit".
|
230
|
+
operation: A callable that takes two magnitudes and returns a boolean result.
|
231
|
+
|
232
|
+
Returns:
|
233
|
+
The result of the comparison operation.
|
234
|
+
|
235
|
+
Raises:
|
236
|
+
TypeError: If `other` is not a Measurement instance or a valid string representation.
|
237
|
+
ValueError: If the measurements have different dimensions and cannot be compared.
|
238
|
+
"""
|
205
239
|
if isinstance(other, str):
|
206
240
|
other = Measurement.from_string(other)
|
207
241
|
|
208
242
|
# Überprüfen, ob `other` ein Measurement-Objekt ist
|
209
243
|
if not isinstance(other, Measurement):
|
210
|
-
|
244
|
+
raise TypeError("Comparison is only allowed between Measurement instances.")
|
211
245
|
try:
|
212
246
|
# Convert `other` to the same units as `self`
|
213
247
|
other_converted: pint.Quantity = other.quantity.to(self.quantity.units) # type: ignore
|
@@ -238,4 +272,17 @@ class Measurement:
|
|
238
272
|
return self._compare(other, gt)
|
239
273
|
|
240
274
|
def __ge__(self, other: Any) -> bool:
|
275
|
+
"""
|
276
|
+
Returns True if this measurement is greater than or equal to another measurement.
|
277
|
+
|
278
|
+
Comparison is performed after converting the other operand to the same unit. Raises a TypeError if the other object is not a Measurement instance or a compatible string, or a ValueError if the units are not compatible.
|
279
|
+
"""
|
241
280
|
return self._compare(other, ge)
|
281
|
+
|
282
|
+
def __hash__(self) -> int:
|
283
|
+
"""
|
284
|
+
Returns a hash value based on the magnitude and unit of the measurement.
|
285
|
+
|
286
|
+
This enables Measurement instances to be used in hash-based collections such as sets and dictionaries.
|
287
|
+
"""
|
288
|
+
return hash((self.quantity.magnitude, str(self.quantity.units)))
|
@@ -28,7 +28,7 @@ general_manager/manager/groupManager.py,sha256=O4FABqbm7KlZw6t36Ot3HU1FsBYN0h6Zh
|
|
28
28
|
general_manager/manager/input.py,sha256=iKawV3P1QICz-0AQUF00OvH7LZYxussg3svpvCUl8hE,2977
|
29
29
|
general_manager/manager/meta.py,sha256=5wHrCVnua5c38vpVZSCesrNvgydQDH8h6pxW6_QgCDg,3107
|
30
30
|
general_manager/measurement/__init__.py,sha256=X97meFujBldE5v0WMF7SmKeGpC5R0JTczfLo_Lq1Xek,84
|
31
|
-
general_manager/measurement/measurement.py,sha256=
|
31
|
+
general_manager/measurement/measurement.py,sha256=e_FjHieeJbBtjXGCO9J7vRPw6KCkMrOxwWjaD0m8ee4,11777
|
32
32
|
general_manager/measurement/measurementField.py,sha256=iq9Hqe6ZGX8CxXm4nIqTAWTRkQVptzpqE9ExX-jFyNs,5928
|
33
33
|
general_manager/permission/__init__.py,sha256=5UlDERN60Vn8obGVkT-cOM8kHjzmoxgK5w5FgTCDhGE,59
|
34
34
|
general_manager/permission/basePermission.py,sha256=PsJiX-UNeSh6xUlcUwuQNCLYvHZipWUJ0kAoMkdxXJc,6113
|
@@ -39,8 +39,8 @@ general_manager/permission/permissionDataManager.py,sha256=Ji7fsnuaKTa6M8yzCGyzr
|
|
39
39
|
general_manager/rule/__init__.py,sha256=4Har5cfPD1fmOsilTDod-ZUz3Com-tkl58jz7yY4fD0,23
|
40
40
|
general_manager/rule/handler.py,sha256=z8SFHTIZ0LbLh3fV56Mud0V4_OvWkqJjlHvFqau7Qfk,7334
|
41
41
|
general_manager/rule/rule.py,sha256=3FVCKGL7BTVoStdgOTdWQwuoVRIxAIAilV4VOzouDpc,10759
|
42
|
-
generalmanager-0.4.
|
43
|
-
generalmanager-0.4.
|
44
|
-
generalmanager-0.4.
|
45
|
-
generalmanager-0.4.
|
46
|
-
generalmanager-0.4.
|
42
|
+
generalmanager-0.4.5.dist-info/licenses/LICENSE,sha256=YGFm0ieb4KpkMRRt2qnWue6uFh0cUMtobwEBkHwajhc,1450
|
43
|
+
generalmanager-0.4.5.dist-info/METADATA,sha256=XtO9PCJmtFWR-pPXbRZ_EaV4b0SwgbVSWsHhusr9FKQ,6528
|
44
|
+
generalmanager-0.4.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
45
|
+
generalmanager-0.4.5.dist-info/top_level.txt,sha256=sTDtExP9ga-YP3h3h42yivUY-A2Q23C2nw6LNKOho4I,16
|
46
|
+
generalmanager-0.4.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|