hapi-schema 0.8.3__tar.gz → 0.8.4__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.3 → hapi_schema-0.8.4}/PKG-INFO +1 -1
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/changelog.md +11 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/_version.py +2 -2
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_poverty_rate.py +12 -17
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/utils/constraints.py +8 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/utils/enums.py +0 -1
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_poverty_rate.py +3 -2
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_poverty_rate.py +8 -6
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/.config/coveragerc +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/.config/pre-commit-config.yaml +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/.config/pytest.ini +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/.config/ruff.toml +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/.github/workflows/publish.yaml +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/.github/workflows/run-python-tests.yaml +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/.gitignore +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/LICENSE +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/README.md +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/contributing.md +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/docker/docker-compose.yml +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/initialize_test_db.sh +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/pyproject.toml +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/requirements.txt +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/__init__.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_admin1.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_admin2.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_conflict_event.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_currency.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_dataset.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_food_price.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_food_security.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_funding.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_humanitarian_needs.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_location.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_national_risk.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_operational_presence.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_org.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_org_type.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_patch.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_population.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_refugees.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_resource.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_sector.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_views_as_tables.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_wfp_commodity.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/db_wfp_market.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/utils/__init__.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/utils/base.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/utils/hapi_views_code_generator.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/utils/view_as_table_code_generator.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/utils/view_as_table_definitions.toml +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/utils/view_params.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/views.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/conftest.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/__init__.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_admin1.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_admin2.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_conflict_event.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_currency.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_dataset.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_food_price.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_food_security.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_funding.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_humanitarian_needs.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_location.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_national_risk.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_operational_presence.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_org.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_org_type.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_patch.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_population.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_refugees.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_resource.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_sector.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_wfp_commodity.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/sample_data/data_wfp_market.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_admin1.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_admin2.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_conflict_event.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_currency.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_dataset.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_food_price.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_food_security.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_funding.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_humanitarian_needs.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_location.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_national_risk.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_operational_presence.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_org.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_org_type.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_patch.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_population.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_refugees.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_resource.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_sector.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_views_as_tables.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_wfp_commodity.py +0 -0
- {hapi_schema-0.8.3 → hapi_schema-0.8.4}/tests/test_wfp_market.py +0 -0
|
@@ -5,6 +5,17 @@ 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.4
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- New constraints: rate\_constraint
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- remove ALL ("*") from PovertyClassification enum
|
|
17
|
+
- refactor DBPovertyRate to track rates rather than population, and link to location (with admin1\_name as a text field)
|
|
18
|
+
|
|
8
19
|
## 0.8.3
|
|
9
20
|
|
|
10
21
|
### Changed
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
"""PovertyRate table and view."""
|
|
2
2
|
|
|
3
3
|
from datetime import datetime
|
|
4
|
+
from decimal import Decimal
|
|
4
5
|
|
|
5
6
|
from sqlalchemy import (
|
|
6
7
|
DateTime,
|
|
7
8
|
Enum,
|
|
8
9
|
ForeignKey,
|
|
9
|
-
|
|
10
|
+
String,
|
|
10
11
|
select,
|
|
11
12
|
)
|
|
12
13
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
13
14
|
|
|
14
|
-
from hapi_schema.db_admin1 import DBAdmin1
|
|
15
15
|
from hapi_schema.db_location import DBLocation
|
|
16
16
|
from hapi_schema.db_resource import DBResource
|
|
17
17
|
from hapi_schema.utils.base import Base
|
|
18
18
|
from hapi_schema.utils.constraints import (
|
|
19
|
-
|
|
19
|
+
rate_constraint,
|
|
20
20
|
reference_period_constraint,
|
|
21
21
|
)
|
|
22
22
|
from hapi_schema.utils.enums import PovertyClassification
|
|
@@ -27,7 +27,7 @@ from hapi_schema.utils.view_params import ViewParams
|
|
|
27
27
|
class DBPovertyRate(Base):
|
|
28
28
|
__tablename__ = "poverty_rate"
|
|
29
29
|
__table_args__ = (
|
|
30
|
-
|
|
30
|
+
rate_constraint(),
|
|
31
31
|
reference_period_constraint(),
|
|
32
32
|
)
|
|
33
33
|
|
|
@@ -35,15 +35,18 @@ class DBPovertyRate(Base):
|
|
|
35
35
|
ForeignKey("resource.hdx_id", onupdate="CASCADE", ondelete="CASCADE"),
|
|
36
36
|
nullable=False,
|
|
37
37
|
)
|
|
38
|
-
|
|
39
|
-
ForeignKey("
|
|
38
|
+
location_ref: Mapped[int] = mapped_column(
|
|
39
|
+
ForeignKey("location.id", onupdate="CASCADE"),
|
|
40
40
|
nullable=False,
|
|
41
41
|
primary_key=True,
|
|
42
42
|
)
|
|
43
|
+
admin1_name: Mapped[str] = mapped_column(
|
|
44
|
+
String(512), nullable=False, index=True, primary_key=True
|
|
45
|
+
)
|
|
43
46
|
classification: Mapped[PovertyClassification] = mapped_column(
|
|
44
47
|
Enum(PovertyClassification), nullable=False, primary_key=True
|
|
45
48
|
)
|
|
46
|
-
|
|
49
|
+
rate: Mapped[Decimal] = mapped_column(nullable=True, index=False)
|
|
47
50
|
reference_period_start: Mapped[datetime] = mapped_column(
|
|
48
51
|
DateTime, primary_key=True
|
|
49
52
|
)
|
|
@@ -52,7 +55,7 @@ class DBPovertyRate(Base):
|
|
|
52
55
|
)
|
|
53
56
|
|
|
54
57
|
resource = relationship(DBResource)
|
|
55
|
-
|
|
58
|
+
location = relationship(DBLocation)
|
|
56
59
|
|
|
57
60
|
|
|
58
61
|
# view
|
|
@@ -63,18 +66,10 @@ view_params_poverty_rate = ViewParams(
|
|
|
63
66
|
*DBPovertyRate.__table__.columns,
|
|
64
67
|
DBLocation.code.label("location_code"),
|
|
65
68
|
DBLocation.name.label("location_name"),
|
|
66
|
-
DBAdmin1.code.label("admin1_code"),
|
|
67
|
-
DBAdmin1.name.label("admin1_name"),
|
|
68
|
-
DBAdmin1.is_unspecified.label("admin1_is_unspecified"),
|
|
69
|
-
DBAdmin1.location_ref.label("location_ref"),
|
|
70
69
|
).select_from(
|
|
71
70
|
DBPovertyRate.__table__.join(
|
|
72
|
-
DBAdmin1.__table__,
|
|
73
|
-
DBPovertyRate.admin1_ref == DBAdmin1.id,
|
|
74
|
-
isouter=True,
|
|
75
|
-
).join(
|
|
76
71
|
DBLocation.__table__,
|
|
77
|
-
|
|
72
|
+
DBPovertyRate.location_ref == DBLocation.id,
|
|
78
73
|
isouter=True,
|
|
79
74
|
)
|
|
80
75
|
),
|
|
@@ -43,6 +43,14 @@ def non_negative_constraint(
|
|
|
43
43
|
return CheckConstraint(sqltext=sqltext, name=f"{var_name}")
|
|
44
44
|
|
|
45
45
|
|
|
46
|
+
def rate_constraint(
|
|
47
|
+
var_name: str = "rate",
|
|
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"
|
|
51
|
+
return CheckConstraint(sqltext=sqltext, name=f"{var_name}")
|
|
52
|
+
|
|
53
|
+
|
|
46
54
|
def reference_period_constraint() -> CheckConstraint:
|
|
47
55
|
"""reference_period_end should be greater than reference_period_start"""
|
|
48
56
|
sqltext = "reference_period_end >= reference_period_start "
|
|
@@ -3,9 +3,10 @@ from datetime import datetime
|
|
|
3
3
|
data_poverty_rate = [
|
|
4
4
|
dict(
|
|
5
5
|
resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
|
|
6
|
-
|
|
6
|
+
location_ref=1,
|
|
7
|
+
admin1_name="Province 01", # not p-coded/normalised yet
|
|
7
8
|
classification="vulnerable",
|
|
8
|
-
|
|
9
|
+
rate=0.75,
|
|
9
10
|
reference_period_start=datetime(2024, 1, 1),
|
|
10
11
|
reference_period_end=datetime(2024, 12, 31),
|
|
11
12
|
),
|
|
@@ -20,19 +20,20 @@ def test_poverty_rate_view(run_view_test):
|
|
|
20
20
|
== "90deb235-1bf5-4bae-b231-3393222c2d01",
|
|
21
21
|
view_poverty_rate.c.location_name == "Foolandia",
|
|
22
22
|
view_poverty_rate.c.admin1_name == "Province 01",
|
|
23
|
+
view_poverty_rate.c.rate == 0.75,
|
|
23
24
|
),
|
|
24
25
|
)
|
|
25
26
|
|
|
26
27
|
|
|
27
|
-
def
|
|
28
|
-
"""Check that
|
|
28
|
+
def test_rate_constraint(run_constraints_test):
|
|
29
|
+
"""Check that rate is between 0.0 and 1.0"""
|
|
29
30
|
data = _sample_data()
|
|
30
|
-
data["
|
|
31
|
+
data["rate"] = 1.1
|
|
31
32
|
run_constraints_test(
|
|
32
33
|
new_rows=[
|
|
33
34
|
DBPovertyRate(**data),
|
|
34
35
|
],
|
|
35
|
-
expected_constraint="
|
|
36
|
+
expected_constraint="rate",
|
|
36
37
|
)
|
|
37
38
|
|
|
38
39
|
|
|
@@ -55,9 +56,10 @@ def _sample_data():
|
|
|
55
56
|
# return the whole record, then tests can change as needed
|
|
56
57
|
return dict(
|
|
57
58
|
resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
|
|
58
|
-
|
|
59
|
+
location_ref=1,
|
|
60
|
+
admin1_name="Province 01",
|
|
59
61
|
classification="vulnerable",
|
|
60
|
-
|
|
62
|
+
rate=0.75,
|
|
61
63
|
reference_period_start=datetime(2024, 1, 1),
|
|
62
64
|
reference_period_end=datetime(2024, 12, 31),
|
|
63
65
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/utils/view_as_table_code_generator.py
RENAMED
|
File without changes
|
{hapi_schema-0.8.3 → hapi_schema-0.8.4}/src/hapi_schema/utils/view_as_table_definitions.toml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|