-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ele 2626 support singular tests in test results runs (#1449)
* rename * test results and runs includes keys for singular as well * freshness api types * change test runs totals * fix type * types cleanup + fix test results totals
- Loading branch information
Showing
5 changed files
with
54 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,40 @@ | ||
from collections import defaultdict | ||
from typing import Dict, List, Optional, Union | ||
from typing import Dict, List, Union | ||
|
||
from elementary.monitor.api.source_freshnesses.schema import ( | ||
SourceFreshnessMetadataSchema, | ||
SourceFreshnessResultSchema, | ||
SourceFreshnessRunSchema, | ||
) | ||
from elementary.monitor.api.tests.schema import ( | ||
TestMetadataSchema, | ||
TestResultSchema, | ||
TestRunSchema, | ||
) | ||
from elementary.monitor.api.tests.schema import TestResultSchema, TestRunSchema | ||
from elementary.monitor.api.totals_schema import TotalsSchema | ||
|
||
|
||
def get_total_test_results( | ||
test_results: Dict[ | ||
Optional[str], List[Union[TestResultSchema, SourceFreshnessResultSchema]] | ||
], | ||
) -> Dict[Optional[str], TotalsSchema]: | ||
test_metadatas = [] | ||
for test_result in test_results.values(): | ||
test_metadatas.extend([result.metadata for result in test_result]) | ||
test_results: Dict[str, List[Union[TestResultSchema, SourceFreshnessResultSchema]]], | ||
) -> Dict[str, TotalsSchema]: | ||
totals: Dict[str, TotalsSchema] = defaultdict(TotalsSchema) | ||
for key, test_result in test_results.items(): | ||
for result in test_result: | ||
# count by the key of the tests_results | ||
totals[key].add_total(result.metadata.latest_run_status) | ||
|
||
return _calculate_test_results_totals(test_metadatas) | ||
return totals | ||
|
||
|
||
def get_total_test_runs( | ||
tests_runs: Dict[ | ||
Optional[str], List[Union[TestRunSchema, SourceFreshnessRunSchema]] | ||
] | ||
) -> Dict[Optional[str], TotalsSchema]: | ||
totals: Dict[Optional[str], TotalsSchema] = defaultdict(TotalsSchema) | ||
for test_runs in tests_runs.values(): | ||
tests_runs: Dict[str, List[Union[TestRunSchema, SourceFreshnessRunSchema]]] | ||
) -> Dict[str, TotalsSchema]: | ||
totals: Dict[str, TotalsSchema] = defaultdict(TotalsSchema) | ||
for key, test_runs in tests_runs.items(): | ||
for test_run in test_runs: | ||
# It's possible test_runs will be None if we didn't find any invocations associated | ||
# with this test, in that case it also makes sense to skip it. | ||
if not test_run.test_runs: | ||
continue | ||
|
||
test_invocations = test_run.test_runs.invocations | ||
model_unique_id = test_run.metadata.model_unique_id | ||
|
||
for test_invocation in test_invocations: | ||
totals[model_unique_id].add_total(test_invocation.status) | ||
return totals | ||
|
||
|
||
def _calculate_test_results_totals( | ||
test_metadatas: List[Union[TestMetadataSchema, SourceFreshnessMetadataSchema]], | ||
) -> Dict[Optional[str], TotalsSchema]: | ||
totals: Dict[Optional[str], TotalsSchema] = defaultdict(TotalsSchema) | ||
for test in test_metadatas: | ||
totals[test.model_unique_id].add_total(test.latest_run_status) | ||
# count by the key of the tests_runs | ||
totals[key].add_total(test_invocation.status) | ||
return totals |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters