add Report.concat(*reports)

This commit is contained in:
Jörn-Michael Miehe 2023-08-31 22:10:33 +00:00
parent ecffaa3d07
commit db96082a31
3 changed files with 28 additions and 13 deletions

View file

@ -1,19 +1,12 @@
from . import metrics
from .settings import SETTINGS
def main() -> None:
# env parameters
print(SETTINGS.model_dump())
# CPU metric
print(metrics.cpu())
# MEM metric
print(metrics.memory())
# DISK metric
print(metrics.disk())
print(metrics.Report.concat(
metrics.cpu(),
metrics.memory(),
metrics.disk(),
))
if __name__ == "__main__":

View file

@ -1,8 +1,11 @@
from ._report import Report
from .cpu import cpu
from .disk import disk
from .memory import memory
__all__ = [
"Report",
"cpu",
"disk",
"memory",

View file

@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import Callable, Iterator, Self
from typing import Any, Callable, Iterator, Self
from ..settings import MetricSettings
@ -34,6 +34,25 @@ class Report:
result: str
failed: bool = False
@classmethod
def concat(cls, *_reports: Any) -> Self:
reports = [
report
for report in _reports
if isinstance(report, Report)
]
return cls(
result=", ".join(
report.result
for report in reports
),
failed=any(
report.failed
for report in reports
),
)
@classmethod
def aggregate(
cls, *,