hapi-schema 0.8.7__tar.gz → 0.8.9__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.7 → hapi_schema-0.8.9}/PKG-INFO +1 -1
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/changelog.md +26 -7
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/_version.py +2 -2
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_conflict_event.py +2 -3
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_food_price.py +7 -4
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_food_security.py +5 -4
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_funding.py +3 -3
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_humanitarian_needs.py +7 -5
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_national_risk.py +4 -4
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_population.py +4 -3
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_poverty_rate.py +1 -1
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_refugees.py +9 -4
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_wfp_commodity.py +3 -3
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/utils/constraints.py +13 -9
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/utils/enums.py +30 -17
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_humanitarian_needs.py +7 -7
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_population.py +4 -4
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_sector.py +2 -2
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_admin1.py +2 -2
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_admin2.py +2 -2
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_conflict_event.py +3 -3
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_food_price.py +2 -2
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_food_security.py +2 -2
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_funding.py +4 -4
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_humanitarian_needs.py +7 -7
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_location.py +2 -2
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_national_risk.py +13 -8
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_operational_presence.py +1 -1
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_population.py +15 -8
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_poverty_rate.py +8 -8
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_refugees.py +6 -6
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_wfp_market.py +1 -1
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/.config/coveragerc +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/.config/pre-commit-config.yaml +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/.config/pytest.ini +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/.config/ruff.toml +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/.github/workflows/publish.yaml +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/.github/workflows/run-python-tests.yaml +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/.gitignore +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/LICENSE +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/README.md +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/contributing.md +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/docker/docker-compose.yml +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/initialize_test_db.sh +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/pyproject.toml +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/requirements.txt +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/__init__.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_admin1.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_admin2.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_currency.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_dataset.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_location.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_operational_presence.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_org.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_org_type.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_patch.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_resource.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_sector.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_views_as_tables.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/db_wfp_market.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/utils/__init__.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/utils/base.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/utils/hapi_views_code_generator.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/utils/view_as_table_code_generator.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/utils/view_as_table_definitions.toml +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/utils/view_params.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/src/hapi_schema/views.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/conftest.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/__init__.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_admin1.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_admin2.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_conflict_event.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_currency.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_dataset.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_food_price.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_food_security.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_funding.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_location.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_national_risk.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_operational_presence.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_org.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_org_type.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_patch.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_poverty_rate.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_refugees.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_resource.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_wfp_commodity.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/sample_data/data_wfp_market.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_currency.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_dataset.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_org.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_org_type.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_patch.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_resource.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_sector.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_views_as_tables.py +0 -0
- {hapi_schema-0.8.7 → hapi_schema-0.8.9}/tests/test_wfp_commodity.py +0 -0
|
@@ -5,14 +5,31 @@ 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.9
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Some enums missing built from values
|
|
13
|
+
|
|
14
|
+
## 0.8.8
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Rewrite enums to use values rather than variable names
|
|
19
|
+
- Switch from "*" to "all" for rollup in enums
|
|
20
|
+
- Add "intersectoral" to sample sector data (distinct from "all")
|
|
21
|
+
- Ensure that constraint names end consistently with "\_constraint"
|
|
22
|
+
|
|
8
23
|
## 0.8.7
|
|
9
24
|
|
|
10
|
-
|
|
25
|
+
### Changed
|
|
26
|
+
|
|
11
27
|
- Add unit to food\_price table primary key
|
|
12
28
|
|
|
13
29
|
## 0.8.6
|
|
14
30
|
|
|
15
|
-
|
|
31
|
+
### Changed
|
|
32
|
+
|
|
16
33
|
- Added food\_price view as tables by updating the toml parameter file
|
|
17
34
|
- Updated poverty\_rate view as table
|
|
18
35
|
- Updated operational\_presence view as table by updating the toml parameter file
|
|
@@ -20,11 +37,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
20
37
|
|
|
21
38
|
## 0.8.5
|
|
22
39
|
|
|
23
|
-
|
|
40
|
+
### Changed
|
|
41
|
+
|
|
24
42
|
- refactor DBPovertyRate to wide instead of narrow
|
|
25
43
|
- added org\_type\_description to operational\_presence\_view
|
|
26
44
|
|
|
27
45
|
## Removed
|
|
46
|
+
|
|
28
47
|
- rate\_constraint and `PovertyClassification` enum
|
|
29
48
|
|
|
30
49
|
## 0.8.4
|
|
@@ -33,7 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
33
52
|
|
|
34
53
|
- New constraints: rate\_constraint
|
|
35
54
|
|
|
36
|
-
###
|
|
55
|
+
### Changed
|
|
37
56
|
|
|
38
57
|
- refactor DBPovertyRate to track rates rather than population, and link to
|
|
39
58
|
location (with admin1\_name as a text field)
|
|
@@ -51,19 +70,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
51
70
|
Miscellaneous fixes for pipelines
|
|
52
71
|
|
|
53
72
|
### Changed
|
|
54
|
-
- added from\_cods column to location, admin1, and admin2
|
|
55
73
|
|
|
74
|
+
- added from\_cods column to location, admin1, and admin2
|
|
56
75
|
|
|
57
76
|
## 0.8.1
|
|
58
77
|
|
|
59
78
|
Implemented the Food Prices subcategory.
|
|
60
79
|
|
|
61
80
|
### Added
|
|
81
|
+
|
|
62
82
|
- New tables and views: food\_price, wfp\_commodity, wfp\_market, currency
|
|
63
83
|
- New enums: PriceFlag, PriceType, CommodityCategory
|
|
64
84
|
- New constraints: non\_negative\_constraint, latlon\_constraint
|
|
65
85
|
|
|
66
|
-
|
|
67
86
|
## 0.8.0
|
|
68
87
|
|
|
69
88
|
### Changed
|
|
@@ -76,6 +95,7 @@ Implemented the Food Prices subcategory.
|
|
|
76
95
|
- Programmatically obtain views
|
|
77
96
|
|
|
78
97
|
### Added
|
|
98
|
+
|
|
79
99
|
- New tables: humanitarian\_needs, funding, refugees, conflict\_event, poverty\_rate
|
|
80
100
|
- New enums: Gender, DisabledMarker, EventType, PopulationGroup, PopulationStatus, IPCPhase, PovertyClassification, IPCType, and RiskClass
|
|
81
101
|
- Generalized constraints
|
|
@@ -84,7 +104,6 @@ Implemented the Food Prices subcategory.
|
|
|
84
104
|
|
|
85
105
|
- ipc\_phase, ipc\_type, age\_range, and gender tables
|
|
86
106
|
|
|
87
|
-
|
|
88
107
|
## [0.7.3]
|
|
89
108
|
|
|
90
109
|
### Fixed
|
|
@@ -4,7 +4,6 @@ from datetime import datetime
|
|
|
4
4
|
|
|
5
5
|
from sqlalchemy import (
|
|
6
6
|
DateTime,
|
|
7
|
-
Enum,
|
|
8
7
|
ForeignKey,
|
|
9
8
|
Integer,
|
|
10
9
|
select,
|
|
@@ -18,7 +17,7 @@ from hapi_schema.utils.constraints import (
|
|
|
18
17
|
population_constraint,
|
|
19
18
|
reference_period_constraint,
|
|
20
19
|
)
|
|
21
|
-
from hapi_schema.utils.enums import EventType
|
|
20
|
+
from hapi_schema.utils.enums import EventType, build_enum_using_values
|
|
22
21
|
from hapi_schema.utils.view_params import ViewParams
|
|
23
22
|
|
|
24
23
|
|
|
@@ -43,7 +42,7 @@ class DBConflictEvent(Base):
|
|
|
43
42
|
primary_key=True,
|
|
44
43
|
)
|
|
45
44
|
event_type: Mapped[EventType] = mapped_column(
|
|
46
|
-
|
|
45
|
+
build_enum_using_values(EventType), nullable=False, primary_key=True
|
|
47
46
|
)
|
|
48
47
|
events: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
|
|
49
48
|
fatalities: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
|
|
@@ -5,7 +5,6 @@ from decimal import Decimal
|
|
|
5
5
|
|
|
6
6
|
from sqlalchemy import (
|
|
7
7
|
DateTime,
|
|
8
|
-
Enum,
|
|
9
8
|
ForeignKey,
|
|
10
9
|
String,
|
|
11
10
|
select,
|
|
@@ -22,7 +21,11 @@ from hapi_schema.utils.constraints import (
|
|
|
22
21
|
non_negative_constraint,
|
|
23
22
|
reference_period_constraint,
|
|
24
23
|
)
|
|
25
|
-
from hapi_schema.utils.enums import
|
|
24
|
+
from hapi_schema.utils.enums import (
|
|
25
|
+
PriceFlag,
|
|
26
|
+
PriceType,
|
|
27
|
+
build_enum_using_values,
|
|
28
|
+
)
|
|
26
29
|
from hapi_schema.utils.view_params import ViewParams
|
|
27
30
|
|
|
28
31
|
# normalised table
|
|
@@ -52,10 +55,10 @@ class DBFoodPrice(Base):
|
|
|
52
55
|
)
|
|
53
56
|
unit: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
54
57
|
price_flag: Mapped[PriceFlag] = mapped_column(
|
|
55
|
-
|
|
58
|
+
build_enum_using_values(PriceFlag), primary_key=True
|
|
56
59
|
)
|
|
57
60
|
price_type: Mapped[PriceType] = mapped_column(
|
|
58
|
-
|
|
61
|
+
build_enum_using_values(PriceType), primary_key=True
|
|
59
62
|
)
|
|
60
63
|
price: Mapped[Decimal] = mapped_column(nullable=False)
|
|
61
64
|
reference_period_start: Mapped[datetime] = mapped_column(
|
|
@@ -5,7 +5,6 @@ from decimal import Decimal
|
|
|
5
5
|
|
|
6
6
|
from sqlalchemy import (
|
|
7
7
|
DateTime,
|
|
8
|
-
Enum,
|
|
9
8
|
Float,
|
|
10
9
|
ForeignKey,
|
|
11
10
|
Integer,
|
|
@@ -22,7 +21,7 @@ from hapi_schema.utils.constraints import (
|
|
|
22
21
|
population_constraint,
|
|
23
22
|
reference_period_constraint,
|
|
24
23
|
)
|
|
25
|
-
from hapi_schema.utils.enums import IPCPhase, IPCType
|
|
24
|
+
from hapi_schema.utils.enums import IPCPhase, IPCType, build_enum_using_values
|
|
26
25
|
from hapi_schema.utils.view_params import ViewParams
|
|
27
26
|
|
|
28
27
|
|
|
@@ -41,9 +40,11 @@ class DBFoodSecurity(Base):
|
|
|
41
40
|
ForeignKey("admin2.id", onupdate="CASCADE"), primary_key=True
|
|
42
41
|
)
|
|
43
42
|
ipc_phase: Mapped[IPCPhase] = mapped_column(
|
|
44
|
-
|
|
43
|
+
build_enum_using_values(IPCPhase), primary_key=True
|
|
44
|
+
)
|
|
45
|
+
ipc_type: Mapped[IPCType] = mapped_column(
|
|
46
|
+
build_enum_using_values(IPCType), primary_key=True
|
|
45
47
|
)
|
|
46
|
-
ipc_type: Mapped[IPCType] = mapped_column(Enum(IPCType), primary_key=True)
|
|
47
48
|
population_in_phase: Mapped[int] = mapped_column(
|
|
48
49
|
Integer, nullable=False, index=True
|
|
49
50
|
)
|
|
@@ -24,15 +24,15 @@ class DBFunding(Base):
|
|
|
24
24
|
__table_args__ = (
|
|
25
25
|
CheckConstraint(
|
|
26
26
|
"requirements_usd >= 0.0",
|
|
27
|
-
name="
|
|
27
|
+
name="requirements_usd_constraint",
|
|
28
28
|
),
|
|
29
29
|
CheckConstraint(
|
|
30
30
|
"funding_usd >= 0.0",
|
|
31
|
-
name="
|
|
31
|
+
name="funding_usd_constraint",
|
|
32
32
|
),
|
|
33
33
|
CheckConstraint(
|
|
34
34
|
"funding_pct >= 0.0",
|
|
35
|
-
name="
|
|
35
|
+
name="funding_pct_constraint",
|
|
36
36
|
),
|
|
37
37
|
reference_period_constraint(),
|
|
38
38
|
)
|
|
@@ -4,7 +4,6 @@ from datetime import datetime
|
|
|
4
4
|
|
|
5
5
|
from sqlalchemy import (
|
|
6
6
|
DateTime,
|
|
7
|
-
Enum,
|
|
8
7
|
ForeignKey,
|
|
9
8
|
Integer,
|
|
10
9
|
String,
|
|
@@ -28,6 +27,7 @@ from hapi_schema.utils.enums import (
|
|
|
28
27
|
Gender,
|
|
29
28
|
PopulationGroup,
|
|
30
29
|
PopulationStatus,
|
|
30
|
+
build_enum_using_values,
|
|
31
31
|
)
|
|
32
32
|
from hapi_schema.utils.view_params import ViewParams
|
|
33
33
|
|
|
@@ -49,7 +49,9 @@ class DBHumanitarianNeeds(Base):
|
|
|
49
49
|
ForeignKey("admin2.id", onupdate="CASCADE"),
|
|
50
50
|
primary_key=True,
|
|
51
51
|
)
|
|
52
|
-
gender: Mapped[Gender] = mapped_column(
|
|
52
|
+
gender: Mapped[Gender] = mapped_column(
|
|
53
|
+
build_enum_using_values(Gender), primary_key=True
|
|
54
|
+
)
|
|
53
55
|
age_range: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
54
56
|
min_age: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
|
|
55
57
|
max_age: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
|
|
@@ -58,17 +60,17 @@ class DBHumanitarianNeeds(Base):
|
|
|
58
60
|
primary_key=True,
|
|
59
61
|
)
|
|
60
62
|
population_group: Mapped[PopulationGroup] = mapped_column(
|
|
61
|
-
|
|
63
|
+
build_enum_using_values(PopulationGroup),
|
|
62
64
|
primary_key=True,
|
|
63
65
|
)
|
|
64
66
|
|
|
65
67
|
population_status: Mapped[PopulationStatus] = mapped_column(
|
|
66
|
-
|
|
68
|
+
build_enum_using_values(PopulationStatus),
|
|
67
69
|
primary_key=True,
|
|
68
70
|
)
|
|
69
71
|
|
|
70
72
|
disabled_marker: Mapped[DisabledMarker] = mapped_column(
|
|
71
|
-
|
|
73
|
+
build_enum_using_values(DisabledMarker), primary_key=True
|
|
72
74
|
)
|
|
73
75
|
population: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
74
76
|
reference_period_start: Mapped[datetime] = mapped_column(
|
|
@@ -6,7 +6,6 @@ from decimal import Decimal
|
|
|
6
6
|
from sqlalchemy import (
|
|
7
7
|
CheckConstraint,
|
|
8
8
|
DateTime,
|
|
9
|
-
Enum,
|
|
10
9
|
Float,
|
|
11
10
|
ForeignKey,
|
|
12
11
|
Integer,
|
|
@@ -20,7 +19,7 @@ from hapi_schema.utils.constraints import (
|
|
|
20
19
|
general_risk_constraint,
|
|
21
20
|
reference_period_constraint,
|
|
22
21
|
)
|
|
23
|
-
from hapi_schema.utils.enums import RiskClass
|
|
22
|
+
from hapi_schema.utils.enums import RiskClass, build_enum_using_values
|
|
24
23
|
from hapi_schema.utils.view_params import ViewParams
|
|
25
24
|
|
|
26
25
|
|
|
@@ -32,7 +31,8 @@ class DBNationalRisk(Base):
|
|
|
32
31
|
general_risk_constraint("vulnerability"),
|
|
33
32
|
general_risk_constraint("coping_capacity"),
|
|
34
33
|
CheckConstraint(
|
|
35
|
-
"(global_rank >= 1) AND (global_rank <= 250)",
|
|
34
|
+
"(global_rank >= 1) AND (global_rank <= 250)",
|
|
35
|
+
name="global_rank_constraint",
|
|
36
36
|
),
|
|
37
37
|
CheckConstraint(
|
|
38
38
|
"meta_avg_recentness_years >= 0.0",
|
|
@@ -53,7 +53,7 @@ class DBNationalRisk(Base):
|
|
|
53
53
|
ForeignKey("location.id", onupdate="CASCADE"), primary_key=True
|
|
54
54
|
)
|
|
55
55
|
risk_class: Mapped[RiskClass] = mapped_column(
|
|
56
|
-
|
|
56
|
+
build_enum_using_values(RiskClass), nullable=False
|
|
57
57
|
)
|
|
58
58
|
global_rank: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
59
59
|
overall_risk: Mapped[Decimal] = mapped_column(Float, nullable=False)
|
|
@@ -4,7 +4,6 @@ from datetime import datetime
|
|
|
4
4
|
|
|
5
5
|
from sqlalchemy import (
|
|
6
6
|
DateTime,
|
|
7
|
-
Enum,
|
|
8
7
|
ForeignKey,
|
|
9
8
|
Integer,
|
|
10
9
|
String,
|
|
@@ -22,7 +21,7 @@ from hapi_schema.utils.constraints import (
|
|
|
22
21
|
population_constraint,
|
|
23
22
|
reference_period_constraint,
|
|
24
23
|
)
|
|
25
|
-
from hapi_schema.utils.enums import Gender
|
|
24
|
+
from hapi_schema.utils.enums import Gender, build_enum_using_values
|
|
26
25
|
from hapi_schema.utils.view_params import ViewParams
|
|
27
26
|
|
|
28
27
|
|
|
@@ -43,7 +42,9 @@ class DBPopulation(Base):
|
|
|
43
42
|
ForeignKey("admin2.id", onupdate="CASCADE"),
|
|
44
43
|
primary_key=True,
|
|
45
44
|
)
|
|
46
|
-
gender: Mapped[Gender] = mapped_column(
|
|
45
|
+
gender: Mapped[Gender] = mapped_column(
|
|
46
|
+
build_enum_using_values(Gender), primary_key=True
|
|
47
|
+
)
|
|
47
48
|
age_range: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
48
49
|
min_age: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
|
|
49
50
|
max_age: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
|
|
@@ -7,7 +7,6 @@ from datetime import datetime
|
|
|
7
7
|
|
|
8
8
|
from sqlalchemy import (
|
|
9
9
|
DateTime,
|
|
10
|
-
Enum,
|
|
11
10
|
ForeignKey,
|
|
12
11
|
Integer,
|
|
13
12
|
String,
|
|
@@ -23,7 +22,11 @@ from hapi_schema.utils.constraints import (
|
|
|
23
22
|
population_constraint,
|
|
24
23
|
reference_period_constraint,
|
|
25
24
|
)
|
|
26
|
-
from hapi_schema.utils.enums import
|
|
25
|
+
from hapi_schema.utils.enums import (
|
|
26
|
+
Gender,
|
|
27
|
+
PopulationGroup,
|
|
28
|
+
build_enum_using_values,
|
|
29
|
+
)
|
|
27
30
|
from hapi_schema.utils.view_params import ViewParams
|
|
28
31
|
|
|
29
32
|
|
|
@@ -48,9 +51,11 @@ class DBRefugees(Base):
|
|
|
48
51
|
)
|
|
49
52
|
# population_group is broader than we need, but it will do
|
|
50
53
|
population_group: Mapped[PopulationGroup] = mapped_column(
|
|
51
|
-
|
|
54
|
+
build_enum_using_values(PopulationGroup), primary_key=True
|
|
55
|
+
)
|
|
56
|
+
gender: Mapped[Gender] = mapped_column(
|
|
57
|
+
build_enum_using_values(Gender), primary_key=True
|
|
52
58
|
)
|
|
53
|
-
gender: Mapped[Gender] = mapped_column(Enum(Gender), primary_key=True)
|
|
54
59
|
age_range: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
55
60
|
min_age: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
|
|
56
61
|
max_age: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"""wfp_commodity table and view."""
|
|
2
2
|
|
|
3
|
-
from sqlalchemy import
|
|
3
|
+
from sqlalchemy import String, select
|
|
4
4
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
5
5
|
|
|
6
6
|
from hapi_schema.utils.base import Base
|
|
7
|
-
from hapi_schema.utils.enums import CommodityCategory
|
|
7
|
+
from hapi_schema.utils.enums import CommodityCategory, build_enum_using_values
|
|
8
8
|
from hapi_schema.utils.view_params import ViewParams
|
|
9
9
|
|
|
10
10
|
|
|
@@ -13,7 +13,7 @@ class DBWFPCommodity(Base):
|
|
|
13
13
|
|
|
14
14
|
code: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
15
15
|
category: Mapped[CommodityCategory] = mapped_column(
|
|
16
|
-
|
|
16
|
+
build_enum_using_values(CommodityCategory), index=True
|
|
17
17
|
)
|
|
18
18
|
name: Mapped[str] = mapped_column(String(512), nullable=False, index=True)
|
|
19
19
|
|
|
@@ -9,8 +9,8 @@ def min_age_constraint() -> CheckConstraint:
|
|
|
9
9
|
Otherwise, it can be NULL for unknown, or should be an
|
|
10
10
|
integer of 0 or greater."""
|
|
11
11
|
sqltext = (
|
|
12
|
-
"(age_range = '
|
|
13
|
-
"(age_range != '
|
|
12
|
+
"(age_range = 'all' AND min_age IS NULL) OR "
|
|
13
|
+
"(age_range != 'all' AND min_age >= 0)"
|
|
14
14
|
)
|
|
15
15
|
return CheckConstraint(sqltext=sqltext, name="min_age_constraint")
|
|
16
16
|
|
|
@@ -32,7 +32,9 @@ def population_constraint(
|
|
|
32
32
|
) -> CheckConstraint:
|
|
33
33
|
"""Population must not be a negative number."""
|
|
34
34
|
sqltext = f"{population_var_name} >= 0"
|
|
35
|
-
return CheckConstraint(
|
|
35
|
+
return CheckConstraint(
|
|
36
|
+
sqltext=sqltext, name=f"{population_var_name}_constraint"
|
|
37
|
+
)
|
|
36
38
|
|
|
37
39
|
|
|
38
40
|
def non_negative_constraint(
|
|
@@ -40,23 +42,25 @@ def non_negative_constraint(
|
|
|
40
42
|
) -> CheckConstraint:
|
|
41
43
|
"""Require a column to be non-negative."""
|
|
42
44
|
sqltext = f"{var_name} >= 0"
|
|
43
|
-
return CheckConstraint(sqltext=sqltext, name=f"{var_name}")
|
|
45
|
+
return CheckConstraint(sqltext=sqltext, name=f"{var_name}_constraint")
|
|
44
46
|
|
|
45
47
|
|
|
46
48
|
def percentage_constraint(var_name: str) -> CheckConstraint:
|
|
47
49
|
sqltext = f"{var_name} >= 0. AND {var_name} <= 100."
|
|
48
|
-
return CheckConstraint(sqltext=sqltext, name=f"{var_name}")
|
|
50
|
+
return CheckConstraint(sqltext=sqltext, name=f"{var_name}_constraint")
|
|
49
51
|
|
|
50
52
|
|
|
51
53
|
def reference_period_constraint() -> CheckConstraint:
|
|
52
54
|
"""reference_period_end should be greater than reference_period_start"""
|
|
53
55
|
sqltext = "reference_period_end >= reference_period_start "
|
|
54
|
-
return CheckConstraint(sqltext=sqltext, name="
|
|
56
|
+
return CheckConstraint(sqltext=sqltext, name="reference_period_constraint")
|
|
55
57
|
|
|
56
58
|
|
|
57
59
|
def general_risk_constraint(risk_name: str) -> CheckConstraint:
|
|
58
60
|
sqltext = f"({risk_name}_risk >= 0) AND ({risk_name}_risk <= 10)"
|
|
59
|
-
return CheckConstraint(
|
|
61
|
+
return CheckConstraint(
|
|
62
|
+
sqltext=sqltext, name=f"{risk_name}_risk_constraint"
|
|
63
|
+
)
|
|
60
64
|
|
|
61
65
|
|
|
62
66
|
def code_and_reference_period_unique_constraint(
|
|
@@ -65,11 +69,11 @@ def code_and_reference_period_unique_constraint(
|
|
|
65
69
|
return UniqueConstraint(
|
|
66
70
|
"code",
|
|
67
71
|
"reference_period_start",
|
|
68
|
-
name=f"{admin_level}
|
|
72
|
+
name=f"{admin_level}_code_and_reference_period_unique_constraint",
|
|
69
73
|
)
|
|
70
74
|
|
|
71
75
|
|
|
72
76
|
def latlon_constraint() -> CheckConstraint:
|
|
73
77
|
"""Latitude and longitude must be valid"""
|
|
74
78
|
sqltext = "lat <= 90.0 AND lat >= -90.0 AND lon <= 180.0 AND lon >= -180.0"
|
|
75
|
-
return CheckConstraint(sqltext=sqltext, name="
|
|
79
|
+
return CheckConstraint(sqltext=sqltext, name="latlon_constraint")
|
|
@@ -1,28 +1,41 @@
|
|
|
1
|
-
import
|
|
1
|
+
from enum import Enum as PythonEnum
|
|
2
|
+
from typing import List, Type
|
|
2
3
|
|
|
4
|
+
from sqlalchemy import Enum as SQLAlchemyEnum
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
"""The two functions below create enums using the values rather than the keys"""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _get_list_of_values(enum_class: Type[PythonEnum]) -> List[str]:
|
|
10
|
+
return [e.value for e in enum_class]
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def build_enum_using_values(enum_class: Type[PythonEnum]) -> SQLAlchemyEnum:
|
|
14
|
+
return SQLAlchemyEnum(enum_class, values_callable=_get_list_of_values)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Gender(str, PythonEnum):
|
|
5
18
|
FEMALE = "f"
|
|
6
19
|
MALE = "m"
|
|
7
20
|
NONBINARY = "x"
|
|
8
21
|
UNSPECIFIED = "u"
|
|
9
22
|
OTHER = "o"
|
|
10
|
-
ALL = "
|
|
23
|
+
ALL = "all"
|
|
11
24
|
|
|
12
25
|
|
|
13
|
-
class DisabledMarker(str,
|
|
26
|
+
class DisabledMarker(str, PythonEnum):
|
|
14
27
|
YES = "y"
|
|
15
28
|
NO = "n"
|
|
16
|
-
ALL = "
|
|
29
|
+
ALL = "all"
|
|
17
30
|
|
|
18
31
|
|
|
19
|
-
class EventType(str,
|
|
32
|
+
class EventType(str, PythonEnum):
|
|
20
33
|
CIVILIAN_TARGETING = "civilian_targeting"
|
|
21
34
|
DEMONSTRATION = "demonstration"
|
|
22
35
|
POLITICAL_VIOLENCE = "political_violence"
|
|
23
36
|
|
|
24
37
|
|
|
25
|
-
class PopulationGroup(str,
|
|
38
|
+
class PopulationGroup(str, PythonEnum):
|
|
26
39
|
REFUGEES = "REF"
|
|
27
40
|
ROC = "ROC"
|
|
28
41
|
ASYLUM_SEEKERS = "ASY"
|
|
@@ -38,47 +51,47 @@ class PopulationGroup(str, enum.Enum):
|
|
|
38
51
|
POC = "POC"
|
|
39
52
|
RDP = "RDP"
|
|
40
53
|
RRI = "RRI"
|
|
41
|
-
ALL = "
|
|
54
|
+
ALL = "all"
|
|
42
55
|
|
|
43
56
|
|
|
44
|
-
class PopulationStatus(str,
|
|
57
|
+
class PopulationStatus(str, PythonEnum):
|
|
45
58
|
POPULATION = "POP"
|
|
46
59
|
AFFECTED = "AFF"
|
|
47
60
|
INNEED = "INN"
|
|
48
61
|
TARGETED = "TGT"
|
|
49
62
|
REACHED = "REA"
|
|
50
|
-
ALL = "
|
|
63
|
+
ALL = "all"
|
|
51
64
|
|
|
52
65
|
|
|
53
|
-
class PriceFlag(str,
|
|
66
|
+
class PriceFlag(str, PythonEnum):
|
|
54
67
|
ACTUAL = "actual"
|
|
55
68
|
AGGREGATE = "aggregate"
|
|
56
69
|
ACTUAL_AGGREGATE = "actual,aggregate"
|
|
57
70
|
|
|
58
71
|
|
|
59
|
-
class PriceType(str,
|
|
72
|
+
class PriceType(str, PythonEnum):
|
|
60
73
|
FARM_GATE = "Farm Gate"
|
|
61
74
|
RETAIL = "Retail"
|
|
62
75
|
WHOLESALE = "Wholesale"
|
|
63
76
|
|
|
64
77
|
|
|
65
|
-
class IPCPhase(str,
|
|
78
|
+
class IPCPhase(str, PythonEnum):
|
|
66
79
|
PHASE_1 = "1"
|
|
67
80
|
PHASE_2 = "2"
|
|
68
81
|
PHASE_3 = "3"
|
|
69
82
|
PHASE_4 = "4"
|
|
70
83
|
PHASE_5 = "5"
|
|
71
84
|
PHASE_3_PLUS = "3+"
|
|
72
|
-
ALL = "
|
|
85
|
+
ALL = "all"
|
|
73
86
|
|
|
74
87
|
|
|
75
|
-
class IPCType(str,
|
|
88
|
+
class IPCType(str, PythonEnum):
|
|
76
89
|
CURRENT = "current"
|
|
77
90
|
FIRST_PROJECTION = "first projection"
|
|
78
91
|
SECOND_PROJECTION = "second projection"
|
|
79
92
|
|
|
80
93
|
|
|
81
|
-
class RiskClass(str,
|
|
94
|
+
class RiskClass(str, PythonEnum):
|
|
82
95
|
VERY_LOW = "1"
|
|
83
96
|
LOW = "2"
|
|
84
97
|
MEDIUM = "3"
|
|
@@ -86,7 +99,7 @@ class RiskClass(str, enum.Enum):
|
|
|
86
99
|
VERY_HIGH = "5"
|
|
87
100
|
|
|
88
101
|
|
|
89
|
-
class CommodityCategory(str,
|
|
102
|
+
class CommodityCategory(str, PythonEnum):
|
|
90
103
|
CEREALS_TUBERS = "cereals and tubers"
|
|
91
104
|
MEAT_FISH_EGGS = "meat, fish and eggs"
|
|
92
105
|
MILK_DAIRY = "milk and dairy"
|
|
@@ -5,11 +5,11 @@ data_humanitarian_needs = [
|
|
|
5
5
|
dict(
|
|
6
6
|
resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
|
|
7
7
|
admin2_ref=1,
|
|
8
|
-
gender="
|
|
9
|
-
age_range="
|
|
10
|
-
disabled_marker="
|
|
11
|
-
sector_code="
|
|
12
|
-
population_group="
|
|
8
|
+
gender="all",
|
|
9
|
+
age_range="all",
|
|
10
|
+
disabled_marker="all",
|
|
11
|
+
sector_code="intersectoral",
|
|
12
|
+
population_group="all",
|
|
13
13
|
population_status="AFF",
|
|
14
14
|
population=1_000_000,
|
|
15
15
|
reference_period_start=datetime(2023, 1, 1),
|
|
@@ -20,7 +20,7 @@ data_humanitarian_needs = [
|
|
|
20
20
|
resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
|
|
21
21
|
admin2_ref=1,
|
|
22
22
|
gender="f",
|
|
23
|
-
age_range="
|
|
23
|
+
age_range="all",
|
|
24
24
|
disabled_marker="n",
|
|
25
25
|
sector_code="SHL",
|
|
26
26
|
population_group="REF",
|
|
@@ -49,7 +49,7 @@ data_humanitarian_needs = [
|
|
|
49
49
|
dict(
|
|
50
50
|
resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
|
|
51
51
|
admin2_ref=4,
|
|
52
|
-
gender="
|
|
52
|
+
gender="all",
|
|
53
53
|
age_range="80+",
|
|
54
54
|
min_age=80,
|
|
55
55
|
disabled_marker="y",
|
|
@@ -5,8 +5,8 @@ data_population = [
|
|
|
5
5
|
dict(
|
|
6
6
|
resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
|
|
7
7
|
admin2_ref=1,
|
|
8
|
-
gender="
|
|
9
|
-
age_range="
|
|
8
|
+
gender="all",
|
|
9
|
+
age_range="all",
|
|
10
10
|
population=1_000_000,
|
|
11
11
|
reference_period_start=datetime(2023, 1, 1),
|
|
12
12
|
reference_period_end=datetime(2023, 6, 30),
|
|
@@ -16,7 +16,7 @@ data_population = [
|
|
|
16
16
|
resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
|
|
17
17
|
admin2_ref=1,
|
|
18
18
|
gender="f",
|
|
19
|
-
age_range="
|
|
19
|
+
age_range="all",
|
|
20
20
|
population=500_000,
|
|
21
21
|
reference_period_start=datetime(2023, 1, 1),
|
|
22
22
|
reference_period_end=datetime(2023, 6, 30),
|
|
@@ -37,7 +37,7 @@ data_population = [
|
|
|
37
37
|
dict(
|
|
38
38
|
resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
|
|
39
39
|
admin2_ref=4,
|
|
40
|
-
gender="
|
|
40
|
+
gender="all",
|
|
41
41
|
age_range="80+",
|
|
42
42
|
min_age=80,
|
|
43
43
|
population=500,
|
|
@@ -42,7 +42,7 @@ def test_reference_period_constraint(run_constraints_test):
|
|
|
42
42
|
reference_period_end=datetime(2023, 1, 1),
|
|
43
43
|
)
|
|
44
44
|
],
|
|
45
|
-
expected_constraint="
|
|
45
|
+
expected_constraint="reference_period_constraint",
|
|
46
46
|
)
|
|
47
47
|
|
|
48
48
|
|
|
@@ -65,5 +65,5 @@ def test_code_date_unique(run_constraints_test):
|
|
|
65
65
|
reference_period_start=datetime(2023, 1, 1),
|
|
66
66
|
),
|
|
67
67
|
],
|
|
68
|
-
expected_constraint="
|
|
68
|
+
expected_constraint="admin1_code_and_reference_period_unique_constraint",
|
|
69
69
|
)
|