Skip to content

Commit 48c1ca0

Browse files
authored
Merge pull request #1130 from cmu-delphi/validator-summary-alert
Modify summary for alerts
2 parents 9eb588b + 07f606d commit 48c1ca0

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

_delphi_utils_python/delphi_utils/validator/report.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@
77
class ValidationReport:
88
"""Class for reporting the results of validation."""
99

10-
def __init__(self, errors_to_suppress: List[ValidationFailure]):
10+
def __init__(self, errors_to_suppress: List[ValidationFailure], data_source: str = ""):
1111
"""Initialize a ValidationReport.
1212
1313
Parameters
1414
----------
1515
errors_to_suppress: List[ValidationFailure]
1616
List of ValidationFailures to ignore.
17+
data_source: str
18+
Name of data source as obtained from params
1719
1820
Attributes
1921
----------
2022
errors_to_suppress: List[ValidationFailure]
2123
See above
24+
data_source: str
25+
See above
2226
num_suppressed: int
2327
Number of errors suppressed
2428
total_checks: int
@@ -31,12 +35,12 @@ def __init__(self, errors_to_suppress: List[ValidationFailure]):
3135
Errors raised from validation failures not found in `self.errors_to_suppress`
3236
"""
3337
self.errors_to_suppress = errors_to_suppress
38+
self.data_source = data_source
3439
self.num_suppressed = 0
3540
self.total_checks = 0
3641
self.raised_errors = []
3742
self.raised_warnings = []
3843
self.unsuppressed_errors = []
39-
self.summary = ""
4044

4145
def add_raised_error(self, error):
4246
"""Add an error to the report.
@@ -74,21 +78,25 @@ def add_raised_warning(self, warning):
7478
"""
7579
self.raised_warnings.append(warning)
7680

77-
def set_summary(self):
78-
"""Represent summary of report as a string."""
79-
out_str = f"{self.total_checks} checks run\n"
80-
out_str += f"{len(self.unsuppressed_errors)} checks failed\n"
81-
out_str += f"{self.num_suppressed} checks suppressed\n"
82-
out_str += f"{len(self.raised_warnings)} warnings\n"
83-
self.summary = out_str
84-
8581
def log(self, logger=None):
8682
"""Log errors and warnings."""
8783
if logger is None:
8884
logger = get_structured_logger(__name__)
8985

90-
self.set_summary()
91-
logger.info(self.summary)
86+
if self.success():
87+
logger.info("Validation run successful",
88+
data_source = self.data_source,
89+
checks_run = self.total_checks,
90+
checks_failed = len(self.unsuppressed_errors),
91+
checks_suppressed = self.num_suppressed,
92+
warnings = len(self.raised_warnings))
93+
else:
94+
logger.info("Validation run unsuccessful",
95+
data_source = self.data_source,
96+
checks_run = self.total_checks,
97+
checks_failed = len(self.unsuppressed_errors),
98+
checks_suppressed = self.num_suppressed,
99+
warnings = len(self.raised_warnings))
92100
for error in self.unsuppressed_errors:
93101
logger.critical(str(error))
94102
for warning in self.raised_warnings:

_delphi_utils_python/delphi_utils/validator/validate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def __init__(self, params):
3737
# Date/time settings
3838
self.time_window = TimeWindow.from_params(validation_params["common"]["end_date"],
3939
validation_params["common"]["span_length"])
40+
self.data_source = validation_params["common"].get("data_source", "")
4041

4142
self.static_validation = StaticValidator(validation_params)
4243
self.dynamic_validation = DynamicValidator(validation_params)
@@ -51,7 +52,7 @@ def validate(self):
5152
Returns:
5253
- ValidationReport collating the validation outcomes
5354
"""
54-
report = ValidationReport(self.suppressed_errors)
55+
report = ValidationReport(self.suppressed_errors, self.data_source)
5556
frames_list = load_all_files(self.export_dir, self.time_window.start_date,
5657
self.time_window.end_date)
5758
self.static_validation.validate(frames_list, report)

_delphi_utils_python/tests/validator/test_report.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ def test_str(self):
4040
report.add_raised_warning(ImportWarning("right import"))
4141
report.add_raised_error(self.ERROR_1)
4242
report.add_raised_error(self.ERROR_2)
43-
report.set_summary()
44-
45-
assert report.summary ==\
46-
"3 checks run\n1 checks failed\n1 checks suppressed\n2 warnings\n"
4743

4844
def test_log(self):
4945
"""Test that the logs contain all failures and warnings."""

0 commit comments

Comments
 (0)