hapi-schema 0.9.9__tar.gz → 0.9.11__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.9.9 → hapi_schema-0.9.11}/PKG-INFO +1 -1
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/changelog.md +12 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/requirements.txt +3 -3
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/_version.py +2 -2
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_funding.py +1 -3
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_population.py +1 -1
- hapi_schema-0.9.11/src/hapi_schema/db_rainfall.py +152 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_views_as_tables.py +69 -31
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/utils/endpoint_constants.py +3 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/utils/enums.py +12 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/utils/view_as_table_definitions.toml +44 -5
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/conftest.py +3 -0
- hapi_schema-0.9.11/tests/sample_data/data_rainfall.py +38 -0
- hapi_schema-0.9.11/tests/test_rainfall.py +127 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_views_as_tables.py +36 -2
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/.config/coveragerc +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/.config/pre-commit-config.yaml +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/.config/pytest.ini +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/.config/ruff.toml +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/.github/workflows/publish.yaml +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/.github/workflows/run-python-tests.yaml +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/.gitignore +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/LICENSE +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/README.md +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/contributing.md +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/docker/docker-compose.yml +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/initialize_test_db.sh +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/pyproject.toml +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/__init__.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_admin1.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_admin2.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_conflict_event.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_currency.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_dataset.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_food_price.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_food_security.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_humanitarian_needs.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_idps.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_location.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_national_risk.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_operational_presence.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_org.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_org_type.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_patch.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_poverty_rate.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_refugees.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_resource.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_returnees.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_sector.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_wfp_commodity.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/db_wfp_market.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/utils/__init__.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/utils/base.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/utils/constraints.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/utils/hapi_views_code_generator.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/utils/view_as_table_code_generator.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/utils/view_params.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/views.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/__init__.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_admin1.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_admin2.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_conflict_event.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_currency.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_dataset.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_food_price.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_food_security.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_funding.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_humanitarian_needs.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_idps.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_location.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_national_risk.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_operational_presence.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_org.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_org_type.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_patch.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_population.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_poverty_rate.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_refugees.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_resource.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_returnees.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_sector.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_wfp_commodity.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/sample_data/data_wfp_market.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_admin1.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_admin2.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_conflict_event.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_currency.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_dataset.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_food_price.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_food_security.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_funding.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_humanitarian_needs.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_idps.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_location.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_national_risk.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_operational_presence.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_org.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_org_type.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_patch.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_population.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_poverty_rate.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_refugees.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_resource.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_returnees.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_sector.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_wfp_commodity.py +0 -0
- {hapi_schema-0.9.9 → hapi_schema-0.9.11}/tests/test_wfp_market.py +0 -0
|
@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## 0.9.11
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Added Rainfall table and views
|
|
13
|
+
|
|
14
|
+
## 0.9.10
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- Align VAT definitions with database tables
|
|
19
|
+
|
|
8
20
|
## 0.9.9
|
|
9
21
|
|
|
10
22
|
### Changed
|
|
@@ -12,7 +12,7 @@ greenlet==3.1.1
|
|
|
12
12
|
# via sqlalchemy
|
|
13
13
|
hdx-python-database==1.3.5
|
|
14
14
|
# via hapi-schema (pyproject.toml)
|
|
15
|
-
identify==2.6.
|
|
15
|
+
identify==2.6.8
|
|
16
16
|
# via pre-commit
|
|
17
17
|
iniconfig==2.0.0
|
|
18
18
|
# via pytest
|
|
@@ -26,9 +26,9 @@ pluggy==1.5.0
|
|
|
26
26
|
# via pytest
|
|
27
27
|
pre-commit==4.1.0
|
|
28
28
|
# via hapi-schema (pyproject.toml)
|
|
29
|
-
psycopg==3.2.
|
|
29
|
+
psycopg==3.2.5
|
|
30
30
|
# via hapi-schema (pyproject.toml)
|
|
31
|
-
psycopg-binary==3.2.
|
|
31
|
+
psycopg-binary==3.2.5
|
|
32
32
|
# via psycopg
|
|
33
33
|
pytest==8.3.4
|
|
34
34
|
# via
|
|
@@ -8,7 +8,6 @@ from sqlalchemy import (
|
|
|
8
8
|
ForeignKey,
|
|
9
9
|
String,
|
|
10
10
|
select,
|
|
11
|
-
text,
|
|
12
11
|
)
|
|
13
12
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
14
13
|
from sqlalchemy.sql.expression import literal
|
|
@@ -71,8 +70,7 @@ class DBFunding(Base):
|
|
|
71
70
|
)
|
|
72
71
|
|
|
73
72
|
reference_period_end: Mapped[datetime] = mapped_column(
|
|
74
|
-
nullable=True
|
|
75
|
-
server_default=text("NULL"),
|
|
73
|
+
nullable=False, index=True
|
|
76
74
|
)
|
|
77
75
|
|
|
78
76
|
resource = relationship(DBResource)
|
|
@@ -57,7 +57,7 @@ class DBPopulation(Base):
|
|
|
57
57
|
Integer, nullable=False, index=True
|
|
58
58
|
)
|
|
59
59
|
reference_period_start: Mapped[datetime] = mapped_column(
|
|
60
|
-
nullable=False,
|
|
60
|
+
nullable=False, primary_key=True
|
|
61
61
|
)
|
|
62
62
|
reference_period_end: Mapped[datetime] = mapped_column(
|
|
63
63
|
nullable=False, index=True
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"""Rainfall table and view."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
from decimal import Decimal
|
|
5
|
+
|
|
6
|
+
from sqlalchemy import (
|
|
7
|
+
ForeignKey,
|
|
8
|
+
Integer,
|
|
9
|
+
String,
|
|
10
|
+
select,
|
|
11
|
+
)
|
|
12
|
+
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
13
|
+
from sqlalchemy.sql.expression import literal
|
|
14
|
+
|
|
15
|
+
from hapi_schema.db_admin1 import DBAdmin1
|
|
16
|
+
from hapi_schema.db_admin2 import DBAdmin2
|
|
17
|
+
from hapi_schema.db_location import DBLocation
|
|
18
|
+
from hapi_schema.db_resource import DBResource
|
|
19
|
+
from hapi_schema.utils import endpoint_constants
|
|
20
|
+
from hapi_schema.utils.base import Base
|
|
21
|
+
from hapi_schema.utils.constraints import (
|
|
22
|
+
greater_than_constraint,
|
|
23
|
+
non_negative_constraint,
|
|
24
|
+
reference_period_constraint,
|
|
25
|
+
)
|
|
26
|
+
from hapi_schema.utils.enums import (
|
|
27
|
+
AggregationPeriod,
|
|
28
|
+
Version,
|
|
29
|
+
build_enum_using_values,
|
|
30
|
+
)
|
|
31
|
+
from hapi_schema.utils.view_params import ViewParams
|
|
32
|
+
from hapi_schema.views import get_admin2_case
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class DBRainfall(Base):
|
|
36
|
+
__tablename__ = "rainfall"
|
|
37
|
+
__table_args__ = (
|
|
38
|
+
greater_than_constraint("number_pixels", 1),
|
|
39
|
+
non_negative_constraint(var_name="rainfall"),
|
|
40
|
+
non_negative_constraint(var_name="rainfall_long_term_average"),
|
|
41
|
+
non_negative_constraint(var_name="rainfall_anomaly_pct"),
|
|
42
|
+
reference_period_constraint(),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
resource_hdx_id: Mapped[str] = mapped_column(
|
|
46
|
+
ForeignKey("resource.hdx_id", onupdate="CASCADE", ondelete="CASCADE"),
|
|
47
|
+
nullable=False,
|
|
48
|
+
)
|
|
49
|
+
admin2_ref: Mapped[int] = mapped_column(
|
|
50
|
+
ForeignKey("admin2.id", onupdate="CASCADE"),
|
|
51
|
+
primary_key=True,
|
|
52
|
+
)
|
|
53
|
+
provider_admin1_name = mapped_column(String(512), primary_key=True)
|
|
54
|
+
provider_admin2_name = mapped_column(String(512), primary_key=True)
|
|
55
|
+
provider_admin1_code = mapped_column(String(32), primary_key=True)
|
|
56
|
+
provider_admin2_code = mapped_column(String(32), primary_key=True)
|
|
57
|
+
aggregation_period: Mapped[AggregationPeriod] = mapped_column(
|
|
58
|
+
build_enum_using_values(AggregationPeriod), primary_key=True
|
|
59
|
+
)
|
|
60
|
+
rainfall: Mapped[Decimal] = mapped_column(nullable=False)
|
|
61
|
+
rainfall_long_term_average: Mapped[Decimal] = mapped_column(nullable=False)
|
|
62
|
+
rainfall_anomaly_pct: Mapped[Decimal] = mapped_column(nullable=False)
|
|
63
|
+
number_pixels: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
64
|
+
version: Mapped[Version] = mapped_column(
|
|
65
|
+
build_enum_using_values(Version), primary_key=True
|
|
66
|
+
)
|
|
67
|
+
reference_period_start: Mapped[datetime] = mapped_column(
|
|
68
|
+
nullable=False, primary_key=True
|
|
69
|
+
)
|
|
70
|
+
reference_period_end: Mapped[datetime] = mapped_column(
|
|
71
|
+
nullable=False, index=True
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
resource = relationship(DBResource)
|
|
75
|
+
admin2 = relationship(DBAdmin2)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
view_params_rainfall = ViewParams(
|
|
79
|
+
name="rainfall_view",
|
|
80
|
+
metadata=Base.metadata,
|
|
81
|
+
selectable=select(
|
|
82
|
+
*DBRainfall.__table__.columns,
|
|
83
|
+
DBLocation.code.label("location_code"),
|
|
84
|
+
DBLocation.name.label("location_name"),
|
|
85
|
+
DBLocation.has_hrp.label("has_hrp"),
|
|
86
|
+
DBLocation.in_gho.label("in_gho"),
|
|
87
|
+
DBAdmin1.code.label("admin1_code"),
|
|
88
|
+
DBAdmin1.name.label("admin1_name"),
|
|
89
|
+
DBAdmin1.is_unspecified.label("admin1_is_unspecified"),
|
|
90
|
+
DBAdmin1.location_ref.label("location_ref"),
|
|
91
|
+
DBAdmin2.code.label("admin2_code"),
|
|
92
|
+
DBAdmin2.name.label("admin2_name"),
|
|
93
|
+
DBAdmin2.is_unspecified.label("admin2_is_unspecified"),
|
|
94
|
+
DBAdmin2.admin1_ref.label("admin1_ref"),
|
|
95
|
+
get_admin2_case(DBRainfall),
|
|
96
|
+
).select_from(
|
|
97
|
+
# Join rainfall to admin2 to admin1 to loc
|
|
98
|
+
DBRainfall.__table__.join(
|
|
99
|
+
DBAdmin2.__table__,
|
|
100
|
+
DBRainfall.admin2_ref == DBAdmin2.id,
|
|
101
|
+
isouter=True,
|
|
102
|
+
)
|
|
103
|
+
.join(
|
|
104
|
+
DBAdmin1.__table__,
|
|
105
|
+
DBAdmin2.admin1_ref == DBAdmin1.id,
|
|
106
|
+
isouter=True,
|
|
107
|
+
)
|
|
108
|
+
.join(
|
|
109
|
+
DBLocation.__table__,
|
|
110
|
+
DBAdmin1.location_ref == DBLocation.id,
|
|
111
|
+
isouter=True,
|
|
112
|
+
)
|
|
113
|
+
),
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
# Results format: category, subcategory, location_name, location_code, admin1_name, admin1_code, admin2_name, admin2_code, hapi_updated_date
|
|
117
|
+
availability_stmt_rainfall = (
|
|
118
|
+
select(
|
|
119
|
+
literal(endpoint_constants.RAINFALL_CAT).label("category"),
|
|
120
|
+
literal(endpoint_constants.RAINFALL_SUBCAT).label("subcategory"),
|
|
121
|
+
DBLocation.name.label("location_name"),
|
|
122
|
+
DBLocation.code.label("location_code"),
|
|
123
|
+
DBAdmin1.name.label("admin1_name"),
|
|
124
|
+
DBAdmin1.code.label("admin1_code"),
|
|
125
|
+
DBAdmin2.name.label("admin2_name"),
|
|
126
|
+
DBAdmin2.code.label("admin2_code"),
|
|
127
|
+
get_admin2_case(DBRainfall),
|
|
128
|
+
DBResource.hapi_updated_date,
|
|
129
|
+
)
|
|
130
|
+
.select_from(
|
|
131
|
+
DBRainfall.__table__.join(
|
|
132
|
+
DBAdmin2.__table__,
|
|
133
|
+
DBRainfall.admin2_ref == DBAdmin2.id,
|
|
134
|
+
isouter=True,
|
|
135
|
+
)
|
|
136
|
+
.join(
|
|
137
|
+
DBAdmin1.__table__,
|
|
138
|
+
DBAdmin2.admin1_ref == DBAdmin1.id,
|
|
139
|
+
isouter=True,
|
|
140
|
+
)
|
|
141
|
+
.join(
|
|
142
|
+
DBLocation.__table__,
|
|
143
|
+
DBAdmin1.location_ref == DBLocation.id,
|
|
144
|
+
isouter=True,
|
|
145
|
+
)
|
|
146
|
+
.join(
|
|
147
|
+
DBResource.__table__,
|
|
148
|
+
DBRainfall.resource_hdx_id == DBResource.hdx_id,
|
|
149
|
+
)
|
|
150
|
+
)
|
|
151
|
+
.distinct()
|
|
152
|
+
)
|
|
@@ -12,6 +12,7 @@ from sqlalchemy.orm import Mapped, mapped_column
|
|
|
12
12
|
|
|
13
13
|
from hapi_schema.utils.base import Base
|
|
14
14
|
from hapi_schema.utils.enums import (
|
|
15
|
+
AggregationPeriod,
|
|
15
16
|
CommodityCategory,
|
|
16
17
|
EventType,
|
|
17
18
|
Gender,
|
|
@@ -22,6 +23,7 @@ from hapi_schema.utils.enums import (
|
|
|
22
23
|
PriceFlag,
|
|
23
24
|
PriceType,
|
|
24
25
|
RiskClass,
|
|
26
|
+
Version,
|
|
25
27
|
build_enum_using_values,
|
|
26
28
|
)
|
|
27
29
|
|
|
@@ -35,7 +37,7 @@ class DBAdmin1VAT(Base):
|
|
|
35
37
|
is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
36
38
|
from_cods: Mapped[bool] = mapped_column(Boolean)
|
|
37
39
|
reference_period_start: Mapped[datetime] = mapped_column(
|
|
38
|
-
DateTime, index=True
|
|
40
|
+
DateTime, nullable=True, index=True
|
|
39
41
|
)
|
|
40
42
|
reference_period_end: Mapped[datetime] = mapped_column(
|
|
41
43
|
DateTime,
|
|
@@ -95,7 +97,6 @@ class DBConflictEventVAT(Base):
|
|
|
95
97
|
reference_period_end: Mapped[datetime] = mapped_column(
|
|
96
98
|
DateTime,
|
|
97
99
|
index=True,
|
|
98
|
-
nullable=True,
|
|
99
100
|
)
|
|
100
101
|
location_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
101
102
|
location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
@@ -151,7 +152,6 @@ class DBFoodPriceVAT(Base):
|
|
|
151
152
|
reference_period_end: Mapped[datetime] = mapped_column(
|
|
152
153
|
DateTime,
|
|
153
154
|
index=True,
|
|
154
|
-
nullable=True,
|
|
155
155
|
)
|
|
156
156
|
admin2_ref: Mapped[int] = mapped_column(Integer)
|
|
157
157
|
provider_admin1_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
@@ -202,7 +202,6 @@ class DBFoodSecurityVAT(Base):
|
|
|
202
202
|
reference_period_end: Mapped[datetime] = mapped_column(
|
|
203
203
|
DateTime,
|
|
204
204
|
index=True,
|
|
205
|
-
nullable=True,
|
|
206
205
|
)
|
|
207
206
|
location_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
208
207
|
location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
@@ -225,16 +224,17 @@ class DBFundingVAT(Base):
|
|
|
225
224
|
appeal_code: Mapped[str] = mapped_column(String(32), primary_key=True)
|
|
226
225
|
location_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
227
226
|
appeal_name: Mapped[str] = mapped_column(String(256))
|
|
228
|
-
appeal_type: Mapped[str] = mapped_column(String(32))
|
|
229
|
-
requirements_usd: Mapped[Decimal] = mapped_column(
|
|
227
|
+
appeal_type: Mapped[str] = mapped_column(String(32), nullable=True)
|
|
228
|
+
requirements_usd: Mapped[Decimal] = mapped_column(
|
|
229
|
+
index=True, nullable=True
|
|
230
|
+
)
|
|
230
231
|
funding_usd: Mapped[Decimal] = mapped_column(index=True)
|
|
231
|
-
funding_pct: Mapped[Decimal] = mapped_column(index=True)
|
|
232
|
+
funding_pct: Mapped[Decimal] = mapped_column(index=True, nullable=True)
|
|
232
233
|
reference_period_start: Mapped[datetime] = mapped_column(
|
|
233
|
-
DateTime,
|
|
234
|
+
DateTime, primary_key=True
|
|
234
235
|
)
|
|
235
236
|
reference_period_end: Mapped[datetime] = mapped_column(
|
|
236
|
-
DateTime,
|
|
237
|
-
nullable=True,
|
|
237
|
+
DateTime, index=True
|
|
238
238
|
)
|
|
239
239
|
location_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
240
240
|
location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
@@ -262,9 +262,7 @@ class DBHumanitarianNeedsVAT(Base):
|
|
|
262
262
|
DateTime, primary_key=True
|
|
263
263
|
)
|
|
264
264
|
reference_period_end: Mapped[datetime] = mapped_column(
|
|
265
|
-
DateTime,
|
|
266
|
-
index=True,
|
|
267
|
-
nullable=True,
|
|
265
|
+
DateTime, index=True
|
|
268
266
|
)
|
|
269
267
|
sector_name: Mapped[str] = mapped_column(String(512))
|
|
270
268
|
location_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
@@ -300,9 +298,7 @@ class DBIDPsVAT(Base):
|
|
|
300
298
|
DateTime, primary_key=True
|
|
301
299
|
)
|
|
302
300
|
reference_period_end: Mapped[datetime] = mapped_column(
|
|
303
|
-
DateTime,
|
|
304
|
-
index=True,
|
|
305
|
-
nullable=True,
|
|
301
|
+
DateTime, index=True
|
|
306
302
|
)
|
|
307
303
|
location_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
308
304
|
location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
@@ -328,7 +324,9 @@ class DBLocationVAT(Base):
|
|
|
328
324
|
has_hrp: Mapped[bool] = mapped_column(Boolean)
|
|
329
325
|
in_gho: Mapped[bool] = mapped_column(Boolean)
|
|
330
326
|
reference_period_start: Mapped[datetime] = mapped_column(
|
|
331
|
-
DateTime,
|
|
327
|
+
DateTime,
|
|
328
|
+
index=True,
|
|
329
|
+
nullable=True,
|
|
332
330
|
)
|
|
333
331
|
reference_period_end: Mapped[datetime] = mapped_column(
|
|
334
332
|
DateTime,
|
|
@@ -355,9 +353,7 @@ class DBNationalRiskVAT(Base):
|
|
|
355
353
|
DateTime, primary_key=True
|
|
356
354
|
)
|
|
357
355
|
reference_period_end: Mapped[datetime] = mapped_column(
|
|
358
|
-
DateTime,
|
|
359
|
-
index=True,
|
|
360
|
-
nullable=True,
|
|
356
|
+
DateTime, index=True
|
|
361
357
|
)
|
|
362
358
|
location_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
363
359
|
location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
@@ -441,9 +437,7 @@ class DBPopulationVAT(Base):
|
|
|
441
437
|
DateTime, primary_key=True
|
|
442
438
|
)
|
|
443
439
|
reference_period_end: Mapped[datetime] = mapped_column(
|
|
444
|
-
DateTime,
|
|
445
|
-
index=True,
|
|
446
|
-
nullable=True,
|
|
440
|
+
DateTime, index=True
|
|
447
441
|
)
|
|
448
442
|
location_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
449
443
|
location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
@@ -470,16 +464,16 @@ class DBPovertyRateVAT(Base):
|
|
|
470
464
|
)
|
|
471
465
|
mpi: Mapped[float] = mapped_column(Float)
|
|
472
466
|
headcount_ratio: Mapped[float] = mapped_column(Float)
|
|
473
|
-
intensity_of_deprivation: Mapped[float] = mapped_column(
|
|
467
|
+
intensity_of_deprivation: Mapped[float] = mapped_column(
|
|
468
|
+
Float, nullable=True
|
|
469
|
+
)
|
|
474
470
|
vulnerable_to_poverty: Mapped[float] = mapped_column(Float)
|
|
475
471
|
in_severe_poverty: Mapped[float] = mapped_column(Float)
|
|
476
472
|
reference_period_start: Mapped[datetime] = mapped_column(
|
|
477
473
|
DateTime, primary_key=True
|
|
478
474
|
)
|
|
479
475
|
reference_period_end: Mapped[datetime] = mapped_column(
|
|
480
|
-
DateTime,
|
|
481
|
-
index=True,
|
|
482
|
-
nullable=True,
|
|
476
|
+
DateTime, index=True
|
|
483
477
|
)
|
|
484
478
|
location_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
485
479
|
location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
@@ -492,6 +486,53 @@ class DBPovertyRateVAT(Base):
|
|
|
492
486
|
admin_level: Mapped[int] = mapped_column(Integer, index=True)
|
|
493
487
|
|
|
494
488
|
|
|
489
|
+
class DBRainfallVAT(Base):
|
|
490
|
+
__tablename__ = "rainfall_vat"
|
|
491
|
+
resource_hdx_id: Mapped[str] = mapped_column(String(36))
|
|
492
|
+
admin2_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
493
|
+
provider_admin1_name: Mapped[str] = mapped_column(
|
|
494
|
+
String(512), primary_key=True
|
|
495
|
+
)
|
|
496
|
+
provider_admin2_name: Mapped[str] = mapped_column(
|
|
497
|
+
String(512), primary_key=True
|
|
498
|
+
)
|
|
499
|
+
provider_admin1_code: Mapped[str] = mapped_column(
|
|
500
|
+
String(512), primary_key=True
|
|
501
|
+
)
|
|
502
|
+
provider_admin2_code: Mapped[str] = mapped_column(
|
|
503
|
+
String(512), primary_key=True
|
|
504
|
+
)
|
|
505
|
+
aggregation_period: Mapped[AggregationPeriod] = mapped_column(
|
|
506
|
+
build_enum_using_values(AggregationPeriod), primary_key=True
|
|
507
|
+
)
|
|
508
|
+
rainfall: Mapped[Decimal] = mapped_column(nullable=False)
|
|
509
|
+
rainfall_long_term_average: Mapped[Decimal] = mapped_column(nullable=False)
|
|
510
|
+
rainfall_anomaly_pct: Mapped[Decimal] = mapped_column(nullable=False)
|
|
511
|
+
number_pixels: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
512
|
+
version: Mapped[Version] = mapped_column(
|
|
513
|
+
build_enum_using_values(Version), primary_key=True
|
|
514
|
+
)
|
|
515
|
+
reference_period_start: Mapped[datetime] = mapped_column(
|
|
516
|
+
DateTime, primary_key=True
|
|
517
|
+
)
|
|
518
|
+
reference_period_end: Mapped[datetime] = mapped_column(
|
|
519
|
+
DateTime, index=True
|
|
520
|
+
)
|
|
521
|
+
location_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
522
|
+
location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
523
|
+
has_hrp: Mapped[bool] = mapped_column(Boolean)
|
|
524
|
+
in_gho: Mapped[bool] = mapped_column(Boolean)
|
|
525
|
+
admin1_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
526
|
+
admin1_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
527
|
+
admin1_is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
528
|
+
location_ref: Mapped[int] = mapped_column(Integer)
|
|
529
|
+
admin2_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
530
|
+
admin2_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
531
|
+
admin2_is_unspecified: Mapped[bool] = mapped_column(Boolean)
|
|
532
|
+
admin1_ref: Mapped[int] = mapped_column(Integer)
|
|
533
|
+
admin_level: Mapped[int] = mapped_column(Integer, index=True)
|
|
534
|
+
|
|
535
|
+
|
|
495
536
|
class DBRefugeesVAT(Base):
|
|
496
537
|
__tablename__ = "refugees_vat"
|
|
497
538
|
resource_hdx_id: Mapped[str] = mapped_column(String(36))
|
|
@@ -511,9 +552,7 @@ class DBRefugeesVAT(Base):
|
|
|
511
552
|
DateTime, primary_key=True
|
|
512
553
|
)
|
|
513
554
|
reference_period_end: Mapped[datetime] = mapped_column(
|
|
514
|
-
DateTime,
|
|
515
|
-
index=True,
|
|
516
|
-
nullable=True,
|
|
555
|
+
DateTime, index=True
|
|
517
556
|
)
|
|
518
557
|
origin_location_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
519
558
|
origin_location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
@@ -570,7 +609,6 @@ class DBReturneesVAT(Base):
|
|
|
570
609
|
reference_period_end: Mapped[datetime] = mapped_column(
|
|
571
610
|
DateTime,
|
|
572
611
|
index=True,
|
|
573
|
-
nullable=True,
|
|
574
612
|
)
|
|
575
613
|
origin_location_code: Mapped[str] = mapped_column(String(128), index=True)
|
|
576
614
|
origin_location_name: Mapped[str] = mapped_column(String(512), index=True)
|
|
@@ -5,6 +5,7 @@ Be careful when changing them as these are used to create the endpoints.
|
|
|
5
5
|
|
|
6
6
|
# categories
|
|
7
7
|
AFFECTED_PEOPLE = "affected-people"
|
|
8
|
+
CLIMATE = "climate"
|
|
8
9
|
COORDINATION_CONTEXT = "coordination-context"
|
|
9
10
|
FOOD_SECURITY = "food-security-nutrition-poverty"
|
|
10
11
|
GEOGRAPHY_INFRASTRUCTURE = "geography-infrastructure"
|
|
@@ -29,6 +30,8 @@ POPULATION_CAT = GEOGRAPHY_INFRASTRUCTURE
|
|
|
29
30
|
POPULATION_SUBCAT = "baseline-population"
|
|
30
31
|
POVERTY_RATE_CAT = FOOD_SECURITY
|
|
31
32
|
POVERTY_RATE_SUBCAT = "poverty-rate"
|
|
33
|
+
RAINFALL_CAT = CLIMATE
|
|
34
|
+
RAINFALL_SUBCAT = "hazards-rainfall"
|
|
32
35
|
REFUGEES_CAT = AFFECTED_PEOPLE
|
|
33
36
|
REFUGEES_SUBCAT = "refugees-persons-of-concern"
|
|
34
37
|
RETURNEES_CAT = AFFECTED_PEOPLE
|
|
@@ -106,3 +106,15 @@ class CommodityCategory(str, PythonEnum):
|
|
|
106
106
|
OIL_FATS = "oil and fats"
|
|
107
107
|
PULSES_NUTS = "pulses and nuts"
|
|
108
108
|
VEGETABLES_FRUITS = "vegetables and fruits"
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class AggregationPeriod(str, PythonEnum):
|
|
112
|
+
DEKAD = "dekad"
|
|
113
|
+
ONE_MONTH = "1-month"
|
|
114
|
+
THREE_MONTH = "3-month"
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
class Version(str, PythonEnum):
|
|
118
|
+
FINAL = "final"
|
|
119
|
+
FORECAST = "forecast"
|
|
120
|
+
PRELIMINARY = "preliminary"
|
{hapi_schema-0.9.9 → hapi_schema-0.9.11}/src/hapi_schema/utils/view_as_table_definitions.toml
RENAMED
|
@@ -71,10 +71,10 @@ expected_nullables = []
|
|
|
71
71
|
db_module = "db_funding"
|
|
72
72
|
target_view = "funding_view"
|
|
73
73
|
view_params_name="view_params_funding"
|
|
74
|
-
expected_primary_keys = ["appeal_code", "location_ref"]
|
|
75
|
-
expected_indexes = ["requirements_usd", "funding_usd", "funding_pct", "
|
|
74
|
+
expected_primary_keys = ["appeal_code", "location_ref", "reference_period_start"]
|
|
75
|
+
expected_indexes = ["requirements_usd", "funding_usd", "funding_pct", "reference_period_end",
|
|
76
76
|
"location_code", "location_name"]
|
|
77
|
-
expected_nullables = ["
|
|
77
|
+
expected_nullables = ["appeal_type", "requirements_usd", "funding_pct"]
|
|
78
78
|
|
|
79
79
|
[[tables]]
|
|
80
80
|
db_module = "db_humanitarian_needs"
|
|
@@ -85,6 +85,14 @@ expected_indexes = ["reference_period_end",
|
|
|
85
85
|
"location_code", "location_name", "admin1_code", "admin1_name", "admin2_code", "admin2_name"]
|
|
86
86
|
expected_nullables = []
|
|
87
87
|
|
|
88
|
+
[[tables]]
|
|
89
|
+
db_module = "db_idps"
|
|
90
|
+
target_view = "idps_view"
|
|
91
|
+
view_params_name="view_params_idps"
|
|
92
|
+
expected_primary_keys = ["admin2_ref", "assessment_type", "reporting_round", "operation", "reference_period_start"]
|
|
93
|
+
expected_indexes = ["reference_period_end", "population"]
|
|
94
|
+
expected_nullables = ["assessment_type"]
|
|
95
|
+
|
|
88
96
|
[[tables]]
|
|
89
97
|
db_module = "db_location"
|
|
90
98
|
target_view = "location_view"
|
|
@@ -117,7 +125,7 @@ expected_primary_keys = [
|
|
|
117
125
|
]
|
|
118
126
|
expected_indexes = ["org_type_description","reference_period_end", "location_code",
|
|
119
127
|
"location_name", "admin1_code", "admin1_name", "admin2_code", "admin2_name"]
|
|
120
|
-
expected_nullables = []
|
|
128
|
+
expected_nullables = ["reference_period_end"]
|
|
121
129
|
|
|
122
130
|
[[tables]]
|
|
123
131
|
db_module = "db_org_type"
|
|
@@ -162,7 +170,21 @@ expected_primary_keys = [
|
|
|
162
170
|
]
|
|
163
171
|
expected_indexes = ["reference_period_end", "location_ref", "location_code",
|
|
164
172
|
"location_name", "admin1_name"]
|
|
165
|
-
expected_nullables = ["rate"]
|
|
173
|
+
expected_nullables = ["rate", "intensity_of_deprivation"]
|
|
174
|
+
|
|
175
|
+
[[tables]]
|
|
176
|
+
db_module = "db_rainfall"
|
|
177
|
+
target_view = "rainfall_view"
|
|
178
|
+
view_params_name="view_params_rainfall"
|
|
179
|
+
expected_primary_keys = [
|
|
180
|
+
"admin2_ref",
|
|
181
|
+
"provider_admin1_code",
|
|
182
|
+
"provider_admin2_code",
|
|
183
|
+
"aggregation_period",
|
|
184
|
+
"reference_period_start"
|
|
185
|
+
]
|
|
186
|
+
expected_indexes = ["reference_period_end"]
|
|
187
|
+
expected_nullables = []
|
|
166
188
|
|
|
167
189
|
[[tables]]
|
|
168
190
|
db_module = "db_refugees"
|
|
@@ -188,6 +210,23 @@ expected_primary_keys = ["hdx_id"]
|
|
|
188
210
|
expected_indexes = ["dataset_hdx_stub", "dataset_hdx_provider_stub", "dataset_hdx_provider_name"]
|
|
189
211
|
expected_nullables = []
|
|
190
212
|
|
|
213
|
+
[[tables]]
|
|
214
|
+
db_module = "db_returnees"
|
|
215
|
+
target_view = "returnees_view"
|
|
216
|
+
view_params_name="view_params_returnees"
|
|
217
|
+
expected_primary_keys = [
|
|
218
|
+
"origin_location_ref",
|
|
219
|
+
"asylum_location_ref",
|
|
220
|
+
"population_group",
|
|
221
|
+
"gender",
|
|
222
|
+
"age_range",
|
|
223
|
+
"reference_period_start"
|
|
224
|
+
]
|
|
225
|
+
expected_indexes = ["min_age", "max_age", "population", "reference_period_end",
|
|
226
|
+
"origin_location_code", "origin_location_name",
|
|
227
|
+
"asylum_location_code", "asylum_location_name"]
|
|
228
|
+
expected_nullables = ["min_age", "max_age"]
|
|
229
|
+
|
|
191
230
|
[[tables]]
|
|
192
231
|
db_module = "db_sector"
|
|
193
232
|
target_view = "sector_view"
|
|
@@ -36,6 +36,7 @@ from hapi_schema.db_org_type import DBOrgType
|
|
|
36
36
|
from hapi_schema.db_patch import DBPatch
|
|
37
37
|
from hapi_schema.db_population import DBPopulation
|
|
38
38
|
from hapi_schema.db_poverty_rate import DBPovertyRate
|
|
39
|
+
from hapi_schema.db_rainfall import DBRainfall
|
|
39
40
|
from hapi_schema.db_refugees import DBRefugees
|
|
40
41
|
from hapi_schema.db_resource import DBResource
|
|
41
42
|
from hapi_schema.db_returnees import DBReturnees
|
|
@@ -62,6 +63,7 @@ from sample_data.data_org_type import data_org_type
|
|
|
62
63
|
from sample_data.data_patch import data_patch
|
|
63
64
|
from sample_data.data_population import data_population
|
|
64
65
|
from sample_data.data_poverty_rate import data_poverty_rate
|
|
66
|
+
from sample_data.data_rainfall import data_rainfall
|
|
65
67
|
from sample_data.data_refugees import data_refugees
|
|
66
68
|
from sample_data.data_resource import data_resource
|
|
67
69
|
from sample_data.data_returnees import data_returnees
|
|
@@ -101,6 +103,7 @@ def session():
|
|
|
101
103
|
session.execute(insert(DBPopulation), data_population)
|
|
102
104
|
session.execute(insert(DBOperationalPresence), data_operational_presence)
|
|
103
105
|
session.execute(insert(DBPovertyRate), data_poverty_rate)
|
|
106
|
+
session.execute(insert(DBRainfall), data_rainfall)
|
|
104
107
|
session.execute(insert(DBRefugees), data_refugees)
|
|
105
108
|
session.execute(insert(DBReturnees), data_returnees)
|
|
106
109
|
session.execute(insert(DBFoodSecurity), data_food_security)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
|
|
3
|
+
data_rainfall = [
|
|
4
|
+
# admin 1
|
|
5
|
+
dict(
|
|
6
|
+
resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
|
|
7
|
+
admin2_ref=2,
|
|
8
|
+
provider_admin1_name="Not provided",
|
|
9
|
+
provider_admin2_name="Not provided",
|
|
10
|
+
provider_admin1_code="393",
|
|
11
|
+
provider_admin2_code="39339",
|
|
12
|
+
aggregation_period="dekad",
|
|
13
|
+
rainfall=4.8571,
|
|
14
|
+
rainfall_long_term_average=9.4095,
|
|
15
|
+
rainfall_anomaly_pct=68.4071,
|
|
16
|
+
number_pixels=7,
|
|
17
|
+
version="final",
|
|
18
|
+
reference_period_start=datetime(2023, 1, 1),
|
|
19
|
+
reference_period_end=datetime(2023, 1, 10),
|
|
20
|
+
),
|
|
21
|
+
# admin 2
|
|
22
|
+
dict(
|
|
23
|
+
resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
|
|
24
|
+
admin2_ref=4,
|
|
25
|
+
provider_admin1_name="Not provided",
|
|
26
|
+
provider_admin2_name="Not provided",
|
|
27
|
+
provider_admin1_code="393",
|
|
28
|
+
provider_admin2_code="",
|
|
29
|
+
aggregation_period="dekad",
|
|
30
|
+
rainfall=5.8571,
|
|
31
|
+
rainfall_long_term_average=10.4095,
|
|
32
|
+
rainfall_anomaly_pct=69.4071,
|
|
33
|
+
number_pixels=5,
|
|
34
|
+
version="final",
|
|
35
|
+
reference_period_start=datetime(2023, 1, 1),
|
|
36
|
+
reference_period_end=datetime(2023, 1, 10),
|
|
37
|
+
),
|
|
38
|
+
]
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from hdx.database import Database
|
|
5
|
+
|
|
6
|
+
from hapi_schema.db_rainfall import DBRainfall, view_params_rainfall
|
|
7
|
+
from hapi_schema.utils.enums import AggregationPeriod, Version
|
|
8
|
+
from hapi_schema.views import prepare_hapi_views
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_rainfall_view(run_view_test):
|
|
12
|
+
"""Check that rainfall references other tables."""
|
|
13
|
+
view_rainfall = Database.prepare_view(view_params_rainfall.__dict__)
|
|
14
|
+
run_view_test(
|
|
15
|
+
view=view_rainfall,
|
|
16
|
+
whereclause=(
|
|
17
|
+
view_rainfall.c.resource_hdx_id
|
|
18
|
+
== "90deb235-1bf5-4bae-b231-3393222c2d01",
|
|
19
|
+
view_rainfall.c.provider_admin1_name == "Not provided",
|
|
20
|
+
view_rainfall.c.provider_admin2_name == "Not provided",
|
|
21
|
+
view_rainfall.c.provider_admin1_code == "393",
|
|
22
|
+
view_rainfall.c.provider_admin2_code == "39339",
|
|
23
|
+
view_rainfall.c.admin2_code == "FOO-001-XXX",
|
|
24
|
+
view_rainfall.c.admin1_code == "FOO-001",
|
|
25
|
+
view_rainfall.c.location_code == "FOO",
|
|
26
|
+
view_rainfall.c.admin_level == 2,
|
|
27
|
+
),
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_rainfall_availability(run_view_test):
|
|
32
|
+
view_availability = prepare_hapi_views()["data_availability"]
|
|
33
|
+
run_view_test(
|
|
34
|
+
view=view_availability,
|
|
35
|
+
whereclause=(
|
|
36
|
+
view_availability.c.category == "climate",
|
|
37
|
+
view_availability.c.subcategory == "hazards-rainfall",
|
|
38
|
+
view_availability.c.location_code == "FOO",
|
|
39
|
+
view_availability.c.admin1_name == "Province 01",
|
|
40
|
+
view_availability.c.admin2_name == "District A",
|
|
41
|
+
view_availability.c.hapi_updated_date == datetime(2023, 6, 1),
|
|
42
|
+
),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@pytest.fixture
|
|
47
|
+
def base_parameters():
|
|
48
|
+
return dict(
|
|
49
|
+
resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
|
|
50
|
+
admin2_ref=1,
|
|
51
|
+
provider_admin1_name="Not provided",
|
|
52
|
+
provider_admin2_name="Not provided",
|
|
53
|
+
provider_admin1_code="393",
|
|
54
|
+
provider_admin2_code="39339",
|
|
55
|
+
aggregation_period=AggregationPeriod.DEKAD,
|
|
56
|
+
rainfall=4.8571,
|
|
57
|
+
rainfall_long_term_average=9.4095,
|
|
58
|
+
rainfall_anomaly_pct=68.4071,
|
|
59
|
+
number_pixels=7,
|
|
60
|
+
version=Version.FINAL,
|
|
61
|
+
reference_period_start=datetime(2020, 1, 1),
|
|
62
|
+
reference_period_end=datetime(2020, 1, 10),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def test_reference_period_constraint(run_constraints_test, base_parameters):
|
|
67
|
+
"""Check that reference_period_end cannot be less than start"""
|
|
68
|
+
modified_params = {
|
|
69
|
+
**base_parameters,
|
|
70
|
+
**dict(
|
|
71
|
+
reference_period_start=datetime(2023, 1, 2),
|
|
72
|
+
reference_period_end=datetime(2023, 1, 1),
|
|
73
|
+
),
|
|
74
|
+
}
|
|
75
|
+
run_constraints_test(
|
|
76
|
+
new_rows=[DBRainfall(**modified_params)],
|
|
77
|
+
expected_constraint="reference_period_constraint",
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_rainfall_positive(run_constraints_test, base_parameters):
|
|
82
|
+
"""Check that the rainfall value is positive"""
|
|
83
|
+
modified_params = {**base_parameters, "rainfall": -1.0345}
|
|
84
|
+
run_constraints_test(
|
|
85
|
+
new_rows=[
|
|
86
|
+
DBRainfall(**modified_params),
|
|
87
|
+
],
|
|
88
|
+
expected_constraint="rainfall_constraint",
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_rainfall_long_term_average_positive(
|
|
93
|
+
run_constraints_test, base_parameters
|
|
94
|
+
):
|
|
95
|
+
"""Check that the rainfall value is positive"""
|
|
96
|
+
modified_params = {
|
|
97
|
+
**base_parameters,
|
|
98
|
+
"rainfall_long_term_average": -1.0345,
|
|
99
|
+
}
|
|
100
|
+
run_constraints_test(
|
|
101
|
+
new_rows=[
|
|
102
|
+
DBRainfall(**modified_params),
|
|
103
|
+
],
|
|
104
|
+
expected_constraint="rainfall_long_term_average_constraint",
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def test_rainfall_anomaly_pct_positive(run_constraints_test, base_parameters):
|
|
109
|
+
"""Check that the rainfall value is positive"""
|
|
110
|
+
modified_params = {**base_parameters, "rainfall_anomaly_pct": -1.0345}
|
|
111
|
+
run_constraints_test(
|
|
112
|
+
new_rows=[
|
|
113
|
+
DBRainfall(**modified_params),
|
|
114
|
+
],
|
|
115
|
+
expected_constraint="rainfall_anomaly_pct_constraint",
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def test_number_pixels_positive(run_constraints_test, base_parameters):
|
|
120
|
+
"""Check that the rainfall value is positive"""
|
|
121
|
+
modified_params = {**base_parameters, "number_pixels": 0}
|
|
122
|
+
run_constraints_test(
|
|
123
|
+
new_rows=[
|
|
124
|
+
DBRainfall(**modified_params),
|
|
125
|
+
],
|
|
126
|
+
expected_constraint="number_pixels_constraint",
|
|
127
|
+
)
|
|
@@ -18,6 +18,7 @@ from hapi_schema.db_org_type import view_params_org_type
|
|
|
18
18
|
from hapi_schema.db_patch import view_params_patch
|
|
19
19
|
from hapi_schema.db_population import view_params_population
|
|
20
20
|
from hapi_schema.db_poverty_rate import view_params_poverty_rate
|
|
21
|
+
from hapi_schema.db_rainfall import view_params_rainfall
|
|
21
22
|
from hapi_schema.db_refugees import view_params_refugees
|
|
22
23
|
from hapi_schema.db_resource import view_params_resource
|
|
23
24
|
from hapi_schema.db_returnees import view_params_returnees
|
|
@@ -181,12 +182,16 @@ def test_funding_vat(
|
|
|
181
182
|
run_indexes_test, run_columns_test, run_primary_keys_test
|
|
182
183
|
):
|
|
183
184
|
"""Check that funding_vat is correct - columns match, expected indexes present"""
|
|
184
|
-
expected_primary_keys = [
|
|
185
|
+
expected_primary_keys = [
|
|
186
|
+
"appeal_code",
|
|
187
|
+
"location_ref",
|
|
188
|
+
"reference_period_start",
|
|
189
|
+
]
|
|
185
190
|
expected_indexes = [
|
|
186
191
|
"requirements_usd",
|
|
187
192
|
"funding_usd",
|
|
188
193
|
"funding_pct",
|
|
189
|
-
"
|
|
194
|
+
"reference_period_end",
|
|
190
195
|
"location_code",
|
|
191
196
|
"location_name",
|
|
192
197
|
]
|
|
@@ -409,6 +414,35 @@ def test_poverty_rate_vat(
|
|
|
409
414
|
run_primary_keys_test("poverty_rate_vat", expected_primary_keys)
|
|
410
415
|
|
|
411
416
|
|
|
417
|
+
def test_rainfall_vat(
|
|
418
|
+
run_indexes_test, run_columns_test, run_primary_keys_test
|
|
419
|
+
):
|
|
420
|
+
"""Check that rainfall_vat is correct - columns match, expected indexes present"""
|
|
421
|
+
expected_primary_keys = [
|
|
422
|
+
"admin2_ref",
|
|
423
|
+
"provider_admin1_name",
|
|
424
|
+
"provider_admin2_name",
|
|
425
|
+
"provider_admin1_code",
|
|
426
|
+
"provider_admin2_code",
|
|
427
|
+
"aggregation_period",
|
|
428
|
+
"version",
|
|
429
|
+
"reference_period_start",
|
|
430
|
+
]
|
|
431
|
+
expected_indexes = [
|
|
432
|
+
"reference_period_end",
|
|
433
|
+
"location_code",
|
|
434
|
+
"location_name",
|
|
435
|
+
"admin1_code",
|
|
436
|
+
"admin1_name",
|
|
437
|
+
"admin2_code",
|
|
438
|
+
"admin2_name",
|
|
439
|
+
"admin_level",
|
|
440
|
+
]
|
|
441
|
+
run_columns_test("rainfall_vat", "rainfall_view", view_params_rainfall)
|
|
442
|
+
run_indexes_test("rainfall_vat", expected_indexes)
|
|
443
|
+
run_primary_keys_test("rainfall_vat", expected_primary_keys)
|
|
444
|
+
|
|
445
|
+
|
|
412
446
|
def test_refugees_vat(
|
|
413
447
|
run_indexes_test, run_columns_test, run_primary_keys_test
|
|
414
448
|
):
|
|
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.9.9 → hapi_schema-0.9.11}/src/hapi_schema/utils/view_as_table_code_generator.py
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|