hapi-schema 0.8.0__tar.gz → 0.8.2__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.0 → hapi_schema-0.8.2}/PKG-INFO +1 -1
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/changelog.md +21 -4
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/_version.py +2 -2
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/db_admin1.py +3 -17
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/db_admin2.py +3 -20
- hapi_schema-0.8.2/src/hapi_schema/db_currency.py +21 -0
- hapi_schema-0.8.2/src/hapi_schema/db_food_price.py +126 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/db_food_security.py +0 -36
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/db_humanitarian_needs.py +0 -37
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/db_location.py +4 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/db_national_risk.py +0 -23
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/db_operational_presence.py +0 -31
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/db_org.py +0 -8
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/db_patch.py +25 -7
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/db_population.py +0 -28
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/db_refugees.py +2 -1
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/db_resource.py +0 -18
- hapi_schema-0.8.2/src/hapi_schema/db_views_as_tables.py +301 -0
- hapi_schema-0.8.2/src/hapi_schema/db_wfp_commodity.py +25 -0
- hapi_schema-0.8.2/src/hapi_schema/db_wfp_market.py +63 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/utils/constraints.py +14 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/utils/enums.py +23 -0
- hapi_schema-0.8.2/src/hapi_schema/utils/hapi_views_code_generator.py +213 -0
- hapi_schema-0.8.2/src/hapi_schema/utils/view_as_table_code_generator.py +191 -0
- hapi_schema-0.8.2/src/hapi_schema/utils/view_as_table_definitions.toml +159 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/conftest.py +14 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/sample_data/data_admin1.py +1 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/sample_data/data_admin2.py +3 -0
- hapi_schema-0.8.2/tests/sample_data/data_currency.py +10 -0
- hapi_schema-0.8.2/tests/sample_data/data_food_price.py +30 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/sample_data/data_location.py +1 -0
- hapi_schema-0.8.2/tests/sample_data/data_wfp_commodity.py +12 -0
- hapi_schema-0.8.2/tests/sample_data/data_wfp_market.py +9 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/test_admin1.py +10 -10
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/test_admin2.py +10 -13
- hapi_schema-0.8.2/tests/test_currency.py +15 -0
- hapi_schema-0.8.2/tests/test_food_price.py +78 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/test_food_security.py +0 -19
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/test_humanitarian_needs.py +0 -19
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/test_location.py +12 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/test_national_risk.py +0 -18
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/test_operational_presence.py +0 -27
- hapi_schema-0.8.2/tests/test_org.py +15 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/test_patch.py +1 -3
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/test_population.py +0 -25
- hapi_schema-0.8.2/tests/test_resource.py +15 -0
- hapi_schema-0.8.2/tests/test_views_as_tables.py +312 -0
- hapi_schema-0.8.2/tests/test_wfp_commodity.py +18 -0
- hapi_schema-0.8.2/tests/test_wfp_market.py +61 -0
- hapi_schema-0.8.0/src/hapi_schema/utils/view_as_table_code_generator.py +0 -125
- hapi_schema-0.8.0/tests/test_org.py +0 -32
- hapi_schema-0.8.0/tests/test_resource.py +0 -33
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/.config/coveragerc +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/.config/pre-commit-config.yaml +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/.config/pytest.ini +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/.config/ruff.toml +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/.github/workflows/publish.yaml +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/.github/workflows/run-python-tests.yaml +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/.gitignore +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/LICENSE +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/README.md +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/contributing.md +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/docker/docker-compose.yml +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/initialize_test_db.sh +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/pyproject.toml +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/requirements.txt +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/__init__.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/db_conflict_event.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/db_dataset.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/db_funding.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/db_org_type.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/db_poverty_rate.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/db_sector.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/utils/__init__.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/utils/base.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/utils/view_params.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/src/hapi_schema/views.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/sample_data/__init__.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/sample_data/data_conflict_event.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/sample_data/data_dataset.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/sample_data/data_food_security.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/sample_data/data_funding.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/sample_data/data_humanitarian_needs.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/sample_data/data_national_risk.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/sample_data/data_operational_presence.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/sample_data/data_org.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/sample_data/data_org_type.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/sample_data/data_patch.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/sample_data/data_population.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/sample_data/data_poverty_rate.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/sample_data/data_refugees.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/sample_data/data_resource.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/sample_data/data_sector.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/test_conflict_event.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/test_dataset.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/test_funding.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/test_org_type.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/test_poverty_rate.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/test_refugees.py +0 -0
- {hapi_schema-0.8.0 → hapi_schema-0.8.2}/tests/test_sector.py +0 -0
|
@@ -5,6 +5,24 @@ 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.2
|
|
9
|
+
|
|
10
|
+
Miscellaneous fixes for pipelines
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
- added from\_cods column to location, admin1, and admin2
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## 0.8.1
|
|
17
|
+
|
|
18
|
+
Implemented the Food Prices subcategory.
|
|
19
|
+
|
|
20
|
+
### Added
|
|
21
|
+
- New tables and views: food\_price, wfp\_commodity, wfp\_market, currency
|
|
22
|
+
- New enums: PriceFlag, PriceType, CommodityCategory
|
|
23
|
+
- New constraints: non\_negative\_constraint, latlon\_constraint
|
|
24
|
+
|
|
25
|
+
|
|
8
26
|
## 0.8.0
|
|
9
27
|
|
|
10
28
|
### Changed
|
|
@@ -17,14 +35,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
17
35
|
- Programmatically obtain views
|
|
18
36
|
|
|
19
37
|
### Added
|
|
20
|
-
- New tables: humanitarian\_needs, funding, refugees, conflict\
|
|
21
|
-
- New enums: Gender, DisabledMarker, EventType, PopulationGroup, PopulationStatus, IPCPhase, PovertyClassification
|
|
22
|
-
IPCType, and RiskClass
|
|
38
|
+
- New tables: humanitarian\_needs, funding, refugees, conflict\_event, poverty\_rate
|
|
39
|
+
- New enums: Gender, DisabledMarker, EventType, PopulationGroup, PopulationStatus, IPCPhase, PovertyClassification, IPCType, and RiskClass
|
|
23
40
|
- Generalized constraints
|
|
24
41
|
|
|
25
42
|
### Removed
|
|
26
43
|
|
|
27
|
-
-
|
|
44
|
+
- ipc\_phase, ipc\_type, age\_range, and gender tables
|
|
28
45
|
|
|
29
46
|
|
|
30
47
|
## [0.7.3]
|
|
@@ -39,6 +39,9 @@ class DBAdmin1(Base):
|
|
|
39
39
|
is_unspecified: Mapped[bool] = mapped_column(
|
|
40
40
|
Boolean, server_default=text("FALSE"), nullable=False
|
|
41
41
|
)
|
|
42
|
+
from_cods: Mapped[bool] = mapped_column(
|
|
43
|
+
Boolean, nullable=False, server_default=text("TRUE")
|
|
44
|
+
)
|
|
42
45
|
reference_period_start: Mapped[datetime] = mapped_column(
|
|
43
46
|
DateTime, nullable=True, server_default=text("NULL"), index=True
|
|
44
47
|
)
|
|
@@ -64,20 +67,3 @@ view_params_admin1 = ViewParams(
|
|
|
64
67
|
)
|
|
65
68
|
),
|
|
66
69
|
)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
class DBAdmin1VAT(Base):
|
|
70
|
-
__tablename__ = "admin1_vat"
|
|
71
|
-
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
72
|
-
location_ref: Mapped[int] = mapped_column(Integer)
|
|
73
|
-
code: Mapped[str] = mapped_column(String(128))
|
|
74
|
-
name: Mapped[str] = mapped_column(String(512))
|
|
75
|
-
is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
76
|
-
reference_period_start: Mapped[datetime] = mapped_column(
|
|
77
|
-
DateTime, index=True
|
|
78
|
-
)
|
|
79
|
-
reference_period_end: Mapped[datetime] = mapped_column(
|
|
80
|
-
DateTime, index=True
|
|
81
|
-
)
|
|
82
|
-
location_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
83
|
-
location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
@@ -40,6 +40,9 @@ class DBAdmin2(Base):
|
|
|
40
40
|
is_unspecified: Mapped[bool] = mapped_column(
|
|
41
41
|
Boolean, server_default=text("FALSE"), nullable=False
|
|
42
42
|
)
|
|
43
|
+
from_cods: Mapped[bool] = mapped_column(
|
|
44
|
+
Boolean, nullable=False, server_default=text("TRUE")
|
|
45
|
+
)
|
|
43
46
|
reference_period_start: Mapped[datetime] = mapped_column(
|
|
44
47
|
DateTime, nullable=True, server_default=text("NULL"), index=True
|
|
45
48
|
)
|
|
@@ -72,23 +75,3 @@ view_params_admin2 = ViewParams(
|
|
|
72
75
|
),
|
|
73
76
|
),
|
|
74
77
|
)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
class DBAdmin2VAT(Base):
|
|
78
|
-
__tablename__ = "admin2_vat"
|
|
79
|
-
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
80
|
-
admin1_ref: Mapped[int] = mapped_column(Integer)
|
|
81
|
-
code: Mapped[str] = mapped_column(String(128), index=True)
|
|
82
|
-
name: Mapped[str] = mapped_column(String(512), index=True)
|
|
83
|
-
is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
84
|
-
reference_period_start: Mapped[datetime] = mapped_column(
|
|
85
|
-
DateTime, index=True
|
|
86
|
-
)
|
|
87
|
-
reference_period_end: Mapped[datetime] = mapped_column(
|
|
88
|
-
DateTime, index=True
|
|
89
|
-
)
|
|
90
|
-
admin1_code: Mapped[str] = mapped_column(String(128))
|
|
91
|
-
admin1_name: Mapped[str] = mapped_column(String(512))
|
|
92
|
-
admin1_is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
93
|
-
location_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
94
|
-
location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""Currency table and view."""
|
|
2
|
+
|
|
3
|
+
from sqlalchemy import String, select
|
|
4
|
+
from sqlalchemy.orm import Mapped, mapped_column
|
|
5
|
+
|
|
6
|
+
from hapi_schema.utils.base import Base
|
|
7
|
+
from hapi_schema.utils.view_params import ViewParams
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class DBCurrency(Base):
|
|
11
|
+
__tablename__ = "currency"
|
|
12
|
+
|
|
13
|
+
code: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
14
|
+
name: Mapped[str] = mapped_column(String(512), nullable=False, index=True)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
view_params_currency = ViewParams(
|
|
18
|
+
name="currency_view",
|
|
19
|
+
metadata=Base.metadata,
|
|
20
|
+
selectable=select(*DBCurrency.__table__.columns),
|
|
21
|
+
)
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""FoodPrice table and view."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
|
|
5
|
+
from sqlalchemy import (
|
|
6
|
+
DateTime,
|
|
7
|
+
Enum,
|
|
8
|
+
Float,
|
|
9
|
+
ForeignKey,
|
|
10
|
+
String,
|
|
11
|
+
select,
|
|
12
|
+
)
|
|
13
|
+
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
14
|
+
|
|
15
|
+
from hapi_schema.db_admin2 import DBAdmin1, DBAdmin2, DBLocation
|
|
16
|
+
from hapi_schema.db_currency import DBCurrency
|
|
17
|
+
from hapi_schema.db_resource import DBResource
|
|
18
|
+
from hapi_schema.db_wfp_commodity import DBWFPCommodity
|
|
19
|
+
from hapi_schema.db_wfp_market import DBWFPMarket
|
|
20
|
+
from hapi_schema.utils.base import Base
|
|
21
|
+
from hapi_schema.utils.constraints import (
|
|
22
|
+
non_negative_constraint,
|
|
23
|
+
reference_period_constraint,
|
|
24
|
+
)
|
|
25
|
+
from hapi_schema.utils.enums import PriceFlag, PriceType
|
|
26
|
+
from hapi_schema.utils.view_params import ViewParams
|
|
27
|
+
|
|
28
|
+
# normalised table
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class DBFoodPrice(Base):
|
|
32
|
+
__tablename__ = "food_price"
|
|
33
|
+
__table_args__ = (
|
|
34
|
+
non_negative_constraint(var_name="price"),
|
|
35
|
+
reference_period_constraint(),
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
resource_hdx_id: Mapped[str] = mapped_column(
|
|
39
|
+
ForeignKey("resource.hdx_id", onupdate="CASCADE", ondelete="CASCADE"),
|
|
40
|
+
nullable=False,
|
|
41
|
+
)
|
|
42
|
+
market_code: Mapped[str] = mapped_column(
|
|
43
|
+
ForeignKey("wfp_market.code"), primary_key=True
|
|
44
|
+
)
|
|
45
|
+
commodity_code: Mapped[str] = mapped_column(
|
|
46
|
+
ForeignKey("wfp_commodity.code"), primary_key=True
|
|
47
|
+
)
|
|
48
|
+
currency_code: Mapped[str] = mapped_column(
|
|
49
|
+
ForeignKey("currency.code", onupdate="CASCADE"),
|
|
50
|
+
nullable=False,
|
|
51
|
+
index=True,
|
|
52
|
+
)
|
|
53
|
+
unit: Mapped[str] = mapped_column(String(32), nullable=False)
|
|
54
|
+
price_flag: Mapped[PriceFlag] = mapped_column(
|
|
55
|
+
Enum(PriceFlag), primary_key=True
|
|
56
|
+
)
|
|
57
|
+
price_type: Mapped[PriceType] = mapped_column(
|
|
58
|
+
Enum(PriceType), primary_key=True
|
|
59
|
+
)
|
|
60
|
+
price: Mapped[float] = mapped_column(Float, nullable=False)
|
|
61
|
+
reference_period_start: Mapped[datetime] = mapped_column(
|
|
62
|
+
DateTime, primary_key=True
|
|
63
|
+
)
|
|
64
|
+
reference_period_end: Mapped[datetime] = mapped_column(
|
|
65
|
+
DateTime, nullable=False, index=True
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
resource = relationship(DBResource)
|
|
69
|
+
market = relationship(DBWFPMarket)
|
|
70
|
+
commodity = relationship(DBWFPCommodity)
|
|
71
|
+
currency = relationship(DBCurrency)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
# denormalised view
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
view_params_food_price = ViewParams(
|
|
78
|
+
name="food_price_view",
|
|
79
|
+
metadata=Base.metadata,
|
|
80
|
+
selectable=select(
|
|
81
|
+
*DBFoodPrice.__table__.columns,
|
|
82
|
+
DBWFPMarket.admin2_ref.label("admin2_ref"),
|
|
83
|
+
DBWFPMarket.name.label("market_name"),
|
|
84
|
+
DBWFPMarket.lat.label("lat"),
|
|
85
|
+
DBWFPMarket.lon.label("lon"),
|
|
86
|
+
DBWFPCommodity.category.label("commodity_category"),
|
|
87
|
+
DBWFPCommodity.name.label("commodity_name"),
|
|
88
|
+
DBLocation.code.label("location_code"),
|
|
89
|
+
DBLocation.name.label("location_name"),
|
|
90
|
+
DBAdmin1.location_ref.label("location_ref"),
|
|
91
|
+
DBAdmin1.code.label("admin1_code"),
|
|
92
|
+
DBAdmin1.name.label("admin1_name"),
|
|
93
|
+
DBAdmin1.is_unspecified.label("admin1_is_unspecified"),
|
|
94
|
+
DBAdmin2.admin1_ref.label("admin1_ref"),
|
|
95
|
+
DBAdmin2.code.label("admin2_code"),
|
|
96
|
+
DBAdmin2.name.label("admin2_name"),
|
|
97
|
+
DBAdmin2.is_unspecified.label("admin2_is_unspecified"),
|
|
98
|
+
).select_from(
|
|
99
|
+
# the admin2 comes from wfp_market
|
|
100
|
+
DBFoodPrice.__table__.join(
|
|
101
|
+
DBWFPMarket.__table__,
|
|
102
|
+
DBFoodPrice.market_code == DBWFPMarket.code,
|
|
103
|
+
isouter=True,
|
|
104
|
+
)
|
|
105
|
+
.join(
|
|
106
|
+
DBAdmin2.__table__,
|
|
107
|
+
DBWFPMarket.admin2_ref == DBAdmin2.id,
|
|
108
|
+
isouter=True,
|
|
109
|
+
)
|
|
110
|
+
.join(
|
|
111
|
+
DBAdmin1.__table__,
|
|
112
|
+
DBAdmin2.admin1_ref == DBAdmin1.id,
|
|
113
|
+
isouter=True,
|
|
114
|
+
)
|
|
115
|
+
.join(
|
|
116
|
+
DBLocation.__table__,
|
|
117
|
+
DBAdmin1.location_ref == DBLocation.id,
|
|
118
|
+
isouter=True,
|
|
119
|
+
)
|
|
120
|
+
.join(
|
|
121
|
+
DBWFPCommodity.__table__,
|
|
122
|
+
DBFoodPrice.commodity_code == DBWFPCommodity.code,
|
|
123
|
+
isouter=True,
|
|
124
|
+
)
|
|
125
|
+
),
|
|
126
|
+
)
|
|
@@ -3,13 +3,11 @@
|
|
|
3
3
|
from datetime import datetime
|
|
4
4
|
|
|
5
5
|
from sqlalchemy import (
|
|
6
|
-
Boolean,
|
|
7
6
|
DateTime,
|
|
8
7
|
Enum,
|
|
9
8
|
Float,
|
|
10
9
|
ForeignKey,
|
|
11
10
|
Integer,
|
|
12
|
-
String,
|
|
13
11
|
select,
|
|
14
12
|
)
|
|
15
13
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
@@ -96,37 +94,3 @@ view_params_food_security = ViewParams(
|
|
|
96
94
|
)
|
|
97
95
|
),
|
|
98
96
|
)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
class DBFoodSecurityVAT(Base):
|
|
102
|
-
__tablename__ = "food_security_vat"
|
|
103
|
-
resource_hdx_id: Mapped[str] = mapped_column(String(36))
|
|
104
|
-
admin2_ref: Mapped[int] = mapped_column(
|
|
105
|
-
Integer, index=True, primary_key=True
|
|
106
|
-
)
|
|
107
|
-
ipc_phase: Mapped[IPCPhase] = mapped_column(
|
|
108
|
-
Enum(IPCPhase), index=True, primary_key=True
|
|
109
|
-
)
|
|
110
|
-
ipc_type: Mapped[IPCType] = mapped_column(
|
|
111
|
-
Enum(IPCType), index=True, primary_key=True
|
|
112
|
-
)
|
|
113
|
-
population_in_phase: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
114
|
-
population_fraction_in_phase: Mapped[float] = mapped_column(
|
|
115
|
-
Float, index=True, primary_key=True
|
|
116
|
-
)
|
|
117
|
-
reference_period_start: Mapped[datetime] = mapped_column(
|
|
118
|
-
DateTime, index=True
|
|
119
|
-
)
|
|
120
|
-
reference_period_end: Mapped[datetime] = mapped_column(
|
|
121
|
-
DateTime, index=True
|
|
122
|
-
)
|
|
123
|
-
location_code: Mapped[str] = mapped_column(String(128))
|
|
124
|
-
location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
125
|
-
admin1_code: Mapped[str] = mapped_column(String(128))
|
|
126
|
-
admin1_name: Mapped[str] = mapped_column(String(512))
|
|
127
|
-
admin1_is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
128
|
-
location_ref: Mapped[int] = mapped_column(Integer)
|
|
129
|
-
admin2_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
130
|
-
admin2_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
131
|
-
admin2_is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
132
|
-
admin1_ref: Mapped[int] = mapped_column(Integer)
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
from datetime import datetime
|
|
4
4
|
|
|
5
5
|
from sqlalchemy import (
|
|
6
|
-
Boolean,
|
|
7
6
|
DateTime,
|
|
8
7
|
Enum,
|
|
9
8
|
ForeignKey,
|
|
@@ -126,39 +125,3 @@ view_params_humanitarian_needs = ViewParams(
|
|
|
126
125
|
)
|
|
127
126
|
),
|
|
128
127
|
)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
class DBHumanitarianNeedsVAT(Base):
|
|
132
|
-
__tablename__ = "humanitarian_needs_vat"
|
|
133
|
-
resource_hdx_id: Mapped[str] = mapped_column(String(36))
|
|
134
|
-
admin2_ref: Mapped[int] = mapped_column(
|
|
135
|
-
Integer, index=True, primary_key=True
|
|
136
|
-
)
|
|
137
|
-
gender: Mapped[str] = mapped_column(String(11), primary_key=True)
|
|
138
|
-
age_range: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
139
|
-
min_age: Mapped[int] = mapped_column(Integer, index=True)
|
|
140
|
-
max_age: Mapped[int] = mapped_column(Integer, index=True)
|
|
141
|
-
sector_code: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
142
|
-
population_group: Mapped[str] = mapped_column(String(14), primary_key=True)
|
|
143
|
-
population_status: Mapped[str] = mapped_column(
|
|
144
|
-
String(10), primary_key=True
|
|
145
|
-
)
|
|
146
|
-
disabled_marker: Mapped[str] = mapped_column(String(3), primary_key=True)
|
|
147
|
-
population: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
148
|
-
reference_period_start: Mapped[datetime] = mapped_column(
|
|
149
|
-
DateTime, primary_key=True
|
|
150
|
-
)
|
|
151
|
-
reference_period_end: Mapped[datetime] = mapped_column(
|
|
152
|
-
DateTime, index=True
|
|
153
|
-
)
|
|
154
|
-
sector_name: Mapped[str] = mapped_column(String(512))
|
|
155
|
-
location_code: Mapped[str] = mapped_column(String(128))
|
|
156
|
-
location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
157
|
-
location_ref: Mapped[int] = mapped_column(Integer)
|
|
158
|
-
admin1_code: Mapped[str] = mapped_column(String(128))
|
|
159
|
-
admin1_name: Mapped[str] = mapped_column(String(512))
|
|
160
|
-
admin1_is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
161
|
-
admin2_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
162
|
-
admin2_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
163
|
-
admin2_is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
164
|
-
admin1_ref: Mapped[int] = mapped_column(Integer)
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
from datetime import datetime
|
|
4
4
|
|
|
5
5
|
from sqlalchemy import (
|
|
6
|
+
Boolean,
|
|
6
7
|
DateTime,
|
|
7
8
|
Integer,
|
|
8
9
|
String,
|
|
@@ -29,6 +30,9 @@ class DBLocation(Base):
|
|
|
29
30
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
30
31
|
code: Mapped[str] = mapped_column(String(128), nullable=False, index=True)
|
|
31
32
|
name: Mapped[str] = mapped_column(String(512), nullable=False, index=True)
|
|
33
|
+
from_cods: Mapped[bool] = mapped_column(
|
|
34
|
+
Boolean, nullable=False, server_default=text("TRUE")
|
|
35
|
+
)
|
|
32
36
|
reference_period_start: Mapped[datetime] = mapped_column(
|
|
33
37
|
DateTime, nullable=True, server_default=text("NULL"), index=True
|
|
34
38
|
)
|
|
@@ -9,7 +9,6 @@ from sqlalchemy import (
|
|
|
9
9
|
Float,
|
|
10
10
|
ForeignKey,
|
|
11
11
|
Integer,
|
|
12
|
-
String,
|
|
13
12
|
select,
|
|
14
13
|
)
|
|
15
14
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
@@ -93,25 +92,3 @@ view_params_national_risk = ViewParams(
|
|
|
93
92
|
)
|
|
94
93
|
),
|
|
95
94
|
)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
class DBNationalRiskVAT(Base):
|
|
99
|
-
__tablename__ = "national_risk_vat"
|
|
100
|
-
resource_hdx_id: Mapped[str] = mapped_column(String(36))
|
|
101
|
-
location_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
102
|
-
risk_class: Mapped[str] = mapped_column(String(9))
|
|
103
|
-
global_rank: Mapped[int] = mapped_column(Integer)
|
|
104
|
-
overall_risk: Mapped[float] = mapped_column(Float)
|
|
105
|
-
hazard_exposure_risk: Mapped[float] = mapped_column(Float)
|
|
106
|
-
vulnerability_risk: Mapped[float] = mapped_column(Float)
|
|
107
|
-
coping_capacity_risk: Mapped[float] = mapped_column(Float)
|
|
108
|
-
meta_missing_indicators_pct: Mapped[float] = mapped_column(Float)
|
|
109
|
-
meta_avg_recentness_years: Mapped[float] = mapped_column(Float)
|
|
110
|
-
reference_period_start: Mapped[datetime] = mapped_column(
|
|
111
|
-
DateTime, primary_key=True
|
|
112
|
-
)
|
|
113
|
-
reference_period_end: Mapped[datetime] = mapped_column(
|
|
114
|
-
DateTime, primary_key=True
|
|
115
|
-
)
|
|
116
|
-
location_code: Mapped[str] = mapped_column(String(128))
|
|
117
|
-
location_name: Mapped[str] = mapped_column(String(512))
|
|
@@ -3,11 +3,9 @@
|
|
|
3
3
|
from datetime import datetime
|
|
4
4
|
|
|
5
5
|
from sqlalchemy import (
|
|
6
|
-
Boolean,
|
|
7
6
|
DateTime,
|
|
8
7
|
ForeignKey,
|
|
9
8
|
ForeignKeyConstraint,
|
|
10
|
-
Integer,
|
|
11
9
|
String,
|
|
12
10
|
select,
|
|
13
11
|
text,
|
|
@@ -111,32 +109,3 @@ view_params_operational_presence = ViewParams(
|
|
|
111
109
|
)
|
|
112
110
|
),
|
|
113
111
|
)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
class DBOperationalPresenceVAT(Base):
|
|
117
|
-
__tablename__ = "operational_presence_vat"
|
|
118
|
-
resource_hdx_id: Mapped[str] = mapped_column(String(36))
|
|
119
|
-
admin2_ref: Mapped[int] = mapped_column(
|
|
120
|
-
Integer, primary_key=True, index=True
|
|
121
|
-
)
|
|
122
|
-
org_acronym: Mapped[str] = mapped_column(String, primary_key=True)
|
|
123
|
-
org_name: Mapped[str] = mapped_column(String, primary_key=True)
|
|
124
|
-
sector_code: Mapped[str] = mapped_column(String(32))
|
|
125
|
-
reference_period_start: Mapped[datetime] = mapped_column(
|
|
126
|
-
DateTime, primary_key=True
|
|
127
|
-
)
|
|
128
|
-
reference_period_end: Mapped[datetime] = mapped_column(
|
|
129
|
-
DateTime, index=True
|
|
130
|
-
)
|
|
131
|
-
org_type_code: Mapped[str] = mapped_column(String(32))
|
|
132
|
-
sector_name: Mapped[str] = mapped_column(String(512))
|
|
133
|
-
location_code: Mapped[str] = mapped_column(String(128))
|
|
134
|
-
location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
135
|
-
admin1_code: Mapped[str] = mapped_column(String(128))
|
|
136
|
-
admin1_name: Mapped[str] = mapped_column(String(512))
|
|
137
|
-
admin1_is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
138
|
-
location_ref: Mapped[int] = mapped_column(Integer)
|
|
139
|
-
admin2_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
140
|
-
admin2_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
141
|
-
admin2_is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
142
|
-
admin1_ref: Mapped[int] = mapped_column(Integer)
|
|
@@ -37,11 +37,3 @@ view_params_org = ViewParams(
|
|
|
37
37
|
)
|
|
38
38
|
),
|
|
39
39
|
)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
class DBOrgVAT(Base):
|
|
43
|
-
__tablename__ = "org_vat"
|
|
44
|
-
acronym: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
45
|
-
name: Mapped[str] = mapped_column(String(512), primary_key=True)
|
|
46
|
-
org_type_code: Mapped[str] = mapped_column(String(32))
|
|
47
|
-
org_type_description: Mapped[str] = mapped_column(String(512))
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
import enum
|
|
4
4
|
from datetime import datetime
|
|
5
5
|
|
|
6
|
-
from sqlalchemy import DateTime, Enum, Integer, String
|
|
6
|
+
from sqlalchemy import DateTime, Enum, Integer, String, select
|
|
7
7
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
8
8
|
|
|
9
9
|
from hapi_schema.utils.base import Base
|
|
10
|
+
from hapi_schema.utils.view_params import ViewParams
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
class StateEnum(str, enum.Enum):
|
|
@@ -24,9 +25,7 @@ class DBPatch(Base):
|
|
|
24
25
|
patch_sequence_number: Mapped[int] = mapped_column(
|
|
25
26
|
Integer, nullable=False, index=True
|
|
26
27
|
)
|
|
27
|
-
commit_hash: Mapped[str] = mapped_column(
|
|
28
|
-
String(48), unique=True, nullable=False
|
|
29
|
-
)
|
|
28
|
+
commit_hash: Mapped[str] = mapped_column(String(48), nullable=False)
|
|
30
29
|
commit_date: Mapped[datetime] = mapped_column(DateTime, nullable=False)
|
|
31
30
|
patch_path: Mapped[str] = mapped_column(
|
|
32
31
|
String(512), nullable=False, index=True
|
|
@@ -35,12 +34,31 @@ class DBPatch(Base):
|
|
|
35
34
|
String(1024), nullable=False, unique=True
|
|
36
35
|
)
|
|
37
36
|
patch_target: Mapped[str] = mapped_column(String(128), nullable=False)
|
|
38
|
-
patch_hash: Mapped[str] = mapped_column(
|
|
39
|
-
String(48), unique=True, nullable=False
|
|
40
|
-
)
|
|
37
|
+
patch_hash: Mapped[str] = mapped_column(String(48), nullable=False)
|
|
41
38
|
state: Mapped[StateEnum] = mapped_column(
|
|
42
39
|
Enum(StateEnum), nullable=False, index=True
|
|
43
40
|
)
|
|
44
41
|
execution_date: Mapped[datetime] = mapped_column(
|
|
45
42
|
DateTime, nullable=True, index=True
|
|
46
43
|
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
view_params_patch = ViewParams(
|
|
47
|
+
name="patch_view",
|
|
48
|
+
metadata=Base.metadata,
|
|
49
|
+
selectable=select(*DBPatch.__table__.columns),
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class DBPatchVAT(Base):
|
|
54
|
+
__tablename__ = "patch_vat"
|
|
55
|
+
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
56
|
+
patch_sequence_number: Mapped[int] = mapped_column(Integer, index=True)
|
|
57
|
+
commit_hash: Mapped[str] = mapped_column(String(48))
|
|
58
|
+
commit_date: Mapped[datetime] = mapped_column(DateTime)
|
|
59
|
+
patch_path: Mapped[str] = mapped_column(String(512), index=True)
|
|
60
|
+
patch_permalink_url: Mapped[str] = mapped_column(String(1024))
|
|
61
|
+
patch_target: Mapped[str] = mapped_column(String(128))
|
|
62
|
+
patch_hash: Mapped[str] = mapped_column(String(48))
|
|
63
|
+
state: Mapped[str] = mapped_column(String(10), index=True)
|
|
64
|
+
execution_date: Mapped[datetime] = mapped_column(DateTime, index=True)
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
from datetime import datetime
|
|
4
4
|
|
|
5
5
|
from sqlalchemy import (
|
|
6
|
-
Boolean,
|
|
7
6
|
DateTime,
|
|
8
7
|
Enum,
|
|
9
8
|
ForeignKey,
|
|
@@ -96,30 +95,3 @@ view_params_population = ViewParams(
|
|
|
96
95
|
)
|
|
97
96
|
),
|
|
98
97
|
)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
class DBPopulationVAT(Base):
|
|
102
|
-
__tablename__ = "population_vat"
|
|
103
|
-
resource_hdx_id: Mapped[str] = mapped_column(String(36))
|
|
104
|
-
admin2_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
105
|
-
gender: Mapped[str] = mapped_column(String(11), primary_key=True)
|
|
106
|
-
age_range: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
107
|
-
min_age: Mapped[int] = mapped_column(Integer, index=True)
|
|
108
|
-
max_age: Mapped[int] = mapped_column(Integer, index=True)
|
|
109
|
-
population: Mapped[int] = mapped_column(Integer)
|
|
110
|
-
reference_period_start: Mapped[datetime] = mapped_column(
|
|
111
|
-
DateTime, index=True
|
|
112
|
-
)
|
|
113
|
-
reference_period_end: Mapped[datetime] = mapped_column(
|
|
114
|
-
DateTime, index=True
|
|
115
|
-
)
|
|
116
|
-
location_code: Mapped[str] = mapped_column(String(128))
|
|
117
|
-
location_name: Mapped[str] = mapped_column(String(512))
|
|
118
|
-
admin1_code: Mapped[str] = mapped_column(String(128))
|
|
119
|
-
admin1_name: Mapped[str] = mapped_column(String(512))
|
|
120
|
-
admin1_is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
121
|
-
location_ref: Mapped[int] = mapped_column(Integer)
|
|
122
|
-
admin2_code: Mapped[str] = mapped_column(String(128))
|
|
123
|
-
admin2_name: Mapped[str] = mapped_column(String(512))
|
|
124
|
-
admin2_is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
125
|
-
admin1_ref: Mapped[int] = mapped_column(Integer)
|
|
@@ -64,7 +64,7 @@ class DBRefugees(Base):
|
|
|
64
64
|
DateTime, nullable=False, index=True
|
|
65
65
|
)
|
|
66
66
|
|
|
67
|
-
resource = relationship("DBResource")
|
|
67
|
+
# resource = relationship("DBResource")
|
|
68
68
|
origin_country = relationship(
|
|
69
69
|
"DBLocation", foreign_keys=(origin_location_ref)
|
|
70
70
|
)
|
|
@@ -76,6 +76,7 @@ class DBRefugees(Base):
|
|
|
76
76
|
# Use aliases because we join to DBLocation twice
|
|
77
77
|
origin_location = aliased(DBLocation)
|
|
78
78
|
asylum_location = aliased(DBLocation)
|
|
79
|
+
resource = relationship("DBResource")
|
|
79
80
|
|
|
80
81
|
view_params_refugees = ViewParams(
|
|
81
82
|
name="refugees_view",
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"""Resource table and view."""
|
|
2
2
|
|
|
3
|
-
from datetime import datetime
|
|
4
|
-
|
|
5
3
|
from sqlalchemy import (
|
|
6
4
|
Boolean,
|
|
7
5
|
DateTime,
|
|
@@ -52,19 +50,3 @@ view_params_resource = ViewParams(
|
|
|
52
50
|
)
|
|
53
51
|
),
|
|
54
52
|
)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
class DBResourceVAT(Base):
|
|
58
|
-
__tablename__ = "resource_vat"
|
|
59
|
-
hdx_id: Mapped[str] = mapped_column(String(36), primary_key=True)
|
|
60
|
-
dataset_hdx_id: Mapped[str] = mapped_column(String(36))
|
|
61
|
-
name: Mapped[str] = mapped_column(String(256))
|
|
62
|
-
format: Mapped[str] = mapped_column(String(32))
|
|
63
|
-
update_date: Mapped[datetime] = mapped_column(DateTime)
|
|
64
|
-
is_hxl: Mapped[bool] = mapped_column(Boolean)
|
|
65
|
-
download_url: Mapped[str] = mapped_column(String(1024))
|
|
66
|
-
hapi_updated_date: Mapped[datetime] = mapped_column(DateTime)
|
|
67
|
-
dataset_hdx_stub: Mapped[str] = mapped_column(String(128))
|
|
68
|
-
dataset_title: Mapped[str] = mapped_column(String(1024))
|
|
69
|
-
dataset_hdx_provider_stub: Mapped[str] = mapped_column(String(128))
|
|
70
|
-
dataset_hdx_provider_name: Mapped[str] = mapped_column(String(512))
|