Skip to content

Commit cc503ad

Browse files
authored
Merge pull request #46 from OCHA-DAP/main
Version 0.10.29
2 parents caaa982 + 89865ed commit cc503ad

8 files changed

+118
-113
lines changed

CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

7+
## [0.10.29] - 2024-12-12
8+
9+
### Fixed
10+
11+
- 3W for NGA
12+
13+
### Changed
14+
15+
- Added ability to read historical humanitarian needs data
16+
- Replaced missing funding amounts with zeros
17+
- Updated 3W data for CAF, SSD
18+
719
## [0.10.28] - 2024-12-10
820

921
### Changed

src/hapi/pipelines/configs/operational_presence.yaml

+20-22
Original file line numberDiff line numberDiff line change
@@ -62,35 +62,33 @@ operational_presence_admintwo:
6262

6363
operational_presence_caf:
6464
dataset: "republique-centrafricaine-presence-operationnelle"
65-
resource: "3W_CAR_Mar2024"
65+
resource: "3W_CAR_Sep2024"
6666
format: "xlsx"
6767
xlsx2csv: True
68-
sheet: "OCHA CAR 3W OP T1 2024"
69-
headers:
70-
- 1
71-
- 2
68+
sheet: "3W T3 2024"
69+
headers: 1
7270
source_date:
73-
start: "01/01/2024"
74-
end: "31/03/2024"
71+
start: "01/04/2024"
72+
end: "30/09/2024"
7573
use_hxl: False
7674
admin:
7775
- ~
78-
- "PCODE2 #adm2+code"
76+
- "PCODE2"
7977
admin_exact: True
8078
input:
81-
- "Description_Acteur"
82-
- "ACTEUR #org+acronym"
79+
- "DESCRIPTION_ACTEUR"
80+
- "ACTEUR"
8381
- "TYPE_ORG"
84-
- "SECTEUR #sector"
85-
- "PREFECTURE #adm1+name"
86-
- "SOUSPREFECTURE #adm2+name"
82+
- "SECTEUR"
83+
- "PREFECTURE"
84+
- "SOUSPREFECTURE"
8785
list:
88-
- "Description_Acteur"
89-
- "ACTEUR #org+acronym"
86+
- "DESCRIPTION_ACTEUR"
87+
- "ACTEUR"
9088
- "TYPE_ORG"
91-
- "SECTEUR #sector"
92-
- "PREFECTURE #adm1+name"
93-
- "SOUSPREFECTURE #adm2+name"
89+
- "SECTEUR"
90+
- "PREFECTURE"
91+
- "SOUSPREFECTURE"
9492

9593
operational_presence_cmr:
9694
dataset: "cameroon-5w-operational-presence"
@@ -356,7 +354,7 @@ operational_presence_admintwo:
356354

357355
operational_presence_nga:
358356
dataset: "nigeria-3w"
359-
resource: "who-is-doing-what-and-where_nga_3w_apr_jun_2024.xlsx.csv"
357+
resource: "who-is-doing-what-and-where_nga_3w_apr_jun_2024.csv"
360358
format: "csv"
361359
headers: 1
362360
source_date:
@@ -759,14 +757,14 @@ operational_presence_national:
759757

760758
operational_presence_ssd:
761759
dataset: "south-sudan-operational-presence"
762-
resource: "ss_20241106_3w_oerational presence_Jan to Sep_2024.xlsx"
760+
resource: "ss_20241212_3w_oerational presence_Jan to Oct_2024.xlsx"
763761
format: "xlsx"
764762
xlsx2csv: True
765-
sheet: "data"
763+
sheet: "Data"
766764
headers: 1
767765
source_date:
768766
start: "01/01/2024"
769-
end: "30/09/2024"
767+
end: "31/10/2024"
770768
admin_single: "SSD"
771769
input:
772770
- "Name of organization"

src/hapi/pipelines/database/funding.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,10 @@ def populate(self) -> None:
9696
# This check for a missing funding line has been added due to
9797
# an error in the UKR funding requirements data
9898
if funding_usd is None:
99-
self._error_manager.add_missing_value_message(
100-
"Funding",
101-
dataset_name,
102-
"funding_usd for appeal code",
103-
appeal_code,
104-
resource_name=resource_name,
105-
err_to_hdx=True,
106-
)
107-
continue
99+
funding_usd = 0
108100
funding_pct = row["#value+funding+pct"]
101+
if funding_pct is None and funding_usd == 0:
102+
funding_pct = 0
109103
reference_period_start = parse_date(row["#date+start"])
110104
reference_period_end = parse_date(row["#date+end"])
111105

src/hapi/pipelines/database/humanitarian_needs.py

+80-79
Original file line numberDiff line numberDiff line change
@@ -95,86 +95,87 @@ def populate(self) -> None:
9595
self._metadata.add_dataset(dataset)
9696
dataset_id = dataset["id"]
9797
dataset_name = dataset["name"]
98-
resource = dataset.get_resource(0) # assumes first resource is latest!
99-
self._metadata.add_resource(dataset_id, resource)
100-
negative_values_by_iso3 = {}
101-
rounded_values_by_iso3 = {}
102-
resource_id = resource["id"]
103-
resource_name = resource["name"]
104-
year = int(resource_name[-4:])
105-
time_period_start = datetime(year, 1, 1)
106-
time_period_end = datetime(year, 12, 31, 23, 59, 59)
107-
url = resource["url"]
108-
headers, rows = reader.get_tabular_rows(url, dict_form=True)
109-
# Admin 1 PCode,Admin 2 PCode,Sector,Gender,Age Group,Disabled,Population Group,Population,In Need,Targeted,Affected,Reached
110-
for row in rows:
111-
countryiso3 = row["Country ISO3"]
112-
admin2_ref = self.get_admin2_ref(row, dataset_name)
113-
if not admin2_ref:
114-
continue
115-
provider_admin1_name = get_provider_name(row, "Admin 1 Name")
116-
provider_admin2_name = get_provider_name(row, "Admin 2 Name")
117-
sector = row["Sector"]
118-
sector_code = self._sector.get_sector_code(sector)
119-
if not sector_code:
120-
self._error_manager.add_missing_value_message(
121-
"HumanitarianNeeds", dataset_name, "sector", sector
122-
)
123-
continue
124-
category = row["Category"]
125-
if category is None:
126-
category = ""
127-
128-
def create_row(in_col, population_status):
129-
value = row[in_col]
130-
if value is None:
131-
return
132-
value = get_numeric_if_possible(value)
133-
if value < 0:
134-
dict_of_lists_add(
135-
negative_values_by_iso3, countryiso3, str(value)
98+
resources = dataset.get_resources()
99+
for resource in resources:
100+
self._metadata.add_resource(dataset_id, resource)
101+
negative_values_by_iso3 = {}
102+
rounded_values_by_iso3 = {}
103+
resource_id = resource["id"]
104+
resource_name = resource["name"]
105+
year = int(resource_name[-4:])
106+
time_period_start = datetime(year, 1, 1)
107+
time_period_end = datetime(year, 12, 31, 23, 59, 59)
108+
url = resource["url"]
109+
headers, rows = reader.get_tabular_rows(url, dict_form=True)
110+
# Admin 1 PCode,Admin 2 PCode,Sector,Gender,Age Group,Disabled,Population Group,Population,In Need,Targeted,Affected,Reached
111+
for row in rows:
112+
countryiso3 = row["Country ISO3"]
113+
admin2_ref = self.get_admin2_ref(row, dataset_name)
114+
if not admin2_ref:
115+
continue
116+
provider_admin1_name = get_provider_name(row, "Admin 1 Name")
117+
provider_admin2_name = get_provider_name(row, "Admin 2 Name")
118+
sector = row["Sector"]
119+
sector_code = self._sector.get_sector_code(sector)
120+
if not sector_code:
121+
self._error_manager.add_missing_value_message(
122+
"HumanitarianNeeds", dataset_name, "sector", sector
136123
)
137-
return
138-
if isinstance(value, float):
139-
dict_of_lists_add(
140-
rounded_values_by_iso3, countryiso3, str(value)
124+
continue
125+
category = row["Category"]
126+
if category is None:
127+
category = ""
128+
129+
def create_row(in_col, population_status):
130+
value = row[in_col]
131+
if value is None:
132+
return
133+
value = get_numeric_if_possible(value)
134+
if value < 0:
135+
dict_of_lists_add(
136+
negative_values_by_iso3, countryiso3, str(value)
137+
)
138+
return
139+
if isinstance(value, float):
140+
dict_of_lists_add(
141+
rounded_values_by_iso3, countryiso3, str(value)
142+
)
143+
value = round(value)
144+
humanitarian_needs_row = DBHumanitarianNeeds(
145+
resource_hdx_id=resource_id,
146+
admin2_ref=admin2_ref,
147+
provider_admin1_name=provider_admin1_name,
148+
provider_admin2_name=provider_admin2_name,
149+
category=category,
150+
sector_code=sector_code,
151+
population_status=population_status,
152+
population=value,
153+
reference_period_start=time_period_start,
154+
reference_period_end=time_period_end,
141155
)
142-
value = round(value)
143-
humanitarian_needs_row = DBHumanitarianNeeds(
144-
resource_hdx_id=resource_id,
145-
admin2_ref=admin2_ref,
146-
provider_admin1_name=provider_admin1_name,
147-
provider_admin2_name=provider_admin2_name,
148-
category=category,
149-
sector_code=sector_code,
150-
population_status=population_status,
151-
population=value,
152-
reference_period_start=time_period_start,
153-
reference_period_end=time_period_end,
154-
)
155-
self._session.add(humanitarian_needs_row)
156+
self._session.add(humanitarian_needs_row)
156157

157-
create_row("Population", "all")
158-
create_row("Affected", "AFF")
159-
create_row("In Need", "INN")
160-
create_row("Targeted", "TGT")
161-
create_row("Reached", "REA")
158+
create_row("Population", "all")
159+
create_row("Affected", "AFF")
160+
create_row("In Need", "INN")
161+
create_row("Targeted", "TGT")
162+
create_row("Reached", "REA")
162163

163-
self._session.commit()
164-
for countryiso3, values in negative_values_by_iso3.items():
165-
self._error_manager.add_multi_valued_message(
166-
"HumanitarianNeeds",
167-
dataset_name,
168-
f"negative population value(s) removed in {countryiso3}",
169-
values,
170-
resource_name=resource_name,
171-
err_to_hdx=True,
172-
)
173-
for countryiso3, values in rounded_values_by_iso3.items():
174-
self._error_manager.add_multi_valued_message(
175-
"HumanitarianNeeds",
176-
dataset_name,
177-
f"population value(s) rounded in {countryiso3}",
178-
values,
179-
message_type="warning",
180-
)
164+
self._session.commit()
165+
for countryiso3, values in negative_values_by_iso3.items():
166+
self._error_manager.add_multi_valued_message(
167+
"HumanitarianNeeds",
168+
dataset_name,
169+
f"negative population value(s) removed in {countryiso3}",
170+
values,
171+
resource_name=resource_name,
172+
err_to_hdx=True,
173+
)
174+
for countryiso3, values in rounded_values_by_iso3.items():
175+
self._error_manager.add_multi_valued_message(
176+
"HumanitarianNeeds",
177+
dataset_name,
178+
f"population value(s) rounded in {countryiso3}",
179+
values,
180+
message_type="warning",
181+
)

tests/fixtures/input/global-hpc-hno.json

+1-1
Large diffs are not rendered by default.

tests/fixtures/input/nigeria-3w.json

+1-1
Large diffs are not rendered by default.

tests/test_main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def test_funding(self, configuration, folder, pipelines):
230230
count = session.scalar(select(func.count(DBResource.hdx_id)))
231231
check.equal(count, 3)
232232
count = session.scalar(select(func.count(DBFunding.resource_hdx_id)))
233-
check.equal(count, 56)
233+
check.equal(count, 57)
234234

235235
@pytest.mark.parametrize(
236236
"themes_to_run", [{"conflict_event": ("BFA", "COL")}]

0 commit comments

Comments
 (0)