Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding to the report a formatted table read from json file #36

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions skvalidate/report/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,61 @@ def __repr_section__(name, section):
str(section),
)

def formatted_table(table_json, **kwargs):

with open(table_json) as f:
table = json.load(f)

try:
if 'table_header' not in table:
raise Exception("Missing \'table_header\' field")
if 'table_content' not in table:
raise Exception("Missing \'table_content\' field")
except Exception as e:
logger.error('Error reading the table file: {}'.format(e))
raise e

if 'symbol_success' in kwargs:
symbol_success = kwargs.pop('symbol_success')
else:
symbol_success = 'success'

if 'symbol_failed' in kwargs:
symbol_failed = kwargs.pop('symbol_failed')
else:
symbol_failed = 'failed'

header_keys = []
formated_header = '|'
formated_separator = '|'

for key, name in table['table_header'].items():
header_keys.append(key)
formated_header += f' {name} |'
formated_separator += '---|'

formated_table = {}
formated_table['table_header'] = formated_header
formated_table['table_separator'] = formated_separator

formated_content = []

for var_key, var_values in table['table_content'].items():
formated_line = '|'
for header_key in header_keys:
if header_key.find('status') != -1 and var_values[header_key]:
formated_line += f' {symbol_success} |'
elif header_key.find('status') != -1:
formated_line += f' {symbol_failed} |'
else:
formated_line += f' {var_values[header_key]} |'

formated_content.append(formated_line)

formated_table['table_content'] = formated_content

return formated_table


def get_metrics(metrics_json, metrics_ref_json, **kwargs):
profile = kwargs.pop('profile', '')
Expand Down