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

feat(regions): include income groups #3544

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 10 additions & 6 deletions baker/algolia/indexChartsToAlgolia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
OwidGdocLinkType,
excludeNullish,
isNil,
countries,
regions,
orderBy,
removeTrailingParenthetical,
} from "@ourworldindata/utils"
Expand All @@ -23,10 +23,14 @@ const computeScore = (record: Omit<ChartRecord, "score">): number => {
return numRelatedArticles * 500 + views_7d
}

const countriesWithVariantNames = new Set(
countries
.filter((country) => country.variantNames?.length || country.shortName)
.map((country) => country.name)
const regionsWithVariantNames = new Set(
regions
.filter(
(region) =>
("variantNames" in region && region.variantNames?.length) ||
("shortName" in region && region.shortName)
)
.map((region) => region.name)
)

const processAvailableEntities = (availableEntities: string[] | null) => {
Expand All @@ -45,7 +49,7 @@ const processAvailableEntities = (availableEntities: string[] | null) => {
availableEntities,
[
(entityName) =>
countriesWithVariantNames.has(
regionsWithVariantNames.has(
removeTrailingParenthetical(entityName)
),
(entityName) => entityName.includes("-"),
Expand Down
6 changes: 5 additions & 1 deletion devTools/regionsUpdater/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import _ from "lodash"

const ETL_REGIONS_URL =
process.env.ETL_REGIONS_URL ||
"https://catalog.ourworldindata.org/grapher/regions/latest/regions/regions.csv",
"https://catalog.ourworldindata.org/external/owid_grapher/latest/regions/regions.csv",
GEO_JSON_URL =
"https://raw.githubusercontent.com/alexabruck/worldmap-sensitive/master/dist/world.geo.json",
GRAPHER_ROOT = __dirname.replace(/\/(itsJustJavascript\/)?devTools.*/, ""),
Expand All @@ -31,6 +31,10 @@ const ETL_REGIONS_URL =
MKD: ["Macedonia"],
SWZ: ["Swaziland"],
USA: ["US", "USA"],
OWID_LIC: ["Low-income"],
OWID_LMC: ["Lower-middle income"],
OWID_UMC: ["Upper-middle income"],
OWID_HIC: ["High-income"],
}

interface Entity {
Expand Down
253 changes: 253 additions & 0 deletions packages/@ourworldindata/utils/src/regions.json
Original file line number Diff line number Diff line change
Expand Up @@ -1730,6 +1730,98 @@
"regionType": "country",
"isHistorical": true
},
{
"code": "OWID_HIC",
"name": "High-income countries",
"slug": "high-income-countries",
"regionType": "income_group",
"variantNames": ["High-income"],
"members": [
"ASM",
"AND",
"ATG",
"ABW",
"AUS",
"AUT",
"BHS",
"BHR",
"BRB",
"BEL",
"BMU",
"VGB",
"BRN",
"CAN",
"CYM",
"OWID_CIS",
"CHL",
"HRV",
"CUW",
"CYP",
"CZE",
"DNK",
"EST",
"FRO",
"FIN",
"FRA",
"PYF",
"DEU",
"GIB",
"GRC",
"GRL",
"GUM",
"GUY",
"HKG",
"HUN",
"ISL",
"IRL",
"IMN",
"ISR",
"ITA",
"JPN",
"KOR",
"KWT",
"LVA",
"LIE",
"LTU",
"LUX",
"MAC",
"MLT",
"MCO",
"NRU",
"NLD",
"NCL",
"NZL",
"MNP",
"NOR",
"OMN",
"PAN",
"POL",
"PRT",
"PRI",
"QAT",
"ROU",
"SMR",
"SAU",
"SYC",
"SGP",
"SXM",
"SVK",
"SVN",
"ESP",
"KNA",
"MAF",
"SWE",
"CHE",
"TWN",
"TTO",
"TCA",
"ARE",
"GBR",
"USA",
"URY",
"VIR"
]
},
{
"code": "OWID_KOS",
"name": "Kosovo",
Expand All @@ -1744,6 +1836,104 @@
"regionType": "country",
"isHistorical": true
},
{
"code": "OWID_LIC",
"name": "Low-income countries",
"slug": "low-income-countries",
"regionType": "income_group",
"variantNames": ["Low-income"],
"members": [
"AFG",
"BFA",
"BDI",
"CAF",
"TCD",
"COD",
"ERI",
"ETH",
"GMB",
"GNB",
"PRK",
"LBR",
"MDG",
"MWI",
"MLI",
"MOZ",
"NER",
"RWA",
"SLE",
"SOM",
"SSD",
"SDN",
"SYR",
"TGO",
"UGA",
"YEM"
]
},
{
"code": "OWID_LMC",
"name": "Lower-middle-income countries",
"slug": "lower-middle-income-countries",
"regionType": "income_group",
"variantNames": ["Lower-middle income"],
"members": [
"DZA",
"AGO",
"BGD",
"BEN",
"BTN",
"BOL",
"CPV",
"KHM",
"CMR",
"COM",
"COG",
"CIV",
"DJI",
"EGY",
"SWZ",
"GHA",
"GIN",
"HTI",
"HND",
"IND",
"IRN",
"JOR",
"KEN",
"KIR",
"KGZ",
"LAO",
"LBN",
"LSO",
"MRT",
"FSM",
"MNG",
"MAR",
"MMR",
"NPL",
"NIC",
"NGA",
"PAK",
"PNG",
"PHL",
"WSM",
"SEN",
"SLB",
"LKA",
"STP",
"TJK",
"TZA",
"TLS",
"TUN",
"UKR",
"UZB",
"VUT",
"VNM",
"ZMB",
"ZWE"
]
},
{
"code": "OWID_MNS",
"name": "Melanesia",
Expand Down Expand Up @@ -1980,6 +2170,69 @@
"regionType": "country",
"isHistorical": true
},
{
"code": "OWID_UMC",
"name": "Upper-middle-income countries",
"slug": "upper-middle-income-countries",
"regionType": "income_group",
"variantNames": ["Upper-middle income"],
"members": [
"ALB",
"ARG",
"ARM",
"AZE",
"BLR",
"BLZ",
"BIH",
"BWA",
"BRA",
"BGR",
"CHN",
"COL",
"CRI",
"CUB",
"DMA",
"DOM",
"ECU",
"SLV",
"GNQ",
"FJI",
"GAB",
"GEO",
"GRD",
"GTM",
"IDN",
"IRQ",
"JAM",
"KAZ",
"OWID_KOS",
"LBY",
"MYS",
"MDV",
"MHL",
"MUS",
"MEX",
"MDA",
"MNE",
"NAM",
"MKD",
"PLW",
"PRY",
"PER",
"RUS",
"SRB",
"ZAF",
"LCA",
"VCT",
"SUR",
"THA",
"TON",
"TKM",
"TUV",
"TUR",
"PSE"
]
},
{
"code": "OWID_USS",
"name": "USSR",
Expand Down
15 changes: 14 additions & 1 deletion packages/@ourworldindata/utils/src/regions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum RegionType {
Other = "other",
Aggregate = "aggregate",
Continent = "continent",
IncomeGroup = "income_group",
}

export interface Country {
Expand All @@ -27,6 +28,14 @@ export interface Aggregate {
members: string[]
}

export interface IncomeGroup {
name: string
regionType: "income_group"
code: string
members: string[]
variantNames?: string[]
}

export interface Continent {
name:
| "Africa"
Expand All @@ -40,7 +49,7 @@ export interface Continent {
members: string[]
}

export type Region = Country | Aggregate | Continent
export type Region = Country | Aggregate | IncomeGroup | Continent

export const regions: Region[] = entities as Region[]

Expand All @@ -59,6 +68,10 @@ export const aggregates: Aggregate[] = entities.filter(
(entity) => entity.regionType === "aggregate"
) as Aggregate[]

export const IncomeGroups: IncomeGroup[] = entities.filter(
(entity) => entity.regionType === "income_group"
) as IncomeGroup[]

export const continents: Continent[] = entities.filter(
(entity) => entity.regionType === "continent"
) as Continent[]
Expand Down