Commit 3db64f36 authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

wip - improve error report display

parent d46f3308
......@@ -130,7 +130,7 @@
<p>Aucune erreur de structure.</p>
{% endif %}
{% set value_errors = report.table['error-stats']['value-errors'] %}
{% set value_errors = report.table['error-stats']['body-errors'] %}
{% if value_errors['count'] > 0 %}
<p>Erreurs de contenu ({{ value_errors['count'] }} sur {{ value_errors['rows-count'] }} ligne{% if value_errors['rows-count'] > 1 %}s{% endif %}) :</p>
<ul>
......
......@@ -137,7 +137,7 @@
<div class="mx-4">
<h3 class="my-4">
{% if report.table.errors.body %}
{% set value_errors = report.table['error-stats']['value-errors'] %}
{% set value_errors = report.table['error-stats']['body-errors'] %}
Erreurs de contenu ({{ value_errors['count'] }} sur {{ value_errors['rows-count'] }} ligne{% if value_errors['rows-count'] > 1 %}s{% endif %})
{% else %}
{% if report.table.errors.structure %}
......
......@@ -7,7 +7,7 @@ import json
import logging
import subprocess
import tempfile
from collections import defaultdict
from collections import defaultdict, Counter
from datetime import datetime
from operator import itemgetter
from pathlib import Path
......@@ -221,20 +221,27 @@ def improve_errors(errors):
# Set default title if no title
if not 'title' in err:
update_keys['title'] = '[{}]'.format(err['code'])
update_keys['title'] = translate_error_code(err['code'])
# Convert message to markdown only if no content
# => for pre-checks errors
if 'message' in err and not 'content' in err:
update_keys['message'] = commonmark(err['message'])
# # Convert message to markdown only if no content
# # => for pre-checks errors
# if 'message' in err and not 'content' in err:
# update_keys['message'] = commonmark(err['message'])
# Else, default message
elif not 'message' in err or err['message'] is None:
update_keys['message'] = '[{}]'.format(err['code'])
# # Else, default message
# elif not 'message' in err or err['message'] is None:
# update_keys['message'] = '[{}]'.format(err['code'])
# Message content
md_content = '*content soon available*' if not 'content' in err else err['content']
update_keys['content'] = commonmark(md_content)
# # Message content
# md_content = '*content soon available*' if not 'content' in err else err['content']
# update_keys['content'] = commonmark(md_content)
content = "*content soon available*"
if "description" in err:
content = err["description"]
elif "message" in err:
content = err["message"]
update_keys["content"] = commonmark(content)
return {**err, **update_keys}
......@@ -383,6 +390,8 @@ def create_validata_ui_report(validata_core_report, schema_dict):
"""
report = copy.deepcopy(validata_core_report)
#open("err_validata_core_report.json", "wt", encoding="utf-8").write(json.dumps(report, indent=2, sort_keys=True, ensure_ascii=False))
# One table is enough
report['table'] = report['tables'][0]
del report['tables']
......@@ -418,7 +427,7 @@ def create_validata_ui_report(validata_core_report, schema_dict):
# Then group them in 2 groups : structure and body
report['table']['errors'] = {'structure': [], 'body': []}
for err in errors:
if err['tag'] == 'structure':
if '#head' in err['tags'] or '#structure' in err['tags']:
report['table']['errors']['structure'].append(err)
else:
report['table']['errors']['body'].append(err)
......@@ -427,11 +436,11 @@ def create_validata_ui_report(validata_core_report, schema_dict):
rows = []
current_row_id = 0
for err in report['table']['errors']['body']:
if not 'row-number' in err:
if not 'rowPosition' in err:
print('ERR', err)
row_id = err['row-number']
del err['row-number']
del err['context']
row_id = err['rowPosition']
# del err['row-number']
# del err['context']
if row_id != current_row_id:
current_row_id = row_id
rows.append({'row_id': current_row_id, 'errors': {}})
......@@ -447,16 +456,31 @@ def create_validata_ui_report(validata_core_report, schema_dict):
report['repair_actions'] = compute_repair_actions(report['table']['errors']['structure'])
# Sort by error names in statistics
report["table"]["error-stats"] = {}
report["table"]["count-by-code"] = {}
stats = report['table']['error-stats']
for key in ('structure-errors', 'value-errors'):
stats = {}
total_errors_count = 0
for key in ('structure', 'body'):
# convert dict into tuples with french title instead of error code
# and sorts by title
stats[key] = {}
stats[key]["count-by-code"] = {}
stats[key]['count-by-code'] = sorted(((translate_error_code(k), v)
for k, v in stats[key]['count-by-code'].items()), key=itemgetter(0))
key_errors = report["table"]["errors"][key]
key_errors_count = len(key_errors)
ct = Counter(ke["code"] for ke in key_errors)
error_stats = {
"count": key_errors_count,
"count-by-code": sorted((translate_error_code(k), v) for k,v in ct.items())
}
total_errors_count += key_errors_count
# Add error rows count
if key == 'body':
error_rows = {err["rowPosition"] for row in key_errors if "rowPosition" in err}
error_stats["rows-count"] = len(error_rows)
stats[f"{key}-errors"] = error_stats
stats["count"] = total_errors_count
report["table"]["error-stats"] = stats
return report
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment