-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
📊 happiness: by age group #2867
Draft
antea04
wants to merge
19
commits into
master
Choose a base branch
from
happiness-ages
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6c34ec1
add snapshot
2580b2e
add meadow, garden and grapher step
a60f658
recover garden and meadow steps
feb2692
recover dag
ff09c9a
country harmonization
7502a7b
Merge remote-tracking branch 'origin/master' into happiness-ages
796dfed
trigger build
bffd82d
pivot table for grapher & add origins
80f3442
fix build
20a81b3
move happiness by age group data into happiness dataset
4a7d80d
improve descriptions
ee4eeea
remove regional aggregates where data is missing & update metadata
b1c4805
trigger build
2594511
PR review comments (fix pivoting and metadata)
20fccbf
edit metadata
07048e5
new staging server
698e6c6
fix charts and metadata
d0453d1
trigger build
4ec2d5f
Merge remote-tracking branch 'origin/master' into happiness-ages
Marigold File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
etl/steps/data/grapher/happiness/2024-06-09/happiness.meta.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# NOTE: To learn more about the fields, hover over their names. | ||
definitions: | ||
common: | ||
presentation: | ||
topic_tags: | ||
- Happiness & Life Satisfaction | ||
attribution_short: WHR | ||
display: | ||
numDecimalPlaces: 2 | ||
processing_level: major | ||
unit: "" | ||
short_unit: "" | ||
origins: | ||
# Data product / Snapshot | ||
- title: World Happiness Report | ||
description: |- | ||
The World Happiness Report is a partnership of Gallup, the Oxford Wellbeing Research Centre, the UN Sustainable Development Solutions Network, and the WHR’s Editorial Board. | ||
It reviews the state of happiness in the world today and shows how the science of happiness explains personal and national variations in happiness. | ||
date_published: "2024-03-08" | ||
version_producer: 2024 | ||
# Citation | ||
producer: Wellbeing Research Centre | ||
citation_full: |- | ||
Helliwell, J. F., Layard, R., Sachs, J. D., De Neve, J.-E., Aknin, L. B., & Wang, S. (Eds.). (2024). World Happiness Report 2024. University of Oxford: Wellbeing Research Centre. | ||
attribution_short: WHR | ||
# Files | ||
url_main: https://worldhappiness.report/ed/2024/ | ||
date_accessed: 2024-06-20 | ||
# License | ||
license: | ||
name: "" | ||
url: https://worldhappiness.report/ed/2024/ | ||
description_short: | ||
"Self-reported life satisfaction is the answer to the question: | ||
'Imagine a ladder with the best possible life being a 10, and the worst possible life being a 0. | ||
Which step on that ladder would you say you stand on right now?'" | ||
description_processing: | ||
Average of regions is calculated by taking a population-weighted average over all countries within that region. | ||
Since data per age group is not available for all countries, regional aggregates can sometimes differ. | ||
description_key: | ||
- The Cantril ladder asks respondents to think of a ladder, with the best possible life for them being a 10 and the worst possible life being a 0. They are then asked to rate their own current lives on that 0 to 10 scale. | ||
- The rankings are calculated by the source based on nationally representative samples for the three years prior to the year of the report, so that data for the 2024 report will draw from survey data from 2021-2023. We show the data for final year of the three-year survey period, i.e. we show the 2021-2023 survey data as 2023. | ||
- The only exception is the data for the 2012 report, which uses survey data from 2005-2011, we show this data as the final year of the survey data - 2011. | ||
- The number of people and countries surveyed varies year to year, but typically more than 100,000 people in 130 countries participate in the Gallup World Poll each year. | ||
- The rankings are based entirely on the survey scores, using the Gallup weights to make the estimates representative. | ||
- The data is the compilation of all previous World Happiness Reports, which can be found at https://worldhappiness.report/archive/. | ||
|
||
|
||
|
||
|
||
# Learn more about the available fields: | ||
# http://docs.owid.io/projects/etl/architecture/metadata/reference/ | ||
dataset: | ||
update_period_days: 365 | ||
|
||
|
||
tables: | ||
happiness: | ||
variables: | ||
happiness_below_30: | ||
title: Life satisfaction of people below 30 | ||
happiness_30_to_44: | ||
title: Life satisfaction of people aged 30-44 | ||
happiness_45_to_59: | ||
title: Life satisfaction of people aged 45-59 | ||
happiness_60_and_above: | ||
title: Life satisfaction of people aged 60 and above | ||
happiness_all_ages: | ||
title: Cantril ladder score | ||
description_short: Average of survey responses to the 'Cantril Ladder' question in the Gallup World Poll. The survey question asks respondents to think of a ladder, with the best possible life for them being a 10, and the worst possible life being a 0. | ||
presentation: | ||
attribution: World Happiness Report (2012-2024) | ||
attribution_short: WHR | ||
title_public: Self-reported life satisfaction | ||
display: | ||
numDecimalPlaces: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
etl/steps/data/meadow/happiness/2024-06-20/happiness_ages.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Load a snapshot and create a meadow dataset.""" | ||
|
||
from etl.helpers import PathFinder, create_dataset | ||
|
||
# Get paths and naming conventions for current step. | ||
paths = PathFinder(__file__) | ||
|
||
COLUMN_MAPPING = { | ||
"Country name": "country", | ||
"year": "year", | ||
"Region indicator": "region", | ||
"Age group code": "age_group_code", | ||
"Age group": "age_group", | ||
"Mean of ladder": "happiness_score", | ||
"Mean of stress": "stress_score", | ||
"Mean of worry": "worry_score", | ||
"Count of ladder": "happiness_count", | ||
"Count of stress": "stress_count", | ||
"Count of worry": "worry_count", | ||
} | ||
|
||
|
||
def run(dest_dir: str) -> None: | ||
# | ||
# Load inputs. | ||
# | ||
# Retrieve snapshot. | ||
snap = paths.load_snapshot("happiness_ages.xls") | ||
|
||
# Load data from snapshot. | ||
tb = snap.read() | ||
|
||
# rename columns | ||
tb = tb.rename(columns=COLUMN_MAPPING, errors="raise") | ||
|
||
# Ensure all columns are snake-case, set an appropriate index, and sort conveniently. | ||
tb = tb.format(["country", "year", "age_group"]) | ||
|
||
# | ||
# Save outputs. | ||
# | ||
# Create a new meadow dataset with the same metadata as the snapshot. | ||
ds_meadow = create_dataset(dest_dir, tables=[tb], check_variables_metadata=True, default_metadata=snap.metadata) | ||
|
||
# Save changes in the new meadow dataset. | ||
ds_meadow.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
"""Script to create a snapshot of dataset.""" | ||
|
||
from pathlib import Path | ||
|
||
import click | ||
|
||
from etl.snapshot import Snapshot | ||
|
||
# Version for current snapshot dataset. | ||
SNAPSHOT_VERSION = Path(__file__).parent.name | ||
|
||
|
||
@click.command() | ||
@click.option("--upload/--skip-upload", default=True, type=bool, help="Upload dataset to Snapshot") | ||
@click.option("--path-to-file", prompt=True, type=str, help="Path to local data file.") | ||
def main(path_to_file: str, upload: bool) -> None: | ||
# Create a new snapshot. | ||
snap = Snapshot(f"happiness/{SNAPSHOT_VERSION}/happiness_ages.xls") | ||
|
||
# Copy local data file to snapshots data folder, add file to DVC and upload to S3. | ||
snap.create_snapshot(filename=path_to_file, upload=upload) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use some Jinja templating here to add metadata to specific age-groups, if you want. Using this you can add index values into the metadata. Here is a slightly complicated example of how you can do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would help with the question you had about pivoting in the grapher step.