Commit 0df5763f authored by Pierre Dittgen's avatar Pierre Dittgen

Adapt to statistics adjustments

parent 98a7316f
...@@ -70,10 +70,10 @@ ...@@ -70,10 +70,10 @@
{% macro error_statistics(report) %} {% macro error_statistics(report) %}
{% set structure_errors = report.table['error-stats']['structure-errors'] %} {% set structure_errors = report.table['error-stats']['structure-errors'] %}
{% if structure_errors['nb'] != 0 %} {% if structure_errors['count'] != 0 %}
Erreur(s) de structure ({{ structure_errors['nb'] }}) : Erreur(s) de structure ({{ structure_errors['count'] }}) :
<ul> <ul>
{% for elt in structure_errors['distribution'] %} {% for elt in structure_errors['count-by-code'] %}
<li>{{ elt[0] }} : {{ elt[1] }}</li> <li>{{ elt[0] }} : {{ elt[1] }}</li>
{% endfor %} {% endfor %}
</ul> </ul>
...@@ -81,10 +81,10 @@ Erreur(s) de structure ({{ structure_errors['nb'] }}) : ...@@ -81,10 +81,10 @@ Erreur(s) de structure ({{ structure_errors['nb'] }}) :
{% if report.table.do_display_body_errors %} {% if report.table.do_display_body_errors %}
{% set value_errors = report.table['error-stats']['value-errors'] %} {% set value_errors = report.table['error-stats']['value-errors'] %}
{% if value_errors['nb'] != 0 %} {% if value_errors['count'] != 0 %}
Erreur(s) de contenu ({{ value_errors['nb'] }}) : Erreur(s) de contenu ({{ value_errors['count'] }}) :
<ul> <ul>
{% for elt in value_errors['distribution'] %} {% for elt in value_errors['count-by-code'] %}
<li>{{ elt[0] }} : {{ elt[1] }}</li> <li>{{ elt[0] }} : {{ elt[1] }}</li>
{% endfor %} {% endfor %}
</ul> </ul>
......
...@@ -94,7 +94,7 @@ ...@@ -94,7 +94,7 @@
<h2>La table est invalide</h2> <h2>La table est invalide</h2>
<p class="text">{{ report.table['error-stats']['total'] }} erreur(s) détectée(s).</p> <p class="text">{{ report.table['error-stats']['count'] }} erreur(s) détectée(s).</p>
{{ macros.error_statistics(report) }} {{ macros.error_statistics(report) }}
......
...@@ -8,6 +8,7 @@ import subprocess ...@@ -8,6 +8,7 @@ import subprocess
import time import time
from datetime import datetime from datetime import datetime
from io import BytesIO from io import BytesIO
from operator import itemgetter
from pathlib import Path from pathlib import Path
from urllib.parse import quote_plus from urllib.parse import quote_plus
...@@ -15,7 +16,7 @@ from commonmark import commonmark ...@@ -15,7 +16,7 @@ from commonmark import commonmark
from flask import make_response, redirect, render_template, request, url_for from flask import make_response, redirect, render_template, request, url_for
import tabulator import tabulator
from validata_core import csv_helpers from validata_core import csv_helpers, messages
from validata_core.loaders import custom_loaders from validata_core.loaders import custom_loaders
from validata_ui import app from validata_ui import app
from validata_ui.ui_util import flash_error, flash_warning from validata_ui.ui_util import flash_error, flash_warning
...@@ -133,7 +134,7 @@ def create_validata_report(goodtables_report, schema): ...@@ -133,7 +134,7 @@ def create_validata_report(goodtables_report, schema):
# Then group them in 2 groups : structure and body # Then group them in 2 groups : structure and body
report['table']['errors'] = {'structure': [], 'body': []} report['table']['errors'] = {'structure': [], 'body': []}
for err in errors: for err in errors:
if err['context'] != 'body': if err['tag'] == 'structure':
report['table']['errors']['structure'].append(err) report['table']['errors']['structure'].append(err)
else: else:
report['table']['errors']['body'].append(err) report['table']['errors']['body'].append(err)
...@@ -164,6 +165,15 @@ def create_validata_report(goodtables_report, schema): ...@@ -164,6 +165,15 @@ def create_validata_report(goodtables_report, schema):
rows[-1]['errors']['row'] = err rows[-1]['errors']['row'] = err
report['table']['errors']['body_by_rows'] = rows report['table']['errors']['body_by_rows'] = rows
# Sort by error names in statistics
stats = report['table']['error-stats']
code_title_map = messages.ERROR_MESSAGE_DEFAULT_TITLE
for key in ('structure-errors', 'value-errors'):
# convert dict into tuples with french title instead of error code
# and sorts by title
stats[key]['count-by-code'] = sorted([(code_title_map.get(k, k), v) for k, v in stats[key]['count-by-code'].items()],
key=itemgetter(0))
return report 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