open-sdg / sdg-build

Python package to convert SDG-related data and metadata between formats
MIT License
5 stars 23 forks source link

Allow per-indicator callbacks in Open SDG output #314

Closed brockfanning closed 1 year ago

brockfanning commented 2 years ago

This feature allows Open SDG implementations to perform some custom Python code on each indicator - not for the purposes of altering any output - but for any other purpose, like maybe to generate some additional output that is not in sdg-build.

Testing instructions:

In your data repository's build_data.py file try the following code:

from sdg.open_sdg import open_sdg_build

def my_indicator_callback(indicator):
  print('Running indicator callback for indicator ' + indicator.inid)

open_sdg_build(config='config_data.yml', indicator_callback=my_indicator_callback)

When the data build runs, there should be log entries printed that say "Running indicator callback for indicator 1.1.1" etc.

Q A
Feature branch/test site URL [Link](https://github.com/ONSdigital/sdg-data/tree/feature-per-indicator-callbacks

) Fixed issues | N/A Related version | 2.2.0-dev Bugfix, feature or docs? |

codecov[bot] commented 2 years ago

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.04 :tada:

Comparison is base (c78e8bd) 73.76% compared to head (ae2a0d1) 73.80%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## 2.2.0-dev #314 +/- ## ============================================= + Coverage 73.76% 73.80% +0.04% ============================================= Files 74 74 Lines 4577 4584 +7 ============================================= + Hits 3376 3383 +7 Misses 1201 1201 ``` | [Impacted Files](https://codecov.io/gh/open-sdg/sdg-build/pull/314?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-sdg) | Coverage Δ | | |---|---|---| | [sdg/open\_sdg.py](https://codecov.io/gh/open-sdg/sdg-build/pull/314?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-sdg#diff-c2RnL29wZW5fc2RnLnB5) | `79.18% <100.00%> (+0.55%)` | :arrow_up: | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-sdg). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=open-sdg)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

LucyGwilliamAdmin commented 2 years ago

@brockfanning just trying to understand this - do you have an example of how it may be applied?

Govej commented 1 year ago

image

Test carried out on the branch https://github.com/ONSdigital/sdg-data/tree/feature-per-indicator-callbacks

Logs showing "Running indicator callback for indicator 1.1.1"