hapi-schema 0.8.4__tar.gz → 0.8.6__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.4 → hapi_schema-0.8.6}/PKG-INFO +1 -1
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/changelog.md +22 -3
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/docker/docker-compose.yml +0 -1
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/_version.py +2 -2
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_operational_presence.py +8 -1
- hapi_schema-0.8.6/src/hapi_schema/db_poverty_rate.py +101 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_views_as_tables.py +129 -16
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/utils/constraints.py +2 -5
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/utils/enums.py +0 -6
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/utils/hapi_views_code_generator.py +3 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/utils/view_as_table_code_generator.py +3 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/utils/view_as_table_definitions.toml +71 -1
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_poverty_rate.py +6 -3
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_operational_presence.py +2 -0
- hapi_schema-0.8.6/tests/test_poverty_rate.py +112 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_views_as_tables.py +139 -0
- hapi_schema-0.8.4/src/hapi_schema/db_poverty_rate.py +0 -76
- hapi_schema-0.8.4/tests/test_poverty_rate.py +0 -65
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/.config/coveragerc +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/.config/pre-commit-config.yaml +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/.config/pytest.ini +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/.config/ruff.toml +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/.github/workflows/publish.yaml +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/.github/workflows/run-python-tests.yaml +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/.gitignore +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/LICENSE +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/README.md +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/contributing.md +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/initialize_test_db.sh +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/pyproject.toml +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/requirements.txt +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/__init__.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_admin1.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_admin2.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_conflict_event.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_currency.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_dataset.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_food_price.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_food_security.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_funding.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_humanitarian_needs.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_location.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_national_risk.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_org.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_org_type.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_patch.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_population.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_refugees.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_resource.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_sector.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_wfp_commodity.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/db_wfp_market.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/utils/__init__.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/utils/base.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/utils/view_params.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/views.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/conftest.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/__init__.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_admin1.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_admin2.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_conflict_event.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_currency.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_dataset.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_food_price.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_food_security.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_funding.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_humanitarian_needs.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_location.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_national_risk.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_operational_presence.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_org.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_org_type.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_patch.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_population.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_refugees.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_resource.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_sector.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_wfp_commodity.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/sample_data/data_wfp_market.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_admin1.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_admin2.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_conflict_event.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_currency.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_dataset.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_food_price.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_food_security.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_funding.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_humanitarian_needs.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_location.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_national_risk.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_org.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_org_type.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_patch.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_population.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_refugees.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_resource.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_sector.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_wfp_commodity.py +0 -0
- {hapi_schema-0.8.4 → hapi_schema-0.8.6}/tests/test_wfp_market.py +0 -0
|
@@ -5,21 +5,40 @@ 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.8.6
|
|
9
|
+
|
|
10
|
+
## Changes
|
|
11
|
+
- Added food\_price view as tables by updating the toml parameter file
|
|
12
|
+
- Updated poverty\_rate view as table
|
|
13
|
+
- Updated operational\_presence view as table by updating the toml parameter file
|
|
14
|
+
- Made a few adhoc changes to the view as table generator code to accommodate Decimal columns
|
|
15
|
+
|
|
16
|
+
## 0.8.5
|
|
17
|
+
|
|
18
|
+
## Changes
|
|
19
|
+
- refactor DBPovertyRate to wide instead of narrow
|
|
20
|
+
- added org\_type\_description to operational\_presence\_view
|
|
21
|
+
|
|
22
|
+
## Removed
|
|
23
|
+
- rate\_constraint and `PovertyClassification` enum
|
|
24
|
+
|
|
8
25
|
## 0.8.4
|
|
9
26
|
|
|
10
27
|
### Added
|
|
11
28
|
|
|
12
29
|
- New constraints: rate\_constraint
|
|
13
30
|
|
|
14
|
-
###
|
|
31
|
+
### CHanged
|
|
15
32
|
|
|
16
|
-
-
|
|
17
|
-
|
|
33
|
+
- refactor DBPovertyRate to track rates rather than population, and link to
|
|
34
|
+
location (with admin1\_name as a text field)
|
|
18
35
|
|
|
19
36
|
## 0.8.3
|
|
20
37
|
|
|
21
38
|
### Changed
|
|
39
|
+
|
|
22
40
|
- fixed WFP commodity enum
|
|
41
|
+
- remove ALL ("*") from PovertyClassification enum
|
|
23
42
|
- change FLOAT to DECIMAL in funding, national\_risk, and food\_security
|
|
24
43
|
|
|
25
44
|
## 0.8.2
|
|
@@ -15,7 +15,7 @@ from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
15
15
|
from hapi_schema.db_admin1 import DBAdmin1
|
|
16
16
|
from hapi_schema.db_admin2 import DBAdmin2
|
|
17
17
|
from hapi_schema.db_location import DBLocation
|
|
18
|
-
from hapi_schema.db_org import DBOrg
|
|
18
|
+
from hapi_schema.db_org import DBOrg, DBOrgType
|
|
19
19
|
from hapi_schema.db_sector import DBSector
|
|
20
20
|
from hapi_schema.utils.base import Base
|
|
21
21
|
from hapi_schema.utils.constraints import reference_period_constraint
|
|
@@ -66,6 +66,7 @@ view_params_operational_presence = ViewParams(
|
|
|
66
66
|
selectable=select(
|
|
67
67
|
*DBOperationalPresence.__table__.columns,
|
|
68
68
|
DBOrg.org_type_code.label("org_type_code"),
|
|
69
|
+
DBOrgType.description.label("org_type_description"),
|
|
69
70
|
DBSector.name.label("sector_name"),
|
|
70
71
|
DBLocation.code.label("location_code"),
|
|
71
72
|
DBLocation.name.label("location_name"),
|
|
@@ -101,6 +102,12 @@ view_params_operational_presence = ViewParams(
|
|
|
101
102
|
& (DBOperationalPresence.org_acronym == DBOrg.acronym),
|
|
102
103
|
isouter=True,
|
|
103
104
|
)
|
|
105
|
+
# Join org to org_type
|
|
106
|
+
.join(
|
|
107
|
+
DBOrgType.__table__,
|
|
108
|
+
(DBOrg.org_type_code == DBOrgType.code),
|
|
109
|
+
isouter=True,
|
|
110
|
+
)
|
|
104
111
|
# Join op to sector
|
|
105
112
|
.join(
|
|
106
113
|
DBSector.__table__,
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""PovertyRate table and view."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
|
|
5
|
+
from sqlalchemy import (
|
|
6
|
+
DateTime,
|
|
7
|
+
Float,
|
|
8
|
+
ForeignKey,
|
|
9
|
+
String,
|
|
10
|
+
select,
|
|
11
|
+
)
|
|
12
|
+
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
13
|
+
from sqlalchemy.schema import CheckConstraint
|
|
14
|
+
|
|
15
|
+
from hapi_schema.db_admin1 import DBAdmin1
|
|
16
|
+
from hapi_schema.db_location import DBLocation
|
|
17
|
+
from hapi_schema.db_resource import DBResource
|
|
18
|
+
from hapi_schema.utils.base import Base
|
|
19
|
+
from hapi_schema.utils.constraints import (
|
|
20
|
+
percentage_constraint,
|
|
21
|
+
reference_period_constraint,
|
|
22
|
+
)
|
|
23
|
+
from hapi_schema.utils.view_params import ViewParams
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# normalised table
|
|
27
|
+
class DBPovertyRate(Base):
|
|
28
|
+
__tablename__ = "poverty_rate"
|
|
29
|
+
__table_args__ = (
|
|
30
|
+
percentage_constraint(var_name="headcount_ratio"),
|
|
31
|
+
percentage_constraint(var_name="intensity_of_deprivation"),
|
|
32
|
+
percentage_constraint(var_name="vulnerable_to_poverty"),
|
|
33
|
+
percentage_constraint(var_name="in_severe_poverty"),
|
|
34
|
+
reference_period_constraint(),
|
|
35
|
+
CheckConstraint(
|
|
36
|
+
sqltext="ABS(headcount_ratio / 100 * intensity_of_deprivation / 100 - mpi) < 0.00001",
|
|
37
|
+
name="mpi_product",
|
|
38
|
+
),
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
resource_hdx_id: Mapped[str] = mapped_column(
|
|
42
|
+
ForeignKey("resource.hdx_id", onupdate="CASCADE", ondelete="CASCADE"),
|
|
43
|
+
nullable=False,
|
|
44
|
+
)
|
|
45
|
+
admin1_ref: Mapped[int] = mapped_column(
|
|
46
|
+
ForeignKey("admin1.id", onupdate="CASCADE"),
|
|
47
|
+
nullable=False,
|
|
48
|
+
primary_key=True,
|
|
49
|
+
)
|
|
50
|
+
# TODO temporary -- will remove in future release and use name from admin1 table
|
|
51
|
+
admin1_name: Mapped[str] = mapped_column(
|
|
52
|
+
String(512), nullable=False, index=True, primary_key=True
|
|
53
|
+
)
|
|
54
|
+
mpi: Mapped[float] = mapped_column(Float, nullable=False, index=False)
|
|
55
|
+
headcount_ratio: Mapped[float] = mapped_column(
|
|
56
|
+
Float, nullable=False, index=False
|
|
57
|
+
)
|
|
58
|
+
intensity_of_deprivation: Mapped[float] = mapped_column(
|
|
59
|
+
Float, nullable=False, index=False
|
|
60
|
+
)
|
|
61
|
+
vulnerable_to_poverty: Mapped[float] = mapped_column(
|
|
62
|
+
Float, nullable=False, index=False
|
|
63
|
+
)
|
|
64
|
+
in_severe_poverty: Mapped[float] = mapped_column(
|
|
65
|
+
Float, nullable=False, index=False
|
|
66
|
+
)
|
|
67
|
+
reference_period_start: Mapped[datetime] = mapped_column(
|
|
68
|
+
DateTime, primary_key=True
|
|
69
|
+
)
|
|
70
|
+
reference_period_end: Mapped[datetime] = mapped_column(
|
|
71
|
+
DateTime, nullable=False, index=True
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
resource = relationship(DBResource)
|
|
75
|
+
admin1 = relationship(DBAdmin1)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# view
|
|
79
|
+
view_params_poverty_rate = ViewParams(
|
|
80
|
+
name="poverty_rate_view",
|
|
81
|
+
metadata=Base.metadata,
|
|
82
|
+
selectable=select(
|
|
83
|
+
*DBPovertyRate.__table__.columns,
|
|
84
|
+
DBLocation.code.label("location_code"),
|
|
85
|
+
DBLocation.name.label("location_name"),
|
|
86
|
+
DBAdmin1.code.label("admin1_code"),
|
|
87
|
+
DBAdmin1.is_unspecified.label("admin1_is_unspecified"),
|
|
88
|
+
DBAdmin1.location_ref.label("location_ref"),
|
|
89
|
+
).select_from(
|
|
90
|
+
# Join PR to admin1 to loc
|
|
91
|
+
DBPovertyRate.__table__.join(
|
|
92
|
+
DBAdmin1.__table__,
|
|
93
|
+
DBPovertyRate.admin1_ref == DBAdmin1.id,
|
|
94
|
+
isouter=True,
|
|
95
|
+
).join(
|
|
96
|
+
DBLocation.__table__,
|
|
97
|
+
DBAdmin1.location_ref == DBLocation.id,
|
|
98
|
+
isouter=True,
|
|
99
|
+
)
|
|
100
|
+
),
|
|
101
|
+
)
|
|
@@ -52,6 +52,37 @@ class DBAdmin2VAT(Base):
|
|
|
52
52
|
location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
53
53
|
|
|
54
54
|
|
|
55
|
+
class DBConflictEventVAT(Base):
|
|
56
|
+
__tablename__ = "conflict_event_vat"
|
|
57
|
+
resource_hdx_id: Mapped[str] = mapped_column(String(36))
|
|
58
|
+
admin2_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
59
|
+
event_type: Mapped[str] = mapped_column(String(18), primary_key=True)
|
|
60
|
+
events: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
|
|
61
|
+
fatalities: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
|
|
62
|
+
reference_period_start: Mapped[datetime] = mapped_column(
|
|
63
|
+
DateTime, primary_key=True
|
|
64
|
+
)
|
|
65
|
+
reference_period_end: Mapped[datetime] = mapped_column(
|
|
66
|
+
DateTime, index=True
|
|
67
|
+
)
|
|
68
|
+
location_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
69
|
+
location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
70
|
+
admin1_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
71
|
+
admin1_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
72
|
+
admin1_is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
73
|
+
location_ref: Mapped[int] = mapped_column(Integer)
|
|
74
|
+
admin2_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
75
|
+
admin2_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
76
|
+
admin2_is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
77
|
+
admin1_ref: Mapped[int] = mapped_column(Integer)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
class DBCurrencyVAT(Base):
|
|
81
|
+
__tablename__ = "currency_vat"
|
|
82
|
+
code: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
83
|
+
name: Mapped[str] = mapped_column(String(512), index=True)
|
|
84
|
+
|
|
85
|
+
|
|
55
86
|
class DBDatasetVAT(Base):
|
|
56
87
|
__tablename__ = "dataset_vat"
|
|
57
88
|
hdx_id: Mapped[str] = mapped_column(String(36), primary_key=True)
|
|
@@ -61,6 +92,42 @@ class DBDatasetVAT(Base):
|
|
|
61
92
|
hdx_provider_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
62
93
|
|
|
63
94
|
|
|
95
|
+
class DBFoodPriceVAT(Base):
|
|
96
|
+
__tablename__ = "food_price_vat"
|
|
97
|
+
resource_hdx_id: Mapped[str] = mapped_column(String(36))
|
|
98
|
+
market_code: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
99
|
+
commodity_code: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
100
|
+
currency_code: Mapped[str] = mapped_column(String(32), index=True)
|
|
101
|
+
unit: Mapped[str] = mapped_column(String(32))
|
|
102
|
+
price_flag: Mapped[str] = mapped_column(String(16), primary_key=True)
|
|
103
|
+
price_type: Mapped[str] = mapped_column(String(9), primary_key=True)
|
|
104
|
+
price: Mapped[Decimal] = mapped_column()
|
|
105
|
+
reference_period_start: Mapped[datetime] = mapped_column(
|
|
106
|
+
DateTime, primary_key=True
|
|
107
|
+
)
|
|
108
|
+
reference_period_end: Mapped[datetime] = mapped_column(
|
|
109
|
+
DateTime, index=True
|
|
110
|
+
)
|
|
111
|
+
admin2_ref: Mapped[int] = mapped_column(Integer)
|
|
112
|
+
market_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
113
|
+
lat: Mapped[float] = mapped_column(Float, index=True)
|
|
114
|
+
lon: Mapped[float] = mapped_column(Float, index=True)
|
|
115
|
+
commodity_category: Mapped[str] = mapped_column(
|
|
116
|
+
String(18), primary_key=True
|
|
117
|
+
)
|
|
118
|
+
commodity_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
119
|
+
location_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
120
|
+
location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
121
|
+
location_ref: Mapped[int] = mapped_column(Integer)
|
|
122
|
+
admin1_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
123
|
+
admin1_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
124
|
+
admin1_is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
125
|
+
admin1_ref: Mapped[int] = mapped_column(Integer)
|
|
126
|
+
admin2_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
127
|
+
admin2_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
128
|
+
admin2_is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
129
|
+
|
|
130
|
+
|
|
64
131
|
class DBFoodSecurityVAT(Base):
|
|
65
132
|
__tablename__ = "food_security_vat"
|
|
66
133
|
resource_hdx_id: Mapped[str] = mapped_column(String(36))
|
|
@@ -68,9 +135,7 @@ class DBFoodSecurityVAT(Base):
|
|
|
68
135
|
ipc_phase: Mapped[str] = mapped_column(String(12), primary_key=True)
|
|
69
136
|
ipc_type: Mapped[str] = mapped_column(String(17), primary_key=True)
|
|
70
137
|
population_in_phase: Mapped[int] = mapped_column(Integer, index=True)
|
|
71
|
-
population_fraction_in_phase: Mapped[Decimal] = mapped_column(
|
|
72
|
-
Float, index=True
|
|
73
|
-
)
|
|
138
|
+
population_fraction_in_phase: Mapped[Decimal] = mapped_column(index=True)
|
|
74
139
|
reference_period_start: Mapped[datetime] = mapped_column(
|
|
75
140
|
DateTime, primary_key=True
|
|
76
141
|
)
|
|
@@ -96,9 +161,9 @@ class DBFundingVAT(Base):
|
|
|
96
161
|
location_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
97
162
|
appeal_name: Mapped[str] = mapped_column(String(256))
|
|
98
163
|
appeal_type: Mapped[str] = mapped_column(String(32))
|
|
99
|
-
requirements_usd: Mapped[Decimal] = mapped_column(
|
|
100
|
-
funding_usd: Mapped[Decimal] = mapped_column(
|
|
101
|
-
funding_pct: Mapped[Decimal] = mapped_column(
|
|
164
|
+
requirements_usd: Mapped[Decimal] = mapped_column(index=True)
|
|
165
|
+
funding_usd: Mapped[Decimal] = mapped_column(index=True)
|
|
166
|
+
funding_pct: Mapped[Decimal] = mapped_column(index=True)
|
|
102
167
|
reference_period_start: Mapped[datetime] = mapped_column(
|
|
103
168
|
DateTime, index=True
|
|
104
169
|
)
|
|
@@ -163,16 +228,12 @@ class DBNationalRiskVAT(Base):
|
|
|
163
228
|
location_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
164
229
|
risk_class: Mapped[str] = mapped_column(String(9))
|
|
165
230
|
global_rank: Mapped[int] = mapped_column(Integer)
|
|
166
|
-
overall_risk: Mapped[Decimal] = mapped_column(
|
|
167
|
-
hazard_exposure_risk: Mapped[Decimal] = mapped_column(
|
|
168
|
-
vulnerability_risk: Mapped[Decimal] = mapped_column(
|
|
169
|
-
coping_capacity_risk: Mapped[Decimal] = mapped_column(
|
|
170
|
-
meta_missing_indicators_pct: Mapped[Decimal] = mapped_column(
|
|
171
|
-
|
|
172
|
-
)
|
|
173
|
-
meta_avg_recentness_years: Mapped[Decimal] = mapped_column(
|
|
174
|
-
Float, nullable=True
|
|
175
|
-
)
|
|
231
|
+
overall_risk: Mapped[Decimal] = mapped_column()
|
|
232
|
+
hazard_exposure_risk: Mapped[Decimal] = mapped_column()
|
|
233
|
+
vulnerability_risk: Mapped[Decimal] = mapped_column()
|
|
234
|
+
coping_capacity_risk: Mapped[Decimal] = mapped_column()
|
|
235
|
+
meta_missing_indicators_pct: Mapped[Decimal] = mapped_column(nullable=True)
|
|
236
|
+
meta_avg_recentness_years: Mapped[Decimal] = mapped_column(nullable=True)
|
|
176
237
|
reference_period_start: Mapped[datetime] = mapped_column(
|
|
177
238
|
DateTime, primary_key=True
|
|
178
239
|
)
|
|
@@ -197,6 +258,7 @@ class DBOperationalPresenceVAT(Base):
|
|
|
197
258
|
DateTime, index=True
|
|
198
259
|
)
|
|
199
260
|
org_type_code: Mapped[str] = mapped_column(String(32))
|
|
261
|
+
org_type_description: Mapped[str] = mapped_column(String(512), index=True)
|
|
200
262
|
sector_name: Mapped[str] = mapped_column(String(512))
|
|
201
263
|
location_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
202
264
|
location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
@@ -253,6 +315,31 @@ class DBPopulationVAT(Base):
|
|
|
253
315
|
admin1_ref: Mapped[int] = mapped_column(Integer)
|
|
254
316
|
|
|
255
317
|
|
|
318
|
+
class DBPovertyRateVAT(Base):
|
|
319
|
+
__tablename__ = "poverty_rate_vat"
|
|
320
|
+
resource_hdx_id: Mapped[str] = mapped_column(String(36))
|
|
321
|
+
admin1_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
322
|
+
admin1_name: Mapped[str] = mapped_column(
|
|
323
|
+
String(512), primary_key=True, index=True
|
|
324
|
+
)
|
|
325
|
+
mpi: Mapped[float] = mapped_column(Float)
|
|
326
|
+
headcount_ratio: Mapped[float] = mapped_column(Float)
|
|
327
|
+
intensity_of_deprivation: Mapped[float] = mapped_column(Float)
|
|
328
|
+
vulnerable_to_poverty: Mapped[float] = mapped_column(Float)
|
|
329
|
+
in_severe_poverty: Mapped[float] = mapped_column(Float)
|
|
330
|
+
reference_period_start: Mapped[datetime] = mapped_column(
|
|
331
|
+
DateTime, primary_key=True
|
|
332
|
+
)
|
|
333
|
+
reference_period_end: Mapped[datetime] = mapped_column(
|
|
334
|
+
DateTime, index=True
|
|
335
|
+
)
|
|
336
|
+
location_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
337
|
+
location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
338
|
+
admin1_code: Mapped[str] = mapped_column(String(128))
|
|
339
|
+
admin1_is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
340
|
+
location_ref: Mapped[int] = mapped_column(Integer, index=True)
|
|
341
|
+
|
|
342
|
+
|
|
256
343
|
class DBRefugeesVAT(Base):
|
|
257
344
|
__tablename__ = "refugees_vat"
|
|
258
345
|
resource_hdx_id: Mapped[str] = mapped_column(String(36))
|
|
@@ -300,3 +387,29 @@ class DBSectorVAT(Base):
|
|
|
300
387
|
__tablename__ = "sector_vat"
|
|
301
388
|
code: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
302
389
|
name: Mapped[str] = mapped_column(String(512), index=True)
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
class DBWfpCommodityVAT(Base):
|
|
393
|
+
__tablename__ = "wfp_commodity_vat"
|
|
394
|
+
code: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
395
|
+
category: Mapped[str] = mapped_column(String(18), index=True)
|
|
396
|
+
name: Mapped[str] = mapped_column(String(512), index=True)
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
class DBWfpMarketVAT(Base):
|
|
400
|
+
__tablename__ = "wfp_market_vat"
|
|
401
|
+
code: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
402
|
+
admin2_ref: Mapped[int] = mapped_column(Integer)
|
|
403
|
+
name: Mapped[str] = mapped_column(String(512), index=True)
|
|
404
|
+
lat: Mapped[float] = mapped_column(Float, index=True)
|
|
405
|
+
lon: Mapped[float] = mapped_column(Float, index=True)
|
|
406
|
+
location_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
407
|
+
location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
408
|
+
admin1_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
409
|
+
admin1_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
410
|
+
admin1_is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
411
|
+
location_ref: Mapped[int] = mapped_column(Integer)
|
|
412
|
+
admin2_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
413
|
+
admin2_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
414
|
+
admin2_is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
415
|
+
admin1_ref: Mapped[int] = mapped_column(Integer)
|
|
@@ -43,11 +43,8 @@ def non_negative_constraint(
|
|
|
43
43
|
return CheckConstraint(sqltext=sqltext, name=f"{var_name}")
|
|
44
44
|
|
|
45
45
|
|
|
46
|
-
def
|
|
47
|
-
var_name
|
|
48
|
-
) -> CheckConstraint:
|
|
49
|
-
"""Require a column to be between 0.0 and 1.0."""
|
|
50
|
-
sqltext = f"{var_name} >= 0 AND {var_name} <= 1.0"
|
|
46
|
+
def percentage_constraint(var_name: str) -> CheckConstraint:
|
|
47
|
+
sqltext = f"{var_name} >= 0. AND {var_name} <= 100."
|
|
51
48
|
return CheckConstraint(sqltext=sqltext, name=f"{var_name}")
|
|
52
49
|
|
|
53
50
|
|
|
@@ -62,12 +62,6 @@ class PriceType(str, enum.Enum):
|
|
|
62
62
|
WHOLESALE = "Wholesale"
|
|
63
63
|
|
|
64
64
|
|
|
65
|
-
class PovertyClassification(str, enum.Enum):
|
|
66
|
-
POOR = "poor"
|
|
67
|
-
VULNERABLE = "vulnerable"
|
|
68
|
-
EXTREMELY_POOR = "extremely_poor"
|
|
69
|
-
|
|
70
|
-
|
|
71
65
|
class IPCPhase(str, enum.Enum):
|
|
72
66
|
PHASE_1 = "1"
|
|
73
67
|
PHASE_2 = "2"
|
|
@@ -54,6 +54,7 @@ def parse_toml():
|
|
|
54
54
|
complete_code.append('"""')
|
|
55
55
|
|
|
56
56
|
# Make imports
|
|
57
|
+
complete_code.append("from decimal import Decimal")
|
|
57
58
|
complete_code.append("from sqlalchemy import DateTime")
|
|
58
59
|
complete_code.append("from sqlalchemy.orm import column_property, Mapped")
|
|
59
60
|
|
|
@@ -180,6 +181,8 @@ def make_table_template_from_view(
|
|
|
180
181
|
mapped_type_1 = "float"
|
|
181
182
|
elif column_type == "TEXT":
|
|
182
183
|
mapped_type_1 = "str"
|
|
184
|
+
elif column_type == "NUMERIC":
|
|
185
|
+
mapped_type_1 = "Decimal"
|
|
183
186
|
table_code.append(
|
|
184
187
|
f" {column.name}: Mapped[{mapped_type_1}] = column_property({source_view}.c.{column.name})"
|
|
185
188
|
)
|
{hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/utils/view_as_table_code_generator.py
RENAMED
|
@@ -159,6 +159,9 @@ def make_table_template_from_view(
|
|
|
159
159
|
elif column_type in ["FLOAT", "DOUBLE PRECISION"]:
|
|
160
160
|
mapped_type_1 = "float"
|
|
161
161
|
mapped_type_2 = "Float"
|
|
162
|
+
elif column_type in ["NUMERIC"]:
|
|
163
|
+
mapped_type_1 = "Decimal"
|
|
164
|
+
mapped_type_2 = "Float"
|
|
162
165
|
elif column_type == "TEXT":
|
|
163
166
|
mapped_type_1 = "str"
|
|
164
167
|
mapped_type_2 = "Text"
|
{hapi_schema-0.8.4 → hapi_schema-0.8.6}/src/hapi_schema/utils/view_as_table_definitions.toml
RENAMED
|
@@ -16,6 +16,29 @@ expected_indexes = ["code", "name",
|
|
|
16
16
|
"location_code", "location_name"]
|
|
17
17
|
expected_nullables = ["reference_period_start", "reference_period_end"]
|
|
18
18
|
|
|
19
|
+
[[tables]]
|
|
20
|
+
db_module = "db_conflict_event"
|
|
21
|
+
target_view = "conflict_event_view"
|
|
22
|
+
view_params_name="view_params_conflict_event"
|
|
23
|
+
expected_primary_keys = [
|
|
24
|
+
"admin2_ref",
|
|
25
|
+
"event_type",
|
|
26
|
+
"reference_period_start"
|
|
27
|
+
]
|
|
28
|
+
expected_indexes = ["events", "fatalities", "reference_period_end", "location_code",
|
|
29
|
+
"location_name", "admin1_code", "admin1_name", "admin2_code", "admin2_name"]
|
|
30
|
+
expected_nullables = ["events", "fatalities"]
|
|
31
|
+
|
|
32
|
+
[[tables]]
|
|
33
|
+
db_module = "db_currency"
|
|
34
|
+
target_view = "currency_view"
|
|
35
|
+
view_params_name = "view_params_currency"
|
|
36
|
+
expected_primary_keys = [
|
|
37
|
+
"code"
|
|
38
|
+
]
|
|
39
|
+
expected_indexes = ["name"]
|
|
40
|
+
expected_nullables = []
|
|
41
|
+
|
|
19
42
|
[[tables]]
|
|
20
43
|
db_module = "db_dataset"
|
|
21
44
|
target_view = "dataset_view"
|
|
@@ -24,6 +47,17 @@ expected_primary_keys = ["hdx_id"]
|
|
|
24
47
|
expected_indexes = ["hdx_stub", "hdx_provider_stub", "hdx_provider_name"]
|
|
25
48
|
expected_nullables = []
|
|
26
49
|
|
|
50
|
+
[[tables]]
|
|
51
|
+
db_module = "db_food_price"
|
|
52
|
+
target_view = "food_price_view"
|
|
53
|
+
view_params_name = "view_params_food_price"
|
|
54
|
+
expected_primary_keys = ["market_code", "commodity_code", "commodity_category", "price_flag", "price_type",
|
|
55
|
+
"reference_period_start"]
|
|
56
|
+
expected_indexes = ["currency_code", "commodity_name", "market_name", "lat", "lon", "reference_period_end",
|
|
57
|
+
"location_code", "location_name",
|
|
58
|
+
"admin1_code", "admin1_name", "admin2_code", "admin2_name"]
|
|
59
|
+
expected_nullables = []
|
|
60
|
+
|
|
27
61
|
[[tables]]
|
|
28
62
|
db_module = "db_food_security"
|
|
29
63
|
target_view = "food_security_view"
|
|
@@ -81,7 +115,8 @@ expected_primary_keys = [
|
|
|
81
115
|
"sector_code",
|
|
82
116
|
"reference_period_start"
|
|
83
117
|
]
|
|
84
|
-
expected_indexes = ["
|
|
118
|
+
expected_indexes = ["org_type_description","reference_period_end", "location_code",
|
|
119
|
+
"location_name", "admin1_code", "admin1_name", "admin2_code", "admin2_name"]
|
|
85
120
|
expected_nullables = []
|
|
86
121
|
|
|
87
122
|
[[tables]]
|
|
@@ -116,6 +151,19 @@ expected_indexes = ["min_age", "max_age", "population", "reference_period_start"
|
|
|
116
151
|
"admin1_code", "admin1_name", "admin2_code", "admin2_name"]
|
|
117
152
|
expected_nullables = ["min_age", "max_age"]
|
|
118
153
|
|
|
154
|
+
[[tables]]
|
|
155
|
+
db_module = "db_poverty_rate"
|
|
156
|
+
target_view = "poverty_rate_view"
|
|
157
|
+
view_params_name="view_params_poverty_rate"
|
|
158
|
+
expected_primary_keys = [
|
|
159
|
+
"admin1_ref",
|
|
160
|
+
"admin1_name",
|
|
161
|
+
"reference_period_start"
|
|
162
|
+
]
|
|
163
|
+
expected_indexes = ["reference_period_end", "location_ref", "location_code",
|
|
164
|
+
"location_name", "admin1_name"]
|
|
165
|
+
expected_nullables = ["rate"]
|
|
166
|
+
|
|
119
167
|
[[tables]]
|
|
120
168
|
db_module = "db_refugees"
|
|
121
169
|
target_view = "refugees_view"
|
|
@@ -150,6 +198,28 @@ expected_primary_keys = [
|
|
|
150
198
|
expected_indexes = ["name"]
|
|
151
199
|
expected_nullables = []
|
|
152
200
|
|
|
201
|
+
[[tables]]
|
|
202
|
+
db_module = "db_wfp_commodity"
|
|
203
|
+
target_view = "wfp_commodity_view"
|
|
204
|
+
view_params_name = "view_params_wfp_commodity"
|
|
205
|
+
expected_primary_keys = [
|
|
206
|
+
"code"
|
|
207
|
+
]
|
|
208
|
+
expected_indexes = ["category","name"]
|
|
209
|
+
expected_nullables = []
|
|
210
|
+
|
|
211
|
+
[[tables]]
|
|
212
|
+
db_module = "db_wfp_market"
|
|
213
|
+
target_view = "wfp_market_view"
|
|
214
|
+
view_params_name = "view_params_wfp_market"
|
|
215
|
+
expected_primary_keys = [
|
|
216
|
+
"code"
|
|
217
|
+
]
|
|
218
|
+
expected_indexes = ["name","lat", "lon", "lat", "lon",
|
|
219
|
+
"location_code", "location_name",
|
|
220
|
+
"admin1_code", "admin1_name", "admin2_code", "admin2_name"]
|
|
221
|
+
expected_nullables = []
|
|
222
|
+
|
|
153
223
|
[[tables]]
|
|
154
224
|
db_module = "db_patch"
|
|
155
225
|
target_view = "patch_view"
|
|
@@ -3,10 +3,13 @@ from datetime import datetime
|
|
|
3
3
|
data_poverty_rate = [
|
|
4
4
|
dict(
|
|
5
5
|
resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
|
|
6
|
-
|
|
6
|
+
admin1_ref=1,
|
|
7
7
|
admin1_name="Province 01", # not p-coded/normalised yet
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
mpi=0.617442,
|
|
9
|
+
headcount_ratio=85.4,
|
|
10
|
+
intensity_of_deprivation=72.3,
|
|
11
|
+
vulnerable_to_poverty=10.5,
|
|
12
|
+
in_severe_poverty=52.1,
|
|
10
13
|
reference_period_start=datetime(2024, 1, 1),
|
|
11
14
|
reference_period_end=datetime(2024, 12, 31),
|
|
12
15
|
),
|
|
@@ -23,6 +23,8 @@ def test_operational_presence_view(run_view_test):
|
|
|
23
23
|
view_operational_presence.c.location_code == "FOO",
|
|
24
24
|
view_operational_presence.c.org_acronym == "ORG02",
|
|
25
25
|
view_operational_presence.c.org_type_code == "437",
|
|
26
|
+
view_operational_presence.c.org_type_description
|
|
27
|
+
== "International NGO",
|
|
26
28
|
view_operational_presence.c.sector_name
|
|
27
29
|
== "Water Sanitation Hygiene",
|
|
28
30
|
),
|