Commit 6ef18790 authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

Merge branch '86_rapports_de_test' into 'frictionless_scratch'

Modifications du rapport de validation

See merge request !10
parents a46749c9 09b3e015
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
## next ## next
- fix source rows count display - fix source rows count display
- display missing required header as structure error
- restore filename display in report page
- move recommendations block before structure errors
- upgrade validata-core vesion to 0.6.0a9
## 0.4.0a20 ## 0.4.0a20
......
...@@ -66,15 +66,25 @@ ...@@ -66,15 +66,25 @@
<p> <p>
<code> <code>
{% if source.type == 'file' %} {% if resource.type == 'file' %}
{{ source.filename }} {{ resource.filename }}
{% elif source.type == 'url' %} {% elif resource.type == 'url' %}
<a href="{{source.url}}" target="_blank">{{source.filename}}</a> <a href="{{resource.url}}" target="_blank">{{resource.filename}}</a>
{% endif %} {% endif %}
</code> </code>
({{ report.table.col_count }} colonnes × {{ report.table.row_count }} lignes) ({{ report.table.col_count }} colonnes × {{ report.table.row_count }} lignes)
</p> </p>
{% if report.warn_count != 0 %}
<p>
{% if report.warn_count == 1 %}
1 recommandation
{% else %}
{{ report.warn_count }} recommandations
{% endif %}
</p>
{% endif %}
{% if report.error_count == 0 %} {% if report.error_count == 0 %}
<p>Aucune erreur détectée</p> <p>Aucune erreur détectée</p>
{% else %} {% else %}
...@@ -89,53 +99,40 @@ ...@@ -89,53 +99,40 @@
{% endif %} {% endif %}
</p> </p>
{% endif %} {% endif %}
{% if report.warn_count != 0 %}
<p>
{% if report.warn_count == 1 %}
1 recommandation
{% else %}
{{ report.warn_count }} recommandations
{% endif %}
</p>
{% endif %}
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="mx-4">
{% if report.table.errors.structure %}
<h3 class="my-4">Erreurs de structure ({{ report.table['error-stats']['structure-errors']['count'] }})</h3>
<p>Prévisualisation du fichier source avec structure invalide (en-têtes)</p>
{# source header display #}
<div class="mb-4">
<div class="table-responsive">
<table class="table table-striped table-bordered table-sm table-hover">
<thead class="thead-light">
<tr>
{% for h, err in source_data.source_header_info %}
<th{% if err %} class="table-danger"{% endif %}>{{ h }}</th>
{% endfor %}
</tr>
</thead>
</table>
</div>
</div>
{% endif %}
</div>
{# Display body errors #} {% if report.warn_count != 0 %}
<div class="mx-4"> <div class="mx-4 info">
{% if report.warn_count != 0 %}
<h3 class="my-4">Recommandations</h3> <h3 class="my-4">Recommandations</h3>
<p>Afin d'assurer la conformité optimale de vos données par rapport au schéma,
merci de prendre en compte les recommandations ci-dessous :</p>
<ul> <ul>
{% for warn in report.warnings %} {% for warn in report.warnings %}
<li>{{ warn.message | commonmark2html | safe}}</li> <li>{{ warn.message | commonmark2html | safe}}</li>
{% endfor %} {% endfor %}
</ul> </ul>
{% endif %} </div>
{% endif %}
{% if report.table.errors.structure %}
<div class="mx-4">
<h3 class="my-4">Erreurs de structure ({{ report.table['error-stats']['structure-errors']['count']}})</h3>
<ul>
{% for err in report.table.errors.structure %}
<li>{{ err.message | commonmark2html | safe}}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{# Display body errors #}
<div class="mx-4">
<h3 class="my-4"> <h3 class="my-4">
{% if report.table.errors.body %} {% if report.table.errors.body %}
{% set value_errors = report.table['error-stats']['body-errors'] %} {% set value_errors = report.table['error-stats']['body-errors'] %}
......
...@@ -7,6 +7,7 @@ import json ...@@ -7,6 +7,7 @@ import json
import logging import logging
from collections import Counter from collections import Counter
from datetime import datetime from datetime import datetime
from pathlib import Path
from urllib.parse import urlencode, urljoin from urllib.parse import urlencode, urljoin
import frictionless import frictionless
...@@ -347,6 +348,14 @@ def get_badge_url_and_message(badge): ...@@ -347,6 +348,14 @@ def get_badge_url_and_message(badge):
def validate(schema_instance: SchemaInstance, validata_resource: ValidataResource): def validate(schema_instance: SchemaInstance, validata_resource: ValidataResource):
""" Validate source and display report """ """ Validate source and display report """
def compute_resource_info(resource: ValidataResource):
source = resource.get_source()
return {
"type": "url" if source.startswith("http") else "file",
"url": source,
"filename": Path(source).name,
}
# Parse source data once # Parse source data once
header, rows = validata_resource.extract_tabular_data() header, rows = validata_resource.extract_tabular_data()
rows_count = len(rows) rows_count = len(rows)
...@@ -443,7 +452,7 @@ def validate(schema_instance: SchemaInstance, validata_resource: ValidataResourc ...@@ -443,7 +452,7 @@ def validate(schema_instance: SchemaInstance, validata_resource: ValidataResourc
schema_info=schema_info, schema_info=schema_info,
section_title=schema_instance.section_title, section_title=schema_instance.section_title,
source_data=build_template_source_data(header, rows), source_data=build_template_source_data(header, rows),
source=validata_resource, resource=compute_resource_info(validata_resource),
validation_date=report_datetime.strftime("le %d/%m/%Y à %Hh%M"), validation_date=report_datetime.strftime("le %d/%m/%Y à %Hh%M"),
) )
......
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