Skip to content

Commit

Permalink
Added helpers to get data for the data-quality tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikola Lekich committed Jan 22, 2020
1 parent e2d870b commit 72d129f
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 1 deletion.
17 changes: 17 additions & 0 deletions ckanext/knowledgehub/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,3 +990,20 @@ def get_dataset_data(id):
break

return data_dict

def get_package_data_quality(id):
print(id)
context = _get_context()
try:
result = toolkit.get_action('package_data_quality') (context, {'id': id})
except Exception:
return {}
return result

def get_resource_data_quality(id):
context = _get_context()
try:
result = toolkit.get_action('resource_data_quality') (context, {'id': id})
except Exception:
return {}
return result
4 changes: 3 additions & 1 deletion ckanext/knowledgehub/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ def get_helpers(self):
'get_tab_url': h.get_tab_url,
'is_rsc_upload_datastore': h.is_rsc_upload_datastore,
'get_dataset_data': h.get_dataset_data,
'get_resource_filtered_data': h.get_resource_filtered_data
'get_resource_filtered_data': h.get_resource_filtered_data,
'get_package_data_quality': h.get_package_data_quality,
'get_resource_data_quality': h.get_resource_data_quality,
}

# IDatasetForm
Expand Down
179 changes: 179 additions & 0 deletions ckanext/knowledgehub/templates/package/snippets/additional_info.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
{% set data_quality = h.get_package_data_quality(pkg_dict.id) %}
<section class="additional-info">
<h3>{{ _('Additional Info') }}</h3>
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th scope="col">{{ _('Field') }}</th>
<th scope="col">{{ _('Value') }}</th>
</tr>
</thead>
<tbody>
{% block package_additional_info %}
{% if pkg_dict.url %}
<tr>
<th scope="row" class="dataset-label">{{ _('Source') }}</th>
{% if h.is_url(pkg_dict.url) %}
<td class="dataset-details" property="foaf:homepage">
{{ h.link_to(pkg_dict.url, pkg_dict.url, rel='foaf:homepage', target='_blank') }}</td>
{% else %}
<td class="dataset-details" property="foaf:homepage">{{ pkg_dict.url }}</td>
{% endif %}
</tr>
{% endif %}

{% if pkg_dict.author_email %}
<tr>
<th scope="row" class="dataset-label">{{ _("Author") }}</th>
<td class="dataset-details" property="dc:creator">
{{ h.mail_to(email_address=pkg_dict.author_email, name=pkg_dict.author) }}</td>
</tr>
{% elif pkg_dict.author %}
<tr>
<th scope="row" class="dataset-label">{{ _("Author") }}</th>
<td class="dataset-details" property="dc:creator">{{ pkg_dict.author }}</td>
</tr>
{% endif %}

{% if pkg_dict.maintainer_email %}
<tr>
<th scope="row" class="dataset-label">{{ _('Maintainer') }}</th>
<td class="dataset-details" property="dc:contributor">
{{ h.mail_to(email_address=pkg_dict.maintainer_email, name=pkg_dict.maintainer) }}</td>
</tr>
{% elif pkg_dict.maintainer %}
<tr>
<th scope="row" class="dataset-label">{{ _('Maintainer') }}</th>
<td class="dataset-details" property="dc:contributor">{{ pkg_dict.maintainer }}</td>
</tr>
{% endif %}

{% if pkg_dict.version %}
<tr>
<th scope="row" class="dataset-label">{{ _("Version") }}</th>
<td class="dataset-details">{{ pkg_dict.version }}</td>
</tr>
{% endif %}

{% if h.check_access('package_update',{'id':pkg_dict.id}) %}
<tr>
<th scope="row" class="dataset-label">{{ _("State") }}</th>
<td class="dataset-details">{{ _(pkg_dict.state) }}</td>
</tr>
{% endif %}
{% if pkg_dict.metadata_modified %}
<tr>
<th scope="row" class="dataset-label">{{ _("Last Updated") }}</th>
<td class="dataset-details">
{% snippet 'snippets/local_friendly_datetime.html', datetime_obj=pkg_dict.metadata_modified %}
</td>
</tr>
{% endif %}
{% if pkg_dict.metadata_created %}
<tr>
<th scope="row" class="dataset-label">{{ _("Created") }}</th>

<td class="dataset-details">
{% snippet 'snippets/local_friendly_datetime.html', datetime_obj=pkg_dict.metadata_created %}
</td>
</tr>
{% endif %}
{% block extras scoped %}
{% for extra in h.sorted_extras(pkg_dict.extras) %}
{% set key, value = extra %}
<tr rel="dc:relation" resource="_:extra{{ i }}">
<th scope="row" class="dataset-label" property="rdfs:label">{{ _(key) }}</th>
<td class="dataset-details" property="rdf:value">{{ value }}</td>
</tr>
{% endfor %}
{% endblock %}

{% endblock %}
</tbody>
</table>

<br>

<h3>{{ _('Data Quality') }}</h3>
{% if data_quality.calculated_on %}
<p>Calculated on: {{data_quality.calculated_on}}</p>
{% endif %}
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th scope="col">{{ _('Field') }}</th>
<th scope="col">{{ _('Value') }}</th>
</tr>
</thead>
<tbody>
<!-- <label> Completeness </label> <span> {{data_quality.timeliness }} -->
{% if data_quality.completeness %}
<tr>
<th>Completeness</th>
<td>{{data_quality.completeness}}</td>
</tr>
{% else %}
<tr>
<th>Completeness</th>
<td>N/A</td>
</tr>
{% endif %}
{% if data_quality.timeliness %}
<tr>
<th>Timeliness</th>
<td>{{data_quality.timeliness}}</td>
</tr>
{% else %}
<tr>
<th>Timeliness</th>
<td>N/A</td>
</tr>
{% endif %}
{% if data_quality.validity %}
<tr>
<th>Validity</th>
<td>{{data_quality.validity}}</td>
</tr>
{% else %}
<tr>
<th>Validity</th>
<td>N/A</td>
</tr>
{% endif %}
{% if data_quality.uniqueness %}
<tr>
<th>Uniqueness</th>
<td>{{data_quality.uniqueness}}</td>
</tr>
{% else %}
<tr>
<th>Uniqueness</th>
<td>N/A</td>
</tr>
{% endif %}
{% if data_quality.consistency %}
<tr>
<th>Consistency</th>
<td>{{data_quality.consistency}}</td>
</tr>
{% else %}
<tr>
<th>Consistency</th>
<td>N/A</td>
</tr>
{% endif %}
{% if data_quality.accuracy %}
<tr>
<th>Accuracy</th>
<td>{{data_quality.accuracy}}</td>
</tr>
{% else %}
<tr>
<th>Accuracy</th>
<td>N/A</td>
</tr>
{% endif %}

</tbody>
</table>
</section>

0 comments on commit 72d129f

Please sign in to comment.