Skip to content

Commit 39fedd9

Browse files
committed
test
1 parent f58ab99 commit 39fedd9

File tree

2 files changed

+35
-26
lines changed

2 files changed

+35
-26
lines changed

api/src/feeds/impl/models/latest_dataset_impl.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from shared.database_gen.sqlacodegen_models import Gtfsdataset
44
from feeds.impl.models.bounding_box_impl import BoundingBoxImpl
5+
from feeds.impl.models.validation_report_impl import ValidationReportImpl
56
from feeds_gen.models.latest_dataset import LatestDataset
67
from feeds_gen.models.latest_dataset_validation_report import LatestDatasetValidationReport
78
from utils.model_utils import compare_java_versions
@@ -29,13 +30,21 @@ def from_orm(cls, dataset: Gtfsdataset | None) -> LatestDataset | None:
2930
lambda a, b: a if compare_java_versions(a.validator_version, b.validator_version) == 1 else b,
3031
dataset.validation_reports,
3132
)
33+
(
34+
total_error,
35+
total_info,
36+
total_warning,
37+
unique_error_count,
38+
unique_info_count,
39+
unique_warning_count,
40+
) = ValidationReportImpl.compute_totals(latest_report)
3241
validation_report = LatestDatasetValidationReport(
33-
total_error=latest_report.total_error,
34-
total_warning=latest_report.total_warning,
35-
total_info=latest_report.total_info,
36-
unique_error_count=latest_report.unique_error_count,
37-
unique_warning_count=latest_report.unique_warning_count,
38-
unique_info_count=latest_report.unique_info_count,
42+
total_error=total_error,
43+
total_warning=total_warning,
44+
total_info=total_info,
45+
unique_error_count=unique_error_count,
46+
unique_warning_count=unique_warning_count,
47+
unique_info_count=unique_info_count,
3948
)
4049
return cls(
4150
id=dataset.stable_id,

api/src/feeds/impl/models/validation_report_impl.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,26 @@ class Config:
1616

1717
from_attributes = True
1818

19-
# @staticmethod
20-
# def compute_totals(validation_report) -> tuple[int, int, int, int, int, int]:
21-
# """Compute the total number of errors, info, and warnings from a validation report,
22-
# and count the number of distinct codes for each."""
23-
# total_info, total_warning, total_error = 0, 0, 0
24-
# info_codes, warning_codes, error_codes = set(), set(), set()
25-
# for notice in validation_report.notices:
26-
# match notice.severity:
27-
# case "INFO":
28-
# total_info += notice.total_notices
29-
# info_codes.add(notice.notice_code)
30-
# case "WARNING":
31-
# total_warning += notice.total_notices
32-
# warning_codes.add(notice.notice_code)
33-
# case "ERROR":
34-
# total_error += notice.total_notices
35-
# error_codes.add(notice.notice_code)
36-
# case _:
37-
# ValidationReportImpl._get_logger().warning(f"Unknown severity: {notice.severity}")
38-
# return total_error, total_info, total_warning, len(error_codes), len(info_codes), len(warning_codes)
19+
@staticmethod
20+
def compute_totals(validation_report) -> tuple[int, int, int, int, int, int]:
21+
"""Compute the total number of errors, info, and warnings from a validation report,
22+
and count the number of distinct codes for each."""
23+
total_info, total_warning, total_error = 0, 0, 0
24+
info_codes, warning_codes, error_codes = set(), set(), set()
25+
for notice in validation_report.notices:
26+
match notice.severity:
27+
case "INFO":
28+
total_info += notice.total_notices
29+
info_codes.add(notice.notice_code)
30+
case "WARNING":
31+
total_warning += notice.total_notices
32+
warning_codes.add(notice.notice_code)
33+
case "ERROR":
34+
total_error += notice.total_notices
35+
error_codes.add(notice.notice_code)
36+
case _:
37+
ValidationReportImpl._get_logger().warning(f"Unknown severity: {notice.severity}")
38+
return total_error, total_info, total_warning, len(error_codes), len(info_codes), len(warning_codes)
3939

4040
@classmethod
4141
def _get_logger(cls):

0 commit comments

Comments
 (0)