IATI / IATI-Dashboard

A dashboard of various metrics, generated nightly from IATI data
http://dashboard.iatistandard.org
16 stars 20 forks source link

Prefer default vocabulary (if a default exists) #568

Closed andylolz closed 3 years ago

andylolz commented 4 years ago

The problem

Some attributes can contain values from different codelists, depending on the @vocabulary used. The dashboard doesn’t have a means of showing this, as per the yellow banner shown on dashboard codelists, and #174.

Given the dashboard doesn’t have the functionality to select from multiple vocabularies, it needs to choose which vocabulary to use. Where a default vocabulary exists, it seems to make sense to prefer that one. That doesn’t necessarily happen at the moment, so this PR fixes that.

So for example, in the case of iati-activity/sector/@code, the default vocabulary is Sector. However, the dashboard currently uses the SectorCategory vocabulary:

Screenshot 2019-11-23 at 14 24 09

Similarly (as reported in #567), iati-activity/default-aid-type/@code uses the AidType vocabulary by default. However, the dashboard currently uses the (rarely used) CashAndVoucherModalities vocabulary: Screenshot 2019-11-23 at 14 27 26

The proposed solution

This PR ensures that when a default vocabulary exists for a given attribute, it is preferred on dashboard codelist pages.

For iati-activity/sector/@code, that’s Sector: Screenshot 2019-11-23 at 14 30 28

For iati-activity/default-aid-type/@code, that’s AidType: Screenshot 2019-11-23 at 14 31 27

It’s worth noting that for a small number of IATI attributes, there is no default codelist. For example, iati-activity/tag/@code. In such cases, we use the codelist for the first mapping for that attribute found in the mapping file.

Fixes #567.

stevieflow commented 4 years ago

Interesting, thanks @andylolz

In terms of knowing the default vocabulary, my understanding is that this must be something you've inferred from the standard, as it's not a flat or explicit reference? If so, did you make a lookup table, or similar? It strikes me that would be a useful resource for the standard/users

andylolz commented 4 years ago

In terms of knowing the default vocabulary, my understanding is that this must be something you've inferred from the standard, as it's not a flat or explicit reference? If so, did you make a lookup table, or similar? It strikes me that would be a useful resource for the standard/users

Good question, @stevieflow! Apologies in advance for the very long answer…

There’s a mapping.xml file that is part of the Single Source of Truth (it lives in the IATI-Codelists repository), and defines the relationship between IATI attributes and IATI codelists. The dashboard and reference site both use this mapping file.

For instance, the mapping file states that iati-activity/recipient-country/@code should always contain a value from the Country codelist (ref):

<mapping>
    <path>//iati-activity/recipient-country/@code</path>
    <codelist ref="Country" />
</mapping>

When the code used depends on the @vocabulary, the mapping includes a condition element. For instance, the CashandVoucherModalities codelist can be used for iati-activity/default-aid-type/@code, but only when iati-activity/default-aid-type/@vocabulary is set to "4" (ref):

<mapping>
    <path>//iati-activity/default-aid-type/@code</path>
    <codelist ref="CashandVoucherModalities" />
    <condition>@vocabulary = '4'</condition>
</mapping>

In cases where multiple vocabularies can be used, there’s usually a default vocabulary. So for example, if no iati-activity/default-aid-type/@vocabulary is declared, the default vocabulary for iati-activity/default-aid-type/@code is the AidType codelist. This is shown in the mapping file by a not(@vocabulary) condition (ref):

<mapping>
    <path>//iati-activity/default-aid-type/@code</path>
    <codelist ref="AidType" />
    <condition>@vocabulary = '1' or not(@vocabulary)</condition>
</mapping>

So this pull request ensures the dahboard preferentially uses these default vocabularies (shown by a not(@vocabulary) condition) over any non-default vocabularies.

andylolz commented 3 years ago

Doesn’t look like this will be merged; closing.