forked from frequenz-floss/frequenz-client-common-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_bounds.py
More file actions
45 lines (32 loc) · 1.09 KB
/
_bounds.py
File metadata and controls
45 lines (32 loc) · 1.09 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
# License: MIT
# Copyright © 2024 Frequenz Energy-as-a-Service GmbH
"""Definitions for bounds."""
import dataclasses
@dataclasses.dataclass(frozen=True, kw_only=True)
class Bounds:
"""A set of lower and upper bounds for any metric.
The lower bound must be less than or equal to the upper bound.
The units of the bounds are always the same as the related metric.
"""
lower: float | None = None
"""The lower bound.
If `None`, there is no lower bound.
"""
upper: float | None = None
"""The upper bound.
If `None`, there is no upper bound.
"""
def __post_init__(self) -> None:
"""Validate these bounds."""
if self.lower is None:
return
if self.upper is None:
return
if self.lower > self.upper:
raise ValueError(
f"Lower bound ({self.lower}) must be less than or equal to upper "
f"bound ({self.upper})"
)
def __str__(self) -> str:
"""Return a string representation of these bounds."""
return f"[{self.lower}, {self.upper}]"