From 78d196fc4d398a75696fd0c2294ba2a7c44fe86c Mon Sep 17 00:00:00 2001 From: Varun Mittal Date: Fri, 23 Jun 2023 16:38:22 -0400 Subject: [PATCH] Added quick stat table to console outputter to show quick summary showing pass/fail counts (#16). --- .../outputter/outputter_console.py | 16 +++++++++++++ tests/outputter/test_outputter_console.py | 23 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/focus_validator/outputter/outputter_console.py b/focus_validator/outputter/outputter_console.py index 8b3b73e..579049f 100644 --- a/focus_validator/outputter/outputter_console.py +++ b/focus_validator/outputter/outputter_console.py @@ -9,6 +9,18 @@ def __init__(self, output_destination): self.output_destination = output_destination self.result_set = None + @staticmethod + def __generate_summary__(result_set: ValidationResult): + check_summary = {} + + for rule_check_list_object in result_set.checklist.values(): + status = rule_check_list_object.status + try: + check_summary[status.name] += 1 + except KeyError: + check_summary[status.name] = 1 + return pd.DataFrame(check_summary.items(), columns=["Status", "Count"]) + @staticmethod def __restructure_check_list__(result_set: ValidationResult): rows = [] @@ -48,6 +60,10 @@ def __restructure_check_list__(result_set: ValidationResult): def write(self, result_set: ValidationResult): self.result_set = result_set + check_summary = self.__generate_summary__(result_set) + print("Summary:") + print(tabulate(check_summary, headers="keys", tablefmt="psql")) + checklist = self.__restructure_check_list__(result_set) print("Checklist:") print(tabulate(checklist, headers="keys", tablefmt="psql")) diff --git a/tests/outputter/test_outputter_console.py b/tests/outputter/test_outputter_console.py index ce90863..15262a7 100644 --- a/tests/outputter/test_outputter_console.py +++ b/tests/outputter/test_outputter_console.py @@ -1,5 +1,7 @@ from unittest import TestCase +import pandas as pd + from focus_validator.outputter.outputter_console import ConsoleOutputter from focus_validator.validator import Validator @@ -28,3 +30,24 @@ def test_failure_output(self): "Status", ], ) + + def test_summary_output(self): + validator = Validator( + data_filename="samples/multiple_failure_example_namespaced.csv", + output_type="console", + output_destination=None, + dimension_namespace="F", + ) + validator.load() + result = validator.spec_rules.validate(focus_data=validator.focus_data) + + outputter = ConsoleOutputter(output_destination=None) + summary_output = outputter.__generate_summary__(result_set=result) + self.assertIsInstance(summary_output, pd.DataFrame) + self.assertEqual( + list(summary_output.columns), + [ + "Status", + "Count", + ], + )