Skip to content

Country region vocabulary #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

leilafarsani
Copy link
Collaborator

Implement country-region vocabulary-based splitting

This PR implements correct handling of countries and regions according to the IATI standard:
Recipient-country documentation

When both the recipient-region and recipient-country are declared, then the @percentage values should sum to 100% per region vocabulary for the specific iati-activity.


✅ Changes Made

  • Countries and regions from the same vocabulary now form a single 100% allocation.
  • Multiple region vocabularies result in independent 100% allocations.
  • Percentages are normalised within each vocabulary group.
  • Added vocabulary attribute to IATIActivityRecipientRegion.

🛠 Implementation Details

  • Countries are always considered part of vocabulary "1" (the default vocabulary).
  • Regions can belong to any vocabulary (defaults to "1" if not specified).
  • When countries and regions share a vocabulary, they are grouped for percentage-based splitting.
  • Each vocabulary group forms a separate 100% allocation.

🧪 Testing

Added five new tests to verify:

  • ✅ Countries and regions in the same vocabulary are treated together.
  • ✅ Splitting works across multiple region vocabularies.
  • ✅ Percentages are properly normalized within vocab groups.
  • ✅ Splitting when only countries are present.
  • ✅ Total output can exceed original value when vocabularies are independent.

All existing tests continue to pass.


🔗 Related Issues

Resolves #6

@leilafarsani leilafarsani self-assigned this May 6, 2025
@leilafarsani leilafarsani requested a review from jarofgreen May 6, 2025 12:11
assert region_south["value"] == 500


def test_incorrect_percentages_normalisation():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this test, there is only 1 vocabulary? And the percentages add up to 100 anyway? I think it would be a better test if both those things were changed

assert region_africa["value"] == 250


def test_multiple_region_vocabularies():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the results correct here?

  • Vocab 1, FR + GB + ASIA + AFRICA = 250 + 250 + 250 + 250 = 1000, that's good
  • Vocab 2, FR + GB + NORTH + SOUTH = 25% + 25% + 50% + 50% = 150% = 250 + 250 + 500 + 500 = 1500, to much? That 150% total should have been normalised back to 100% I think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

What should happen when an activity has both 2 countries AND 2 regions with %'s defined?
2 participants