hapi-schema 0.8.17__tar.gz → 0.9.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/.config/pre-commit-config.yaml +2 -2
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/PKG-INFO +1 -1
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/changelog.md +28 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/requirements.txt +12 -12
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/_version.py +2 -2
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_conflict_event.py +3 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_food_price.py +2 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_food_security.py +3 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_funding.py +4 -5
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_humanitarian_needs.py +2 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_idps.py +4 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_national_risk.py +4 -5
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_operational_presence.py +2 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_population.py +2 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_poverty_rate.py +5 -6
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_refugees.py +4 -5
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_returnees.py +4 -5
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_views_as_tables.py +45 -3
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_wfp_market.py +6 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/utils/enums.py +1 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/views.py +9 -4
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_conflict_event.py +4 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_food_security.py +6 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_humanitarian_needs.py +8 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_idps.py +2 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_operational_presence.py +10 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_population.py +8 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_poverty_rate.py +2 -2
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_wfp_market.py +2 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_conflict_event.py +5 -1
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_food_price.py +3 -1
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_food_security.py +7 -1
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_funding.py +3 -4
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_humanitarian_needs.py +7 -1
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_idps.py +5 -1
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_national_risk.py +3 -4
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_operational_presence.py +5 -1
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_population.py +5 -1
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_poverty_rate.py +3 -4
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_refugees.py +3 -4
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_returnees.py +3 -4
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_views_as_tables.py +23 -4
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_wfp_market.py +4 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/.config/coveragerc +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/.config/pytest.ini +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/.config/ruff.toml +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/.github/workflows/publish.yaml +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/.github/workflows/run-python-tests.yaml +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/.gitignore +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/LICENSE +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/README.md +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/contributing.md +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/docker/docker-compose.yml +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/initialize_test_db.sh +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/pyproject.toml +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/__init__.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_admin1.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_admin2.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_currency.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_dataset.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_location.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_org.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_org_type.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_patch.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_resource.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_sector.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/db_wfp_commodity.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/utils/__init__.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/utils/base.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/utils/constraints.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/utils/hapi_views_code_generator.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/utils/view_as_table_code_generator.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/utils/view_as_table_definitions.toml +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/src/hapi_schema/utils/view_params.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/conftest.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/__init__.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_admin1.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_admin2.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_currency.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_dataset.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_food_price.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_funding.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_location.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_national_risk.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_org.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_org_type.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_patch.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_refugees.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_resource.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_returnees.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_sector.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/sample_data/data_wfp_commodity.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_admin1.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_admin2.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_currency.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_dataset.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_location.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_org.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_org_type.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_patch.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_resource.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_sector.py +0 -0
- {hapi_schema-0.8.17 → hapi_schema-0.9.1}/tests/test_wfp_commodity.py +0 -0
|
@@ -8,7 +8,7 @@ repos:
|
|
|
8
8
|
- id: end-of-file-fixer
|
|
9
9
|
- id: check-ast
|
|
10
10
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
11
|
-
rev: v0.
|
|
11
|
+
rev: v0.6.9
|
|
12
12
|
hooks:
|
|
13
13
|
# Run the linter.
|
|
14
14
|
- id: ruff
|
|
@@ -17,7 +17,7 @@ repos:
|
|
|
17
17
|
- id: ruff-format
|
|
18
18
|
args: [--config, .config/ruff.toml]
|
|
19
19
|
- repo: https://github.com/astral-sh/uv-pre-commit
|
|
20
|
-
rev: 0.
|
|
20
|
+
rev: 0.4.18
|
|
21
21
|
hooks:
|
|
22
22
|
# Run the pip compile
|
|
23
23
|
- id: pip-compile
|
|
@@ -5,6 +5,34 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## 0.9.1
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Return views from prepare_hapi_views call
|
|
13
|
+
|
|
14
|
+
## 0.9.0
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- major refactoring to allow partial/incremental standardisation of
|
|
19
|
+
subnational geocodes. Added `provider_admin1_name` and
|
|
20
|
+
`provider_admin2_name` to the primary keys of subcategory tables
|
|
21
|
+
(except `food_price`), as appropriate.
|
|
22
|
+
- added `provider_admin1_name` and `provider_admin2_name` to `idps`,
|
|
23
|
+
`humanitarian_needs`, `operational_presence`, `conflict_event`,
|
|
24
|
+
`food_security`, `population`, and `wfp_market` (and associated views,
|
|
25
|
+
VATS, and tests)
|
|
26
|
+
- renamed existing column `admin1_name` to `provider_admin1_name` in
|
|
27
|
+
`povert\_rate` for consistency (and updated tests and VAT)
|
|
28
|
+
- updated `food_price_view` and VAT to include `provider_admin1_name` and `provider_admin2_name` from `wfp_market`
|
|
29
|
+
- updated `poverty_rate_view` and VAT to include `admin1_name` from `admin1` table
|
|
30
|
+
- made `reference_period_start` part of the primary key for `population_vat` (originally omitted in error)
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
|
|
34
|
+
- added "Producer" to the `PriceType` enum
|
|
35
|
+
|
|
8
36
|
## 0.8.17
|
|
9
37
|
|
|
10
38
|
### Added
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
# uv pip compile pyproject.toml --resolver=backtracking --all-extras -o requirements.txt
|
|
3
3
|
cfgv==3.4.0
|
|
4
4
|
# via pre-commit
|
|
5
|
-
coverage==7.6.
|
|
5
|
+
coverage==7.6.3
|
|
6
6
|
# via pytest-cov
|
|
7
|
-
distlib==0.3.
|
|
7
|
+
distlib==0.3.9
|
|
8
8
|
# via virtualenv
|
|
9
|
-
filelock==3.
|
|
9
|
+
filelock==3.16.1
|
|
10
10
|
# via virtualenv
|
|
11
|
-
greenlet==3.
|
|
11
|
+
greenlet==3.1.1
|
|
12
12
|
# via sqlalchemy
|
|
13
13
|
hdx-python-database==1.3.3
|
|
14
14
|
# via hapi-schema (pyproject.toml)
|
|
15
|
-
identify==2.6.
|
|
15
|
+
identify==2.6.1
|
|
16
16
|
# via pre-commit
|
|
17
17
|
iniconfig==2.0.0
|
|
18
18
|
# via pytest
|
|
@@ -20,17 +20,17 @@ nodeenv==1.9.1
|
|
|
20
20
|
# via pre-commit
|
|
21
21
|
packaging==24.1
|
|
22
22
|
# via pytest
|
|
23
|
-
platformdirs==4.
|
|
23
|
+
platformdirs==4.3.6
|
|
24
24
|
# via virtualenv
|
|
25
25
|
pluggy==1.5.0
|
|
26
26
|
# via pytest
|
|
27
|
-
pre-commit==
|
|
27
|
+
pre-commit==4.0.1
|
|
28
28
|
# via hapi-schema (pyproject.toml)
|
|
29
|
-
psycopg==3.2.
|
|
29
|
+
psycopg==3.2.3
|
|
30
30
|
# via hapi-schema (pyproject.toml)
|
|
31
|
-
psycopg-binary==3.2.
|
|
31
|
+
psycopg-binary==3.2.3
|
|
32
32
|
# via psycopg
|
|
33
|
-
pytest==8.3.
|
|
33
|
+
pytest==8.3.3
|
|
34
34
|
# via
|
|
35
35
|
# hapi-schema (pyproject.toml)
|
|
36
36
|
# pytest-cov
|
|
@@ -38,7 +38,7 @@ pytest-cov==5.0.0
|
|
|
38
38
|
# via hapi-schema (pyproject.toml)
|
|
39
39
|
pyyaml==6.0.2
|
|
40
40
|
# via pre-commit
|
|
41
|
-
sqlalchemy==2.0.
|
|
41
|
+
sqlalchemy==2.0.35
|
|
42
42
|
# via
|
|
43
43
|
# hapi-schema (pyproject.toml)
|
|
44
44
|
# hdx-python-database
|
|
@@ -46,5 +46,5 @@ typing-extensions==4.12.2
|
|
|
46
46
|
# via
|
|
47
47
|
# psycopg
|
|
48
48
|
# sqlalchemy
|
|
49
|
-
virtualenv==20.26.
|
|
49
|
+
virtualenv==20.26.6
|
|
50
50
|
# via pre-commit
|
|
@@ -5,6 +5,7 @@ from datetime import datetime
|
|
|
5
5
|
from sqlalchemy import (
|
|
6
6
|
ForeignKey,
|
|
7
7
|
Integer,
|
|
8
|
+
String,
|
|
8
9
|
select,
|
|
9
10
|
)
|
|
10
11
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
@@ -42,6 +43,8 @@ class DBConflictEvent(Base):
|
|
|
42
43
|
nullable=False,
|
|
43
44
|
primary_key=True,
|
|
44
45
|
)
|
|
46
|
+
provider_admin1_name = mapped_column(String(512), primary_key=True)
|
|
47
|
+
provider_admin2_name = mapped_column(String(512), primary_key=True)
|
|
45
48
|
event_type: Mapped[EventType] = mapped_column(
|
|
46
49
|
build_enum_using_values(EventType), nullable=False, primary_key=True
|
|
47
50
|
)
|
|
@@ -81,6 +81,8 @@ view_params_food_price = ViewParams(
|
|
|
81
81
|
selectable=select(
|
|
82
82
|
*DBFoodPrice.__table__.columns,
|
|
83
83
|
DBWFPMarket.admin2_ref.label("admin2_ref"),
|
|
84
|
+
DBWFPMarket.provider_admin1_name.label("provider_admin1_name"),
|
|
85
|
+
DBWFPMarket.provider_admin2_name.label("provider_admin2_name"),
|
|
84
86
|
DBWFPMarket.name.label("market_name"),
|
|
85
87
|
DBWFPMarket.lat.label("lat"),
|
|
86
88
|
DBWFPMarket.lon.label("lon"),
|
|
@@ -7,6 +7,7 @@ from sqlalchemy import (
|
|
|
7
7
|
Float,
|
|
8
8
|
ForeignKey,
|
|
9
9
|
Integer,
|
|
10
|
+
String,
|
|
10
11
|
select,
|
|
11
12
|
)
|
|
12
13
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
@@ -39,6 +40,8 @@ class DBFoodSecurity(Base):
|
|
|
39
40
|
admin2_ref: Mapped[int] = mapped_column(
|
|
40
41
|
ForeignKey("admin2.id", onupdate="CASCADE"), primary_key=True
|
|
41
42
|
)
|
|
43
|
+
provider_admin1_name = mapped_column(String(512), primary_key=True)
|
|
44
|
+
provider_admin2_name = mapped_column(String(512), primary_key=True)
|
|
42
45
|
ipc_phase: Mapped[IPCPhase] = mapped_column(
|
|
43
46
|
build_enum_using_values(IPCPhase), primary_key=True
|
|
44
47
|
)
|
|
@@ -11,7 +11,6 @@ from sqlalchemy import (
|
|
|
11
11
|
text,
|
|
12
12
|
)
|
|
13
13
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
14
|
-
from sqlalchemy.sql import null
|
|
15
14
|
from sqlalchemy.sql.expression import literal
|
|
16
15
|
|
|
17
16
|
from hapi_schema.db_location import DBLocation
|
|
@@ -104,10 +103,10 @@ availability_stmt_funding = (
|
|
|
104
103
|
literal("funding").label("subcategory"),
|
|
105
104
|
DBLocation.name.label("location_name"),
|
|
106
105
|
DBLocation.code.label("location_code"),
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
literal("").label("admin1_name"),
|
|
107
|
+
literal("").label("admin1_code"),
|
|
108
|
+
literal("").label("admin2_name"),
|
|
109
|
+
literal("").label("admin2_code"),
|
|
111
110
|
DBResource.hapi_updated_date,
|
|
112
111
|
)
|
|
113
112
|
.select_from(
|
|
@@ -50,6 +50,8 @@ class DBHumanitarianNeeds(Base):
|
|
|
50
50
|
ForeignKey("admin2.id", onupdate="CASCADE"),
|
|
51
51
|
primary_key=True,
|
|
52
52
|
)
|
|
53
|
+
provider_admin1_name = mapped_column(String(512), primary_key=True)
|
|
54
|
+
provider_admin2_name = mapped_column(String(512), primary_key=True)
|
|
53
55
|
gender: Mapped[Gender] = mapped_column(
|
|
54
56
|
build_enum_using_values(Gender), primary_key=True
|
|
55
57
|
)
|
|
@@ -43,6 +43,10 @@ class DBIDPs(Base):
|
|
|
43
43
|
ForeignKey("admin2.id", onupdate="CASCADE"), primary_key=True
|
|
44
44
|
)
|
|
45
45
|
|
|
46
|
+
provider_admin1_name = mapped_column(String(512), primary_key=True)
|
|
47
|
+
|
|
48
|
+
provider_admin2_name = mapped_column(String(512), primary_key=True)
|
|
49
|
+
|
|
46
50
|
assessment_type: Mapped[DTMAssessmentType] = mapped_column(
|
|
47
51
|
build_enum_using_values(DTMAssessmentType), primary_key=True
|
|
48
52
|
)
|
|
@@ -11,7 +11,6 @@ from sqlalchemy import (
|
|
|
11
11
|
select,
|
|
12
12
|
)
|
|
13
13
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
14
|
-
from sqlalchemy.sql import null
|
|
15
14
|
from sqlalchemy.sql.expression import literal
|
|
16
15
|
|
|
17
16
|
from hapi_schema.db_location import DBLocation
|
|
@@ -107,10 +106,10 @@ availability_stmt_national_risk = (
|
|
|
107
106
|
literal("national-risk").label("subcategory"),
|
|
108
107
|
DBLocation.name.label("location_name"),
|
|
109
108
|
DBLocation.code.label("location_code"),
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
109
|
+
literal("").label("admin1_name"),
|
|
110
|
+
literal("").label("admin1_code"),
|
|
111
|
+
literal("").label("admin2_name"),
|
|
112
|
+
literal("").label("admin2_code"),
|
|
114
113
|
DBResource.hapi_updated_date,
|
|
115
114
|
)
|
|
116
115
|
.select_from(
|
|
@@ -42,6 +42,8 @@ class DBOperationalPresence(Base):
|
|
|
42
42
|
admin2_ref: Mapped[int] = mapped_column(
|
|
43
43
|
ForeignKey("admin2.id", onupdate="CASCADE"), primary_key=True
|
|
44
44
|
)
|
|
45
|
+
provider_admin1_name = mapped_column(String(512), primary_key=True)
|
|
46
|
+
provider_admin2_name = mapped_column(String(512), primary_key=True)
|
|
45
47
|
# Foreign key
|
|
46
48
|
org_acronym: Mapped[str] = mapped_column(String, primary_key=True)
|
|
47
49
|
# Foreign key
|
|
@@ -43,6 +43,8 @@ class DBPopulation(Base):
|
|
|
43
43
|
ForeignKey("admin2.id", onupdate="CASCADE"),
|
|
44
44
|
primary_key=True,
|
|
45
45
|
)
|
|
46
|
+
provider_admin1_name = mapped_column(String(512), primary_key=True)
|
|
47
|
+
provider_admin2_name = mapped_column(String(512), primary_key=True)
|
|
46
48
|
gender: Mapped[Gender] = mapped_column(
|
|
47
49
|
build_enum_using_values(Gender), primary_key=True
|
|
48
50
|
)
|
|
@@ -10,7 +10,6 @@ from sqlalchemy import (
|
|
|
10
10
|
)
|
|
11
11
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
12
12
|
from sqlalchemy.schema import CheckConstraint
|
|
13
|
-
from sqlalchemy.sql import null
|
|
14
13
|
from sqlalchemy.sql.expression import literal
|
|
15
14
|
|
|
16
15
|
from hapi_schema.db_admin1 import DBAdmin1
|
|
@@ -48,8 +47,7 @@ class DBPovertyRate(Base):
|
|
|
48
47
|
nullable=False,
|
|
49
48
|
primary_key=True,
|
|
50
49
|
)
|
|
51
|
-
|
|
52
|
-
admin1_name: Mapped[str] = mapped_column(
|
|
50
|
+
provider_admin1_name: Mapped[str] = mapped_column(
|
|
53
51
|
String(512), nullable=False, index=True, primary_key=True
|
|
54
52
|
)
|
|
55
53
|
mpi: Mapped[float] = mapped_column(Float, nullable=False, index=False)
|
|
@@ -84,6 +82,7 @@ view_params_poverty_rate = ViewParams(
|
|
|
84
82
|
DBLocation.name.label("location_name"),
|
|
85
83
|
DBLocation.has_hrp.label("has_hrp"),
|
|
86
84
|
DBLocation.in_gho.label("in_gho"),
|
|
85
|
+
DBAdmin1.name.label("admin1_name"),
|
|
87
86
|
DBAdmin1.code.label("admin1_code"),
|
|
88
87
|
DBAdmin1.is_unspecified.label("admin1_is_unspecified"),
|
|
89
88
|
DBAdmin1.location_ref.label("location_ref"),
|
|
@@ -108,10 +107,10 @@ availability_stmt_poverty_rate = (
|
|
|
108
107
|
literal("poverty-rate").label("subcategory"),
|
|
109
108
|
DBLocation.name.label("location_name"),
|
|
110
109
|
DBLocation.code.label("location_code"),
|
|
111
|
-
|
|
110
|
+
DBAdmin1.name.label("admin1_name"),
|
|
112
111
|
DBAdmin1.code.label("admin1_code"),
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
literal("").label("admin2_name"),
|
|
113
|
+
literal("").label("admin2_code"),
|
|
115
114
|
DBResource.hapi_updated_date,
|
|
116
115
|
)
|
|
117
116
|
.select_from(
|
|
@@ -12,7 +12,6 @@ from sqlalchemy import (
|
|
|
12
12
|
select,
|
|
13
13
|
)
|
|
14
14
|
from sqlalchemy.orm import Mapped, aliased, mapped_column, relationship
|
|
15
|
-
from sqlalchemy.sql import null
|
|
16
15
|
from sqlalchemy.sql.expression import literal
|
|
17
16
|
|
|
18
17
|
from hapi_schema.db_location import DBLocation
|
|
@@ -117,10 +116,10 @@ availability_stmt_refugees = (
|
|
|
117
116
|
literal("refugees").label("subcategory"),
|
|
118
117
|
DBLocation.name.label("location_name"),
|
|
119
118
|
DBLocation.code.label("location_code"),
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
literal("").label("admin1_name"),
|
|
120
|
+
literal("").label("admin1_code"),
|
|
121
|
+
literal("").label("admin2_name"),
|
|
122
|
+
literal("").label("admin2_code"),
|
|
124
123
|
DBResource.hapi_updated_date,
|
|
125
124
|
)
|
|
126
125
|
.select_from(
|
|
@@ -13,7 +13,6 @@ from sqlalchemy import (
|
|
|
13
13
|
select,
|
|
14
14
|
)
|
|
15
15
|
from sqlalchemy.orm import Mapped, aliased, mapped_column, relationship
|
|
16
|
-
from sqlalchemy.sql import null
|
|
17
16
|
from sqlalchemy.sql.expression import literal
|
|
18
17
|
|
|
19
18
|
from hapi_schema.db_location import DBLocation
|
|
@@ -120,10 +119,10 @@ availability_stmt_returnees = (
|
|
|
120
119
|
literal("returnees").label("subcategory"),
|
|
121
120
|
DBLocation.name.label("location_name"),
|
|
122
121
|
DBLocation.code.label("location_code"),
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
122
|
+
literal("").label("admin1_name"),
|
|
123
|
+
literal("").label("admin1_code"),
|
|
124
|
+
literal("").label("admin2_name"),
|
|
125
|
+
literal("").label("admin2_code"),
|
|
127
126
|
DBResource.hapi_updated_date,
|
|
128
127
|
)
|
|
129
128
|
.select_from(
|
|
@@ -79,6 +79,12 @@ class DBConflictEventVAT(Base):
|
|
|
79
79
|
__tablename__ = "conflict_event_vat"
|
|
80
80
|
resource_hdx_id: Mapped[str] = mapped_column(String(36))
|
|
81
81
|
admin2_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
82
|
+
provider_admin1_name: Mapped[str] = mapped_column(
|
|
83
|
+
String(512), primary_key=True
|
|
84
|
+
)
|
|
85
|
+
provider_admin2_name: Mapped[str] = mapped_column(
|
|
86
|
+
String(512), primary_key=True
|
|
87
|
+
)
|
|
82
88
|
event_type: Mapped[EventType] = mapped_column(
|
|
83
89
|
build_enum_using_values(EventType), primary_key=True
|
|
84
90
|
)
|
|
@@ -148,6 +154,8 @@ class DBFoodPriceVAT(Base):
|
|
|
148
154
|
nullable=True,
|
|
149
155
|
)
|
|
150
156
|
admin2_ref: Mapped[int] = mapped_column(Integer)
|
|
157
|
+
provider_admin1_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
158
|
+
provider_admin2_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
151
159
|
market_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
152
160
|
lat: Mapped[float] = mapped_column(Float, index=True)
|
|
153
161
|
lon: Mapped[float] = mapped_column(Float, index=True)
|
|
@@ -173,6 +181,12 @@ class DBFoodSecurityVAT(Base):
|
|
|
173
181
|
__tablename__ = "food_security_vat"
|
|
174
182
|
resource_hdx_id: Mapped[str] = mapped_column(String(36))
|
|
175
183
|
admin2_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
184
|
+
provider_admin1_name: Mapped[str] = mapped_column(
|
|
185
|
+
String(512), primary_key=True
|
|
186
|
+
)
|
|
187
|
+
provider_admin2_name: Mapped[str] = mapped_column(
|
|
188
|
+
String(512), primary_key=True
|
|
189
|
+
)
|
|
176
190
|
ipc_phase: Mapped[IPCPhase] = mapped_column(
|
|
177
191
|
build_enum_using_values(IPCPhase), primary_key=True
|
|
178
192
|
)
|
|
@@ -230,6 +244,12 @@ class DBHumanitarianNeedsVAT(Base):
|
|
|
230
244
|
__tablename__ = "humanitarian_needs_vat"
|
|
231
245
|
resource_hdx_id: Mapped[str] = mapped_column(String(36))
|
|
232
246
|
admin2_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
247
|
+
provider_admin1_name: Mapped[str] = mapped_column(
|
|
248
|
+
String(512), primary_key=True
|
|
249
|
+
)
|
|
250
|
+
provider_admin2_name: Mapped[str] = mapped_column(
|
|
251
|
+
String(512), primary_key=True
|
|
252
|
+
)
|
|
233
253
|
gender: Mapped[Gender] = mapped_column(
|
|
234
254
|
build_enum_using_values(Gender), primary_key=True
|
|
235
255
|
)
|
|
@@ -274,6 +294,12 @@ class DBIDPsVAT(Base):
|
|
|
274
294
|
__tablename__ = "idps_vat"
|
|
275
295
|
resource_hdx_id: Mapped[str] = mapped_column(String(36))
|
|
276
296
|
admin2_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
297
|
+
provider_admin1_name: Mapped[str] = mapped_column(
|
|
298
|
+
String(512), primary_key=True
|
|
299
|
+
)
|
|
300
|
+
provider_admin2_name: Mapped[str] = mapped_column(
|
|
301
|
+
String(512), primary_key=True
|
|
302
|
+
)
|
|
277
303
|
assessment_type: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
278
304
|
reporting_round: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
279
305
|
operation: Mapped[str] = mapped_column(String, primary_key=True)
|
|
@@ -350,6 +376,12 @@ class DBOperationalPresenceVAT(Base):
|
|
|
350
376
|
__tablename__ = "operational_presence_vat"
|
|
351
377
|
resource_hdx_id: Mapped[str] = mapped_column(String(36))
|
|
352
378
|
admin2_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
379
|
+
provider_admin1_name: Mapped[str] = mapped_column(
|
|
380
|
+
String(512), primary_key=True
|
|
381
|
+
)
|
|
382
|
+
provider_admin2_name: Mapped[str] = mapped_column(
|
|
383
|
+
String(512), primary_key=True
|
|
384
|
+
)
|
|
353
385
|
org_acronym: Mapped[str] = mapped_column(String, primary_key=True)
|
|
354
386
|
org_name: Mapped[str] = mapped_column(String, primary_key=True)
|
|
355
387
|
sector_code: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
@@ -398,6 +430,12 @@ class DBPopulationVAT(Base):
|
|
|
398
430
|
__tablename__ = "population_vat"
|
|
399
431
|
resource_hdx_id: Mapped[str] = mapped_column(String(36))
|
|
400
432
|
admin2_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
433
|
+
provider_admin1_name: Mapped[str] = mapped_column(
|
|
434
|
+
String(512), primary_key=True
|
|
435
|
+
)
|
|
436
|
+
provider_admin2_name: Mapped[str] = mapped_column(
|
|
437
|
+
String(512), primary_key=True
|
|
438
|
+
)
|
|
401
439
|
gender: Mapped[Gender] = mapped_column(
|
|
402
440
|
build_enum_using_values(Gender), primary_key=True
|
|
403
441
|
)
|
|
@@ -406,7 +444,7 @@ class DBPopulationVAT(Base):
|
|
|
406
444
|
max_age: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
|
|
407
445
|
population: Mapped[int] = mapped_column(Integer, index=True)
|
|
408
446
|
reference_period_start: Mapped[datetime] = mapped_column(
|
|
409
|
-
DateTime,
|
|
447
|
+
DateTime, primary_key=True
|
|
410
448
|
)
|
|
411
449
|
reference_period_end: Mapped[datetime] = mapped_column(
|
|
412
450
|
DateTime,
|
|
@@ -431,8 +469,9 @@ class DBPovertyRateVAT(Base):
|
|
|
431
469
|
__tablename__ = "poverty_rate_vat"
|
|
432
470
|
resource_hdx_id: Mapped[str] = mapped_column(String(36))
|
|
433
471
|
admin1_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
434
|
-
|
|
435
|
-
String(512),
|
|
472
|
+
provider_admin1_name: Mapped[str] = mapped_column(
|
|
473
|
+
String(512),
|
|
474
|
+
primary_key=True,
|
|
436
475
|
)
|
|
437
476
|
mpi: Mapped[float] = mapped_column(Float)
|
|
438
477
|
headcount_ratio: Mapped[float] = mapped_column(Float)
|
|
@@ -451,6 +490,7 @@ class DBPovertyRateVAT(Base):
|
|
|
451
490
|
location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
452
491
|
has_hrp: Mapped[bool] = mapped_column(Boolean)
|
|
453
492
|
in_gho: Mapped[bool] = mapped_column(Boolean)
|
|
493
|
+
admin1_name: Mapped[str] = mapped_column(String(512))
|
|
454
494
|
admin1_code: Mapped[str] = mapped_column(String(128))
|
|
455
495
|
admin1_is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
456
496
|
location_ref: Mapped[int] = mapped_column(Integer, index=True)
|
|
@@ -565,6 +605,8 @@ class DBWfpMarketVAT(Base):
|
|
|
565
605
|
__tablename__ = "wfp_market_vat"
|
|
566
606
|
code: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
567
607
|
admin2_ref: Mapped[int] = mapped_column(Integer)
|
|
608
|
+
provider_admin1_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
609
|
+
provider_admin2_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
568
610
|
name: Mapped[str] = mapped_column(String(512), index=True)
|
|
569
611
|
lat: Mapped[float] = mapped_column(Float, index=True)
|
|
570
612
|
lon: Mapped[float] = mapped_column(Float, index=True)
|
|
@@ -20,6 +20,12 @@ class DBWFPMarket(Base):
|
|
|
20
20
|
ForeignKey("admin2.id", onupdate="CASCADE"),
|
|
21
21
|
nullable=False,
|
|
22
22
|
)
|
|
23
|
+
provider_admin1_name: Mapped[str] = mapped_column(
|
|
24
|
+
String(512), nullable=False, index=True
|
|
25
|
+
)
|
|
26
|
+
provider_admin2_name: Mapped[str] = mapped_column(
|
|
27
|
+
String(512), nullable=False, index=True
|
|
28
|
+
)
|
|
23
29
|
name: Mapped[str] = mapped_column(String(512), nullable=False, index=True)
|
|
24
30
|
lat: Mapped[float] = mapped_column(Float, nullable=False, index=True)
|
|
25
31
|
lon: Mapped[float] = mapped_column(Float, nullable=False, index=True)
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import inspect
|
|
2
2
|
import os
|
|
3
3
|
from importlib import import_module
|
|
4
|
+
from typing import Dict
|
|
4
5
|
|
|
6
|
+
from sqlalchemy import TableClause
|
|
5
7
|
from sqlalchemy.sql.expression import union_all
|
|
6
8
|
|
|
7
9
|
from hapi_schema.utils.base import Base
|
|
@@ -14,7 +16,7 @@ except ImportError:
|
|
|
14
16
|
pass
|
|
15
17
|
|
|
16
18
|
|
|
17
|
-
def prepare_hapi_views():
|
|
19
|
+
def prepare_hapi_views() -> Dict[str, TableClause]:
|
|
18
20
|
# Programmatically get views and prepare them for creation.
|
|
19
21
|
# Views must be in files with filename of form: db_{name}.py in the same
|
|
20
22
|
# directory. Views must be named like this: view_params_{name}.
|
|
@@ -22,6 +24,7 @@ def prepare_hapi_views():
|
|
|
22
24
|
path = inspect.getabsfile(prepare_hapi_views)
|
|
23
25
|
dirpath, _ = os.path.split(path)
|
|
24
26
|
availability_stmts = []
|
|
27
|
+
views = {}
|
|
25
28
|
for path in os.listdir(dirpath):
|
|
26
29
|
if os.path.isdir(path):
|
|
27
30
|
continue
|
|
@@ -32,7 +35,7 @@ def prepare_hapi_views():
|
|
|
32
35
|
table = filename[3:]
|
|
33
36
|
try:
|
|
34
37
|
view_params = getattr(module, f"view_params_{table}")
|
|
35
|
-
Database.prepare_view(view_params.__dict__)
|
|
38
|
+
views[table] = Database.prepare_view(view_params.__dict__)
|
|
36
39
|
availability_stmt = getattr(
|
|
37
40
|
module, f"availability_stmt_{table}"
|
|
38
41
|
)
|
|
@@ -48,5 +51,7 @@ def prepare_hapi_views():
|
|
|
48
51
|
selectable=union_all(*availability_stmts),
|
|
49
52
|
)
|
|
50
53
|
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
views["data_availability"] = Database.prepare_view(
|
|
55
|
+
view_params_availability.__dict__
|
|
56
|
+
)
|
|
57
|
+
return views
|
|
@@ -4,6 +4,8 @@ data_conflict_event = [
|
|
|
4
4
|
dict(
|
|
5
5
|
resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
|
|
6
6
|
admin2_ref=4,
|
|
7
|
+
provider_admin1_name="Provincia 01",
|
|
8
|
+
provider_admin2_name="Distrito A",
|
|
7
9
|
event_type="political_violence",
|
|
8
10
|
events=10,
|
|
9
11
|
fatalities=2,
|
|
@@ -13,6 +15,8 @@ data_conflict_event = [
|
|
|
13
15
|
dict(
|
|
14
16
|
resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
|
|
15
17
|
admin2_ref=1,
|
|
18
|
+
provider_admin1_name="Provincia 01",
|
|
19
|
+
provider_admin2_name="Distrito A",
|
|
16
20
|
event_type="civilian_targeting",
|
|
17
21
|
events=3,
|
|
18
22
|
fatalities=0,
|
|
@@ -5,6 +5,8 @@ data_food_security = [
|
|
|
5
5
|
dict(
|
|
6
6
|
resource_hdx_id="62ad6e55-5f5d-4494-854c-4110687e9e25",
|
|
7
7
|
admin2_ref=1,
|
|
8
|
+
provider_admin1_name="Provincia 01",
|
|
9
|
+
provider_admin2_name="Distrito A",
|
|
8
10
|
ipc_phase="1",
|
|
9
11
|
ipc_type="current",
|
|
10
12
|
population_in_phase=500_000,
|
|
@@ -16,6 +18,8 @@ data_food_security = [
|
|
|
16
18
|
dict(
|
|
17
19
|
resource_hdx_id="62ad6e55-5f5d-4494-854c-4110687e9e25",
|
|
18
20
|
admin2_ref=2,
|
|
21
|
+
provider_admin1_name="Provincia 01",
|
|
22
|
+
provider_admin2_name="Distrito A",
|
|
19
23
|
ipc_phase="2",
|
|
20
24
|
ipc_type="first projection",
|
|
21
25
|
population_in_phase=40_000,
|
|
@@ -27,6 +31,8 @@ data_food_security = [
|
|
|
27
31
|
dict(
|
|
28
32
|
resource_hdx_id="62ad6e55-5f5d-4494-854c-4110687e9e25",
|
|
29
33
|
admin2_ref=4,
|
|
34
|
+
provider_admin1_name="Provincia 01",
|
|
35
|
+
provider_admin2_name="Distrito A",
|
|
30
36
|
ipc_phase="3",
|
|
31
37
|
ipc_type="second projection",
|
|
32
38
|
population_in_phase=3_000,
|
|
@@ -5,6 +5,8 @@ data_humanitarian_needs = [
|
|
|
5
5
|
dict(
|
|
6
6
|
resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
|
|
7
7
|
admin2_ref=1,
|
|
8
|
+
provider_admin1_name="Provincia 01",
|
|
9
|
+
provider_admin2_name="Distrito B",
|
|
8
10
|
gender="all",
|
|
9
11
|
age_range="all",
|
|
10
12
|
disabled_marker="all",
|
|
@@ -19,6 +21,8 @@ data_humanitarian_needs = [
|
|
|
19
21
|
dict(
|
|
20
22
|
resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
|
|
21
23
|
admin2_ref=1,
|
|
24
|
+
provider_admin1_name="Provincia 01",
|
|
25
|
+
provider_admin2_name="Distrito B",
|
|
22
26
|
gender="f",
|
|
23
27
|
age_range="all",
|
|
24
28
|
disabled_marker="n",
|
|
@@ -33,6 +37,8 @@ data_humanitarian_needs = [
|
|
|
33
37
|
dict(
|
|
34
38
|
resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
|
|
35
39
|
admin2_ref=2,
|
|
40
|
+
provider_admin1_name="Provincia 01",
|
|
41
|
+
provider_admin2_name="Distrito B",
|
|
36
42
|
gender="f",
|
|
37
43
|
age_range="0-4",
|
|
38
44
|
min_age=0,
|
|
@@ -49,6 +55,8 @@ data_humanitarian_needs = [
|
|
|
49
55
|
dict(
|
|
50
56
|
resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
|
|
51
57
|
admin2_ref=4,
|
|
58
|
+
provider_admin1_name="Provincia 03",
|
|
59
|
+
provider_admin2_name="Distrito D",
|
|
52
60
|
gender="all",
|
|
53
61
|
age_range="80+",
|
|
54
62
|
min_age=80,
|