Skip to content
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

🔨 Jinja metadata for UN IGME #1898

Merged
merged 25 commits into from
Nov 8, 2023
Merged

🔨 Jinja metadata for UN IGME #1898

merged 25 commits into from
Nov 8, 2023

Conversation

spoonerf
Copy link
Contributor

@spoonerf spoonerf commented Nov 2, 2023

Hey @Marigold this is a bit of a WIP but I'm trying to figure out Jinja templates. I think I am along the right lines but it doesn't seem to be adding the metadata to the variables as I expect. Probably missing something silly but if you could take a look when you get a chance that would be ace!

@spoonerf spoonerf requested a review from Marigold November 2, 2023 15:07
@spoonerf
Copy link
Contributor Author

spoonerf commented Nov 2, 2023

Hey @Marigold this is a bit of a WIP but I'm trying to figure out Jinja templates. I think I am along the right lines but it doesn't seem to be adding the metadata to the variables as I expect. Probably missing something silly but if you could take a look when you get a chance that would be ace!

Ah, I think it's because the section at the top e.g. where I have indicator, that should in fact be variable names? I probably need to restructure the data so that there is a column for each indicator...

@spoonerf spoonerf removed the request for review from Marigold November 2, 2023 15:57
@Marigold
Copy link
Collaborator

Marigold commented Nov 2, 2023

You were pretty close @spoonerf! Here is the corrected version (took me a while, working with templates can get complex)

definitions:
  common:
    presentation:
      topic_tags:
        - Child & Infant Mortality
  sex: |-
    <% if sex == "Both sexes" %>

    <% elif sex == "Male" %>
    male
    <% elif sex == "Female" %>
    female
    <%- endif -%>
  wealth_quintile: |-
    <% if wealth_quintile == "All wealth quintiles" %>
    all wealth quintiles
    <% elif wealth_quintile == "Poorest quintile" %>
    the poorest 20% of the population
    <% elif wealth_quintile == "Second poorest quintile" %>
    the second poorest 20% of the population
    <% elif wealth_quintile == "Middle wealth quintile" %>
    the middle 20% of the population in terms of wealth
    <% elif wealth_quintile == "Fourth poorest quintile" %>
    the second richest 20% of the population
    <% elif wealth_quintile == "Richest quintile" %>
    the richest 20% of the population
    <%- endif -%>
  unit_of_measure:
    unit: |-
      <% if unit_of_measure == "Deaths per 1,000 live births" %>
      deaths per 1,000 live births
      <% elif unit_of_measure == "Deaths per 1000 children aged 10" %>
      deaths per 1,000 children aged 10
      <% elif unit_of_measure == "Deaths per 1000 children aged 15" %>
      deaths per 1,000 children aged 15
      <% elif unit_of_measure == "Deaths per 1000 children aged 1" %>
      deaths per 1,000 children aged 1
      <% elif unit_of_measure == "Deaths per 1000 children aged 20" %>
      deaths per 1,000 children aged 20
      <% elif unit_of_measure == "Deaths per 1000 children aged 5" %>
      deaths per 1,000 children aged 5
      <% elif unit_of_measure == "Number of stillbirths" %>
      stillbirths
      <% elif unit_of_measure == "Stillbirths per 1,000 total births" %>
      stillbirths per 1,000 total births
      <% elif unit_of_measure == "Number of deaths" %>
      deaths
      <%- endif -%>
  indicator:
    display_name: |-
      <% if indicator == "Neonatal mortality rate" %>
      The estimated number of deaths of << sex >> children aged less than 28 days, per 1,000 live births, in <<wealth_quintile>>.
      <% elif indicator == "Mortality rate 1-59 months" %>
      The estimated number of deaths of << sex >> children aged between 1 and 59 months, per 1,000 live births, in <<wealth_quintile>>.
      <% elif indicator == "Infant mortality rate" %>
      The estimated number of deaths of << sex >> children aged under one year, per 1,000 live births, in <<wealth_quintile>>.
      <% elif indicator == "Under-five mortality rate" %>
      The estimated number of deaths of << sex >> children aged under five years, per 1,000 live births, in <<wealth_quintile>>.
      <% elif indicator == "Mortality rate age 10-14" %>
      The estimated number of deaths of << sex >> children aged between 10 and 14, per 1,000 children aged 10, in <<wealth_quintile>>.
      <% elif indicator == "Mortality rate age 10-19" %>
      The estimated number of deaths of << sex >> children aged between 10 and 19, per 1,000 children aged 10, in <<wealth_quintile>>.
      <% elif indicator == "Mortality rate age 15-19" %>
      The estimated number of deaths of << sex >> children aged between 15 and 19, per 1,000 children aged 15, in <<wealth_quintile>>.
      <% elif indicator == "Mortality rate age 15-24" %>
      The estimated number of deaths of << sex >> children aged between 15 and 24, per 1,000 children aged 15, in <<wealth_quintile>>.
      <% elif indicator == "Child Mortality rate age 1-4" %>
      The estimated number of deaths of << sex >> children aged between 1 and 4, per 1,000 children aged 1, in <<wealth_quintile>>.
      <% elif indicator == "Mortality rate age 20-24" %>
      The estimated number of deaths of << sex >> children aged between 20 and 24, per 1,000 children aged 20, in <<wealth_quintile>>.
      <% elif indicator == "Mortality rate age 5-14" %>
      The estimated number of deaths of << sex >> children aged between 5 and 14, per 1,000 children aged 5, in <<wealth_quintile>>.
      <% elif indicator == "Mortality rate age 5-24" %>
      The estimated number of deaths of << sex >> children aged between 5 and 24, per 1,000 children aged 5, in <<wealth_quintile>>.
      <% elif indicator == "Mortality rate age 5-9" %>
      The estimated number of deaths of << sex >> children aged between 5 and 9, per 1,000 children aged 5, in <<wealth_quintile>>.
      <% elif indicator == "Stillbirths" %>
      The estimated number of stillbirths, in <<wealth_quintile>>.
      <% elif indicator == "Stillbirth rate" %>
      The estimated number of stillbirths, per 1,000 total births, in <<wealth_quintile>>.
      <% elif indicator == "Neonatal deaths" %>
      The estimated number of deaths of << sex >> children aged less than 28 days, in <<wealth_quintile>>.
      <% elif indicator == "Deaths 1-59 months" %>
      The estimated number of deaths of << sex >> children aged between 1 and 59 months, in <<wealth_quintile>>.
      <% elif indicator == "Mortality rate age 5-14" %>
      The estimated number of deaths of << sex >> children aged between 5 and 14, per 1,000 children aged 5, in <<wealth_quintile>>.
      <% elif indicator == "Mortality rate age 5-14" %>
      The estimated number of deaths of << sex >> children aged between 5 and 14, per 1,000 children aged 5, in <<wealth_quintile>>.
      <% elif indicator == "Mortality rate age 5-14" %>
      The estimated number of deaths of << sex >> children aged between 5 and 14, per 1,000 children aged 5, in <<wealth_quintile>>.
      <% elif indicator == "Mortality rate age 5-14" %>
      The estimated number of deaths of << sex >> children aged between 5 and 14, per 1,000 children aged 5, in <<wealth_quintile>>.
      <% elif indicator == "Mortality rate age 5-14" %>
      The estimated number of deaths of << sex >> children aged between 5 and 14, per 1,000 children aged 5, in <<wealth_quintile>>.
      <% elif indicator == "Mortality rate age 5-14" %>
      The estimated number of deaths of << sex >> children aged between 5 and 14, per 1,000 children aged 5, in <<wealth_quintile>>.
      <% elif indicator == "Mortality rate age 5-14" %>
      The estimated number of deaths of << sex >> children aged between 5 and 14, per 1,000 children aged 5, in <<wealth_quintile>>.
      <% elif indicator == "Mortality rate age 5-14" %>
      The estimated number of deaths of << sex >> children aged between 5 and 14, per 1,000 children aged 5, in <<wealth_quintile>>.
      <% elif indicator == "Mortality rate age 5-14" %>
      The estimated number of deaths of << sex >> children aged between 5 and 14, per 1,000 children aged 5, in <<wealth_quintile>>.
      <% elif indicator == "Mortality rate age 5-14" %>
      The estimated number of deaths of << sex >> children aged between 5 and 14, per 1,000 children aged 5, in <<wealth_quintile>>.
      <%- endif -%>
tables:
  igme:
    variables:
      observation_value:
        title: Observation value
        unit: |-
          {definitions.unit_of_measure.unit}
        display:
          name: |-
            {definitions.indicator.display_name}
      lower_bound:
        title: Lower bound
        unit: |-
          {definitions.unit_of_measure.unit}
        display:
          name: |-
            {definitions.indicator.display_name}
      upper_bound:
        title: Upper bound
        unit: |-
          {definitions.unit_of_measure.unit}
        display:
          name: |-
            {definitions.indicator.display_name}

A couple of comments:

  • In Jinja templates you should use << ... >> to reference dimension values, not <%
  • Dynamic placeholders must not contain whitespace, i.e. use {definitions.unit_of_measure.unit} and not { definitions.unit_of_measure.unit } (not sure why it doesn't work...)
  • I had to change definitions.indicator.display.name to definitions.indicator.display_name because YAML doesn't like the dot

The template itself is good after fixing those small issues. I've tried running etl un/2023-08-16/igme --grapher and got proper display names in Admin.

(When inserting to grapher, I got the error Variables used in charts will not be deleted automatically. That typically means variables have changed short names. If you struggle with fixing it, ping me and I'll be glad to help)

@spoonerf
Copy link
Contributor Author

spoonerf commented Nov 2, 2023

Amazing thanks @Marigold! I'll try and figure out the next steps and almost certainly ping you. I think it's likely the short names will be different, but I think we've got round that before by using chart revisions?

@Marigold
Copy link
Collaborator

Marigold commented Nov 2, 2023

but I think we've got round that before by using chart revisions?

Exactly. By the way it'd be great if you could ping me after this PR is ready before doing chart revisions. I'd like to test syncing of changes from staging servers to production.

@spoonerf spoonerf marked this pull request as ready for review November 3, 2023 12:20
@spoonerf spoonerf requested a review from Marigold November 3, 2023 12:25
@spoonerf
Copy link
Contributor Author

spoonerf commented Nov 3, 2023

but I think we've got round that before by using chart revisions?

Exactly. By the way it'd be great if you could ping me after this PR is ready before doing chart revisions. I'd like to test syncing of changes from staging servers to production.

Hey @Marigold - I think we're at this stage now, I believe the only issue remaining is the Variables used in charts will not be deleted automatically one.

@Marigold
Copy link
Collaborator

Marigold commented Nov 7, 2023

I looked into the Variables used in charts will not be deleted automatically error. It happens because variables now use different (short) names.

You should first rebase or merge this PR onto the master. I'd also recommend reordering index levels to be consistent with the current version to make chart revision easier

tb = tb.reorder_levels(["country", "year", "unit_of_measure", "indicator", "sex", "wealth_quintile"])
tb_youth = tb_youth.reorder_levels(["country", "year", "unit_of_measure", "indicator", "sex", "wealth_quintile"])

If you make this change and commit back, staging server will rebuild ETL and you should see an updated dataset there.

Once you have that, the best way to fix this error is to map those variables with

STAGING=igme-metadata etl-wizard charts

and then approving them in chart revisions.

I tried to do it myself, but it's not as straightforward as some old variables don't exist in the current dataset (something with middle income group and possibly others).

With the new workflow, you can approve chart revisions on the staging server, then I can sync them to production (after we merge this PR).

@spoonerf
Copy link
Contributor Author

spoonerf commented Nov 7, 2023

Amazing, thanks @Marigold!

I had messed up some of the variables, making variable matching impossible, but sorted that out now. I have approved the chart revisions on the staging server. So I think we can merge this now? I will wait to hear from you before merging.

* changing units to %

* fixing short_unit

* fixing conversion
@spoonerf spoonerf merged commit 2c6a7a3 into master Nov 8, 2023
1 check passed
@spoonerf spoonerf deleted the igme-metadata branch November 8, 2023 09:33
spoonerf added a commit that referenced this pull request Nov 8, 2023
@spoonerf spoonerf restored the igme-metadata branch November 8, 2023 09:42
@lucasrodes lucasrodes deleted the igme-metadata branch June 13, 2024 20:09
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.

2 participants