summaryrefslogtreecommitdiff
path: root/buildscripts/util/cedar_report.py
blob: ccdd26a687ab7567659e756199230c0cf2496319 (plain)
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
"""Cedar report."""
from dataclasses import dataclass
from typing import Union, List


@dataclass
class CedarMetric:
    """Structure that holds metrics for Cedar."""

    name: str
    type: str
    value: Union[int, float]
    user_submitted: bool = False

    def as_dict(self) -> dict:
        """Return dictionary representation."""
        return {
            "name": self.name,
            "type": self.type,
            "value": self.value,
            "user_submitted": self.user_submitted,
        }


@dataclass
class CedarTestReport:
    """Structure that holds test report for Cedar."""

    test_name: str
    thread_level: int
    metrics: List[CedarMetric]

    def as_dict(self) -> dict:
        """Return dictionary representation."""
        return {
            "info": {"test_name": self.test_name, "args": {"thread_level": self.thread_level, }},
            "metrics": [metric.as_dict() for metric in self.metrics],
        }