Verified Commit 8ebed322 authored by Sebastian Endres's avatar Sebastian Endres
Browse files

Adapt result parser for modified result.json format

parent 63c17f65
......@@ -15,13 +15,22 @@ from typing import Literal, Optional, TypedDict, Union, cast
DETAILS_RE = re.compile(r"(?P<avg>\d+) \(± (?P<var>\d+)\) (?P<unit>\w+)")
class RawTest(TypedDict):
class RawTestDescr(TypedDict):
"""A test description as parsed from result.json."""
name: str
desc: str
class RawMeasurementDescr(TypedDict):
"""A measurement description as parsed from result.json."""
name: str
desc: str
theoretical_max_value: Optional[float]
repetitions: Optional[int]
RawTestResultResult = Union[
None, Literal["succeeded"], Literal["failed"], Literal["unsupported"]
]
......@@ -30,8 +39,6 @@ RawTestResultResult = Union[
class RawTestResult(TypedDict):
"""A test result as parsed from result.json."""
#: deprecated
name: str
abbr: str
result: RawTestResultResult
......@@ -39,8 +46,6 @@ class RawTestResult(TypedDict):
class RawMeasurement(TypedDict):
"""A measurement result as parsed from result.json."""
#: deprecated
name: str
abbr: str
result: RawTestResultResult
details: str
......@@ -55,7 +60,7 @@ class RawResult(TypedDict):
servers: list[str]
clients: list[str]
urls: dict[str, str]
tests: dict[str, RawTest]
tests: dict[str, Union[RawTestDescr, RawMeasurementDescr]]
quic_draft: int
quic_version: str
results: list[list[RawTestResult]]
......@@ -87,10 +92,31 @@ class TestDescription:
name: str
desc: str
def to_raw(self) -> RawTest:
def to_raw(self) -> RawTestDescr:
"""Convert to a raw test description."""
return RawTestDescr(
name=self.name,
desc=self.desc,
)
@dataclass(frozen=True)
class MeasurmentDescription(TestDescription):
"""The description of a measurement."""
theoretical_max_value: Optional[float]
repetitions: Optional[int]
def to_raw(self) -> RawMeasurementDescr:
"""Convert to a raw test description."""
return {"name": self.name, "desc": self.desc}
return RawMeasurementDescr(
name=self.name,
desc=self.desc,
theoretical_max_value=self.theoretical_max_value,
repetitions=self.repetitions,
)
@dataclass(frozen=True) # type: ignore
......@@ -132,7 +158,6 @@ class ExtendedTestResult(_ExtendedTestResultMixin):
"""Return a raw measurement result."""
return RawTestResult(
name=self.test.name,
abbr=self.test.abbr,
result=self.result,
)
......@@ -155,8 +180,11 @@ class ExtendedMeasurementResult(_ExtendedTestResultMixin):
)
repetition_nums = [int(iterdir.name) for iterdir in repetitions]
except FileNotFoundError as err:
breakpoint()
raise err
if self.result == "success":
breakpoint()
raise err
else:
return []
for index, cur_num in enumerate(repetition_nums):
if index + 1 != cur_num:
......@@ -206,7 +234,6 @@ class ExtendedMeasurementResult(_ExtendedTestResultMixin):
"""Return a raw measurement result."""
return RawMeasurement(
name=self.test.name,
abbr=self.test.abbr,
result=self.result,
details=self.details,
......@@ -399,15 +426,28 @@ class Result:
return frozenset(self.servers) | frozenset(self.clients)
@property
def tests(self) -> dict[str, TestDescription]:
def tests(self) -> dict[str, Union[TestDescription, MeasurmentDescription]]:
"""
Return a dict of test and measurement abbr.s and description that ran during this run.
"""
tests = dict[str, Union[TestDescription, MeasurmentDescription]]()
for abbr, test in self.raw_data["tests"].items():
if "theoretical_max_value" in test.keys() or "repetitions" in test.keys():
meas_desc: RawMeasurementDescr = cast(RawMeasurementDescr, test)
tests[abbr] = MeasurmentDescription(
abbr=abbr,
name=test["name"],
desc=test["desc"],
theoretical_max_value=meas_desc.get("theoretical_max_value"),
repetitions=meas_desc.get("repetitions"),
)
else:
tests[abbr] = TestDescription(
abbr=abbr, name=test["name"], desc=test["desc"]
)
return {
abbr: TestDescription(abbr=abbr, name=test["name"], desc=test["desc"])
for abbr, test in self.raw_data["tests"].items()
}
return tests
@property
def test_results(self) -> TestResults:
......@@ -748,7 +788,7 @@ class Result:
**{impl.name: impl.url for impl in self.implementations},
**{impl.name: impl.url for impl in other.implementations},
}
test_descriptions: dict[str, RawTest] = {
test_descriptions: dict[str, Union[RawTestDescr, RawMeasurementDescr]] = {
**{abbr: test.to_raw() for abbr, test in self.tests.items()},
**{abbr: test.to_raw() for abbr, test in other.tests.items()},
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment