Skip to content

Commit cfb7b80

Browse files
authored
HDXDSYS-898 Refactor org code (OCHA-DAP#134)
* Add uncleaned names as keys to lookups Remove intersectoral check dict() to {} Move branches that have continue higher up in loops in operational presence * Some rearrangement of operational presence and comments to help me understand the org processing * Small reorg of org type if code * store normalised keys as well as non normalised * Use already normalised key * Simplify org lookup code and operational presence * Add to lookup to reduce need to keep normalising * Pass around normalise variables * Remove org lookup only used in test * Remove unnecessary variable * Update CHANGELOG * Can just return value here * Combine ifs * Use named tuples for clarity * Rename value to org_info * Use org_data in populate_multiple * Use OrgData in tests * Make OrgInfo into a data class Add used and complete bools to OrgInfo Correct OrgInfo objects in org_map with corrections from looking up in data member variable * Make separate function * Add debug option to command line Add org_map debug
1 parent 95ec410 commit cfb7b80

12 files changed

+476
-188
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ 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.9.36] - 2024-07-19
8+
9+
### Changed
10+
11+
- Refactor org code
12+
- Also add uncleaned names as keys to lookups
13+
714
## [0.9.35] - 2024-07-18
815

916
### Fixed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ requires-python = ">=3.8"
3636
dependencies = [
3737
"hapi-schema>=0.8.14",
3838
"hdx-python-api>= 6.3.1",
39-
"hdx-python-country>= 3.7.6",
39+
"hdx-python-country>= 3.7.7",
4040
"hdx-python-database[postgresql]>= 1.3.1",
4141
"hdx-python-scraper>= 2.4.0",
4242
"hdx-python-utilities>= 3.7.2",

requirements.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ click==8.1.7
2626
# via typer
2727
coverage==7.6.0
2828
# via pytest-cov
29-
cryptography==42.0.8
29+
cryptography==43.0.0
3030
# via pyopenssl
3131
defopt==6.4.0
3232
# via hdx-python-api
@@ -64,7 +64,7 @@ hdx-python-api==6.3.1
6464
# via
6565
# hapi-pipelines (pyproject.toml)
6666
# hdx-python-scraper
67-
hdx-python-country==3.7.6
67+
hdx-python-country==3.7.7
6868
# via
6969
# hapi-pipelines (pyproject.toml)
7070
# hdx-python-api
@@ -172,13 +172,13 @@ pydantic-core==2.20.1
172172
# via pydantic
173173
pygments==2.18.0
174174
# via rich
175-
pyopenssl==24.1.0
175+
pyopenssl==24.2.1
176176
# via
177177
# hdx-python-api
178178
# ndg-httpsclient
179179
pyphonetics==0.5.3
180180
# via hdx-python-country
181-
pytest==8.2.2
181+
pytest==8.3.1
182182
# via
183183
# hapi-pipelines (pyproject.toml)
184184
# pytest-check
@@ -242,7 +242,7 @@ ruamel-yaml==0.18.6
242242
# via hdx-python-utilities
243243
ruamel-yaml-clib==0.2.8
244244
# via ruamel-yaml
245-
setuptools==70.3.0
245+
setuptools==71.1.0
246246
# via ckanapi
247247
shellingham==1.5.4
248248
# via typer

src/hapi/pipelines/app/__main__.py

+12
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ def parse_args():
8484
action="store_true",
8585
help="Use saved data",
8686
)
87+
parser.add_argument(
88+
"-dbg",
89+
"--debug",
90+
default=False,
91+
action="store_true",
92+
help="Debug",
93+
)
8794
return parser.parse_args()
8895

8996

@@ -95,6 +102,7 @@ def main(
95102
basic_auths: Optional[Dict[str, str]] = None,
96103
save: bool = False,
97104
use_saved: bool = False,
105+
debug: bool = False,
98106
**ignore,
99107
) -> None:
100108
"""Run HAPI. Either a database connection string (db_uri) or database
@@ -110,6 +118,7 @@ def main(
110118
basic_auths (Optional[Dict[str, str]]): Basic authorisations
111119
save (bool): Whether to save state for testing. Defaults to False.
112120
use_saved (bool): Whether to use saved state for testing. Defaults to False.
121+
debug (bool): Whether to output debug info. Defaults to False.
113122
114123
Returns:
115124
None
@@ -156,6 +165,8 @@ def main(
156165
)
157166
pipelines.run()
158167
pipelines.output()
168+
if debug:
169+
pipelines.debug("debug")
159170
logger.info("HAPI pipelines completed!")
160171

161172

@@ -233,4 +244,5 @@ def main(
233244
basic_auths=basic_auths,
234245
save=args.save,
235246
use_saved=args.use_saved,
247+
debug=args.debug,
236248
)

src/hapi/pipelines/app/pipelines.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def __init__(
9696
errors_on_exit=errors_on_exit,
9797
scrapers_to_run=scrapers_to_run,
9898
)
99-
self.configurable_scrapers = dict()
99+
self.configurable_scrapers = {}
100100
self.create_configurable_scrapers()
101101
self.metadata = Metadata(
102102
runner=self.runner, session=session, today=today
@@ -333,3 +333,6 @@ def output(self):
333333
self.wfp_commodity.populate()
334334
self.wfp_market.populate()
335335
self.food_price.populate()
336+
337+
def debug(self, folder: str) -> None:
338+
self.org.output_org_map(folder)

src/hapi/pipelines/database/conflict_event.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def populate(self):
103103
batch_populate(conflict_event_rows, self._session, DBConflictEvent)
104104

105105
for dataset, msg in self._config.get(
106-
"conflict_event_error_messages", dict()
106+
"conflict_event_error_messages", {}
107107
).items():
108108
add_message(errors, dataset, msg)
109109
for error in sorted(errors):

0 commit comments

Comments
 (0)