Skip to content

Commit

Permalink
Added quick stat table to console outputter to show quick summary sho…
Browse files Browse the repository at this point in the history
…wing pass/fail counts (#16).
  • Loading branch information
varunmittal91 committed Jun 23, 2023
1 parent c8513f0 commit 78d196f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
16 changes: 16 additions & 0 deletions focus_validator/outputter/outputter_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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"))
Expand Down
23 changes: 23 additions & 0 deletions tests/outputter/test_outputter_console.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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",
],
)

0 comments on commit 78d196f

Please sign in to comment.