hapi-schema 0.8.17__tar.gz → 0.9.0__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.
Files changed (103) hide show
  1. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/PKG-INFO +1 -1
  2. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/changelog.md +22 -0
  3. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/_version.py +2 -2
  4. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_conflict_event.py +3 -0
  5. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_food_price.py +2 -0
  6. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_food_security.py +3 -0
  7. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_funding.py +4 -5
  8. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_humanitarian_needs.py +2 -0
  9. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_idps.py +4 -0
  10. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_national_risk.py +4 -5
  11. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_operational_presence.py +2 -0
  12. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_population.py +2 -0
  13. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_poverty_rate.py +5 -6
  14. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_refugees.py +4 -5
  15. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_returnees.py +4 -5
  16. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_views_as_tables.py +45 -3
  17. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_wfp_market.py +6 -0
  18. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/utils/enums.py +1 -0
  19. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_conflict_event.py +4 -0
  20. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_food_security.py +6 -0
  21. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_humanitarian_needs.py +8 -0
  22. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_idps.py +2 -0
  23. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_operational_presence.py +10 -0
  24. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_population.py +8 -0
  25. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_poverty_rate.py +2 -2
  26. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_wfp_market.py +2 -0
  27. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_conflict_event.py +4 -0
  28. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_food_price.py +2 -0
  29. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_food_security.py +6 -0
  30. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_funding.py +2 -3
  31. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_humanitarian_needs.py +6 -0
  32. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_idps.py +4 -0
  33. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_national_risk.py +2 -3
  34. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_operational_presence.py +4 -0
  35. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_population.py +4 -0
  36. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_poverty_rate.py +2 -3
  37. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_refugees.py +2 -3
  38. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_returnees.py +2 -3
  39. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_views_as_tables.py +23 -4
  40. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_wfp_market.py +4 -0
  41. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/.config/coveragerc +0 -0
  42. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/.config/pre-commit-config.yaml +0 -0
  43. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/.config/pytest.ini +0 -0
  44. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/.config/ruff.toml +0 -0
  45. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/.github/workflows/publish.yaml +0 -0
  46. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/.github/workflows/run-python-tests.yaml +0 -0
  47. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/.gitignore +0 -0
  48. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/LICENSE +0 -0
  49. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/README.md +0 -0
  50. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/contributing.md +0 -0
  51. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/docker/docker-compose.yml +0 -0
  52. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/initialize_test_db.sh +0 -0
  53. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/pyproject.toml +0 -0
  54. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/requirements.txt +0 -0
  55. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/__init__.py +0 -0
  56. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_admin1.py +0 -0
  57. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_admin2.py +0 -0
  58. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_currency.py +0 -0
  59. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_dataset.py +0 -0
  60. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_location.py +0 -0
  61. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_org.py +0 -0
  62. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_org_type.py +0 -0
  63. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_patch.py +0 -0
  64. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_resource.py +0 -0
  65. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_sector.py +0 -0
  66. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/db_wfp_commodity.py +0 -0
  67. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/utils/__init__.py +0 -0
  68. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/utils/base.py +0 -0
  69. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/utils/constraints.py +0 -0
  70. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/utils/hapi_views_code_generator.py +0 -0
  71. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/utils/view_as_table_code_generator.py +0 -0
  72. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/utils/view_as_table_definitions.toml +0 -0
  73. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/utils/view_params.py +0 -0
  74. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/src/hapi_schema/views.py +0 -0
  75. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/conftest.py +0 -0
  76. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/__init__.py +0 -0
  77. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_admin1.py +0 -0
  78. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_admin2.py +0 -0
  79. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_currency.py +0 -0
  80. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_dataset.py +0 -0
  81. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_food_price.py +0 -0
  82. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_funding.py +0 -0
  83. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_location.py +0 -0
  84. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_national_risk.py +0 -0
  85. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_org.py +0 -0
  86. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_org_type.py +0 -0
  87. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_patch.py +0 -0
  88. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_refugees.py +0 -0
  89. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_resource.py +0 -0
  90. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_returnees.py +0 -0
  91. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_sector.py +0 -0
  92. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/sample_data/data_wfp_commodity.py +0 -0
  93. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_admin1.py +0 -0
  94. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_admin2.py +0 -0
  95. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_currency.py +0 -0
  96. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_dataset.py +0 -0
  97. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_location.py +0 -0
  98. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_org.py +0 -0
  99. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_org_type.py +0 -0
  100. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_patch.py +0 -0
  101. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_resource.py +0 -0
  102. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_sector.py +0 -0
  103. {hapi_schema-0.8.17 → hapi_schema-0.9.0}/tests/test_wfp_commodity.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: hapi-schema
3
- Version: 0.8.17
3
+ Version: 0.9.0
4
4
  Summary: HAPI database schema specified in SQLAlchemy
5
5
  Project-URL: Homepage, https://github.com/OCHA-DAP/hapi-schemas
6
6
  Author-email: Simon Johnson <simon.johnson@un.org>
@@ -5,6 +5,28 @@ 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.0
9
+
10
+ ### Added
11
+
12
+ - major refactoring to allow partial/incremental standardisation of
13
+ subnational geocodes. Added `provider_admin1_name` and
14
+ `provider_admin2_name` to the primary keys of subcategory tables
15
+ (except `food_price`), as appropriate.
16
+ - added `provider_admin1_name` and `provider_admin2_name` to `idps`,
17
+ `humanitarian_needs`, `operational_presence`, `conflict_event`,
18
+ `food_security`, `population`, and `wfp_market` (and associated views,
19
+ VATS, and tests)
20
+ - renamed existing column `admin1_name` to `provider_admin1_name` in
21
+ `povert\_rate` for consistency (and updated tests and VAT)
22
+ - updated `food_price_view` and VAT to include `provider_admin1_name` and `provider_admin2_name` from `wfp_market`
23
+ - updated `poverty_rate_view` and VAT to include `admin1_name` from `admin1` table
24
+ - made `reference_period_start` part of the primary key for `population_vat` (originally omitted in error)
25
+
26
+ ### Changed
27
+
28
+ - added "Producer" to the `PriceType` enum
29
+
8
30
  ## 0.8.17
9
31
 
10
32
  ### Added
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.8.17'
16
- __version_tuple__ = version_tuple = (0, 8, 17)
15
+ __version__ = version = '0.9.0'
16
+ __version_tuple__ = version_tuple = (0, 9, 0)
@@ -5,6 +5,7 @@ from datetime import datetime
5
5
  from sqlalchemy import (
6
6
  ForeignKey,
7
7
  Integer,
8
+ String,
8
9
  select,
9
10
  )
10
11
  from sqlalchemy.orm import Mapped, mapped_column, relationship
@@ -42,6 +43,8 @@ class DBConflictEvent(Base):
42
43
  nullable=False,
43
44
  primary_key=True,
44
45
  )
46
+ provider_admin1_name = mapped_column(String(512), primary_key=True)
47
+ provider_admin2_name = mapped_column(String(512), primary_key=True)
45
48
  event_type: Mapped[EventType] = mapped_column(
46
49
  build_enum_using_values(EventType), nullable=False, primary_key=True
47
50
  )
@@ -81,6 +81,8 @@ view_params_food_price = ViewParams(
81
81
  selectable=select(
82
82
  *DBFoodPrice.__table__.columns,
83
83
  DBWFPMarket.admin2_ref.label("admin2_ref"),
84
+ DBWFPMarket.provider_admin1_name.label("provider_admin1_name"),
85
+ DBWFPMarket.provider_admin2_name.label("provider_admin2_name"),
84
86
  DBWFPMarket.name.label("market_name"),
85
87
  DBWFPMarket.lat.label("lat"),
86
88
  DBWFPMarket.lon.label("lon"),
@@ -7,6 +7,7 @@ from sqlalchemy import (
7
7
  Float,
8
8
  ForeignKey,
9
9
  Integer,
10
+ String,
10
11
  select,
11
12
  )
12
13
  from sqlalchemy.orm import Mapped, mapped_column, relationship
@@ -39,6 +40,8 @@ class DBFoodSecurity(Base):
39
40
  admin2_ref: Mapped[int] = mapped_column(
40
41
  ForeignKey("admin2.id", onupdate="CASCADE"), primary_key=True
41
42
  )
43
+ provider_admin1_name = mapped_column(String(512), primary_key=True)
44
+ provider_admin2_name = mapped_column(String(512), primary_key=True)
42
45
  ipc_phase: Mapped[IPCPhase] = mapped_column(
43
46
  build_enum_using_values(IPCPhase), primary_key=True
44
47
  )
@@ -11,7 +11,6 @@ from sqlalchemy import (
11
11
  text,
12
12
  )
13
13
  from sqlalchemy.orm import Mapped, mapped_column, relationship
14
- from sqlalchemy.sql import null
15
14
  from sqlalchemy.sql.expression import literal
16
15
 
17
16
  from hapi_schema.db_location import DBLocation
@@ -104,10 +103,10 @@ availability_stmt_funding = (
104
103
  literal("funding").label("subcategory"),
105
104
  DBLocation.name.label("location_name"),
106
105
  DBLocation.code.label("location_code"),
107
- null().label("admin1_name"),
108
- null().label("admin1_code"),
109
- null().label("admin2_name"),
110
- null().label("admin2_code"),
106
+ literal("").label("admin1_name"),
107
+ literal("").label("admin1_code"),
108
+ literal("").label("admin2_name"),
109
+ literal("").label("admin2_code"),
111
110
  DBResource.hapi_updated_date,
112
111
  )
113
112
  .select_from(
@@ -50,6 +50,8 @@ class DBHumanitarianNeeds(Base):
50
50
  ForeignKey("admin2.id", onupdate="CASCADE"),
51
51
  primary_key=True,
52
52
  )
53
+ provider_admin1_name = mapped_column(String(512), primary_key=True)
54
+ provider_admin2_name = mapped_column(String(512), primary_key=True)
53
55
  gender: Mapped[Gender] = mapped_column(
54
56
  build_enum_using_values(Gender), primary_key=True
55
57
  )
@@ -43,6 +43,10 @@ class DBIDPs(Base):
43
43
  ForeignKey("admin2.id", onupdate="CASCADE"), primary_key=True
44
44
  )
45
45
 
46
+ provider_admin1_name = mapped_column(String(512), primary_key=True)
47
+
48
+ provider_admin2_name = mapped_column(String(512), primary_key=True)
49
+
46
50
  assessment_type: Mapped[DTMAssessmentType] = mapped_column(
47
51
  build_enum_using_values(DTMAssessmentType), primary_key=True
48
52
  )
@@ -11,7 +11,6 @@ from sqlalchemy import (
11
11
  select,
12
12
  )
13
13
  from sqlalchemy.orm import Mapped, mapped_column, relationship
14
- from sqlalchemy.sql import null
15
14
  from sqlalchemy.sql.expression import literal
16
15
 
17
16
  from hapi_schema.db_location import DBLocation
@@ -107,10 +106,10 @@ availability_stmt_national_risk = (
107
106
  literal("national-risk").label("subcategory"),
108
107
  DBLocation.name.label("location_name"),
109
108
  DBLocation.code.label("location_code"),
110
- null().label("admin1_name"),
111
- null().label("admin1_code"),
112
- null().label("admin2_name"),
113
- null().label("admin2_code"),
109
+ literal("").label("admin1_name"),
110
+ literal("").label("admin1_code"),
111
+ literal("").label("admin2_name"),
112
+ literal("").label("admin2_code"),
114
113
  DBResource.hapi_updated_date,
115
114
  )
116
115
  .select_from(
@@ -42,6 +42,8 @@ class DBOperationalPresence(Base):
42
42
  admin2_ref: Mapped[int] = mapped_column(
43
43
  ForeignKey("admin2.id", onupdate="CASCADE"), primary_key=True
44
44
  )
45
+ provider_admin1_name = mapped_column(String(512), primary_key=True)
46
+ provider_admin2_name = mapped_column(String(512), primary_key=True)
45
47
  # Foreign key
46
48
  org_acronym: Mapped[str] = mapped_column(String, primary_key=True)
47
49
  # Foreign key
@@ -43,6 +43,8 @@ class DBPopulation(Base):
43
43
  ForeignKey("admin2.id", onupdate="CASCADE"),
44
44
  primary_key=True,
45
45
  )
46
+ provider_admin1_name = mapped_column(String(512), primary_key=True)
47
+ provider_admin2_name = mapped_column(String(512), primary_key=True)
46
48
  gender: Mapped[Gender] = mapped_column(
47
49
  build_enum_using_values(Gender), primary_key=True
48
50
  )
@@ -10,7 +10,6 @@ from sqlalchemy import (
10
10
  )
11
11
  from sqlalchemy.orm import Mapped, mapped_column, relationship
12
12
  from sqlalchemy.schema import CheckConstraint
13
- from sqlalchemy.sql import null
14
13
  from sqlalchemy.sql.expression import literal
15
14
 
16
15
  from hapi_schema.db_admin1 import DBAdmin1
@@ -48,8 +47,7 @@ class DBPovertyRate(Base):
48
47
  nullable=False,
49
48
  primary_key=True,
50
49
  )
51
- # TODO temporary -- will remove in future release and use name from admin1 table
52
- admin1_name: Mapped[str] = mapped_column(
50
+ provider_admin1_name: Mapped[str] = mapped_column(
53
51
  String(512), nullable=False, index=True, primary_key=True
54
52
  )
55
53
  mpi: Mapped[float] = mapped_column(Float, nullable=False, index=False)
@@ -84,6 +82,7 @@ view_params_poverty_rate = ViewParams(
84
82
  DBLocation.name.label("location_name"),
85
83
  DBLocation.has_hrp.label("has_hrp"),
86
84
  DBLocation.in_gho.label("in_gho"),
85
+ DBAdmin1.name.label("admin1_name"),
87
86
  DBAdmin1.code.label("admin1_code"),
88
87
  DBAdmin1.is_unspecified.label("admin1_is_unspecified"),
89
88
  DBAdmin1.location_ref.label("location_ref"),
@@ -108,10 +107,10 @@ availability_stmt_poverty_rate = (
108
107
  literal("poverty-rate").label("subcategory"),
109
108
  DBLocation.name.label("location_name"),
110
109
  DBLocation.code.label("location_code"),
111
- DBPovertyRate.admin1_name, # fixme
110
+ DBAdmin1.name.label("admin1_name"),
112
111
  DBAdmin1.code.label("admin1_code"),
113
- null().label("admin2_name"),
114
- null().label("admin2_code"),
112
+ literal("").label("admin2_name"),
113
+ literal("").label("admin2_code"),
115
114
  DBResource.hapi_updated_date,
116
115
  )
117
116
  .select_from(
@@ -12,7 +12,6 @@ from sqlalchemy import (
12
12
  select,
13
13
  )
14
14
  from sqlalchemy.orm import Mapped, aliased, mapped_column, relationship
15
- from sqlalchemy.sql import null
16
15
  from sqlalchemy.sql.expression import literal
17
16
 
18
17
  from hapi_schema.db_location import DBLocation
@@ -117,10 +116,10 @@ availability_stmt_refugees = (
117
116
  literal("refugees").label("subcategory"),
118
117
  DBLocation.name.label("location_name"),
119
118
  DBLocation.code.label("location_code"),
120
- null().label("admin1_name"),
121
- null().label("admin1_code"),
122
- null().label("admin2_name"),
123
- null().label("admin2_code"),
119
+ literal("").label("admin1_name"),
120
+ literal("").label("admin1_code"),
121
+ literal("").label("admin2_name"),
122
+ literal("").label("admin2_code"),
124
123
  DBResource.hapi_updated_date,
125
124
  )
126
125
  .select_from(
@@ -13,7 +13,6 @@ from sqlalchemy import (
13
13
  select,
14
14
  )
15
15
  from sqlalchemy.orm import Mapped, aliased, mapped_column, relationship
16
- from sqlalchemy.sql import null
17
16
  from sqlalchemy.sql.expression import literal
18
17
 
19
18
  from hapi_schema.db_location import DBLocation
@@ -120,10 +119,10 @@ availability_stmt_returnees = (
120
119
  literal("returnees").label("subcategory"),
121
120
  DBLocation.name.label("location_name"),
122
121
  DBLocation.code.label("location_code"),
123
- null().label("admin1_name"),
124
- null().label("admin1_code"),
125
- null().label("admin2_name"),
126
- null().label("admin2_code"),
122
+ literal("").label("admin1_name"),
123
+ literal("").label("admin1_code"),
124
+ literal("").label("admin2_name"),
125
+ literal("").label("admin2_code"),
127
126
  DBResource.hapi_updated_date,
128
127
  )
129
128
  .select_from(
@@ -79,6 +79,12 @@ class DBConflictEventVAT(Base):
79
79
  __tablename__ = "conflict_event_vat"
80
80
  resource_hdx_id: Mapped[str] = mapped_column(String(36))
81
81
  admin2_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
82
+ provider_admin1_name: Mapped[str] = mapped_column(
83
+ String(512), primary_key=True
84
+ )
85
+ provider_admin2_name: Mapped[str] = mapped_column(
86
+ String(512), primary_key=True
87
+ )
82
88
  event_type: Mapped[EventType] = mapped_column(
83
89
  build_enum_using_values(EventType), primary_key=True
84
90
  )
@@ -148,6 +154,8 @@ class DBFoodPriceVAT(Base):
148
154
  nullable=True,
149
155
  )
150
156
  admin2_ref: Mapped[int] = mapped_column(Integer)
157
+ provider_admin1_name: Mapped[str] = mapped_column(String(512), index=True)
158
+ provider_admin2_name: Mapped[str] = mapped_column(String(512), index=True)
151
159
  market_name: Mapped[str] = mapped_column(String(512), index=True)
152
160
  lat: Mapped[float] = mapped_column(Float, index=True)
153
161
  lon: Mapped[float] = mapped_column(Float, index=True)
@@ -173,6 +181,12 @@ class DBFoodSecurityVAT(Base):
173
181
  __tablename__ = "food_security_vat"
174
182
  resource_hdx_id: Mapped[str] = mapped_column(String(36))
175
183
  admin2_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
184
+ provider_admin1_name: Mapped[str] = mapped_column(
185
+ String(512), primary_key=True
186
+ )
187
+ provider_admin2_name: Mapped[str] = mapped_column(
188
+ String(512), primary_key=True
189
+ )
176
190
  ipc_phase: Mapped[IPCPhase] = mapped_column(
177
191
  build_enum_using_values(IPCPhase), primary_key=True
178
192
  )
@@ -230,6 +244,12 @@ class DBHumanitarianNeedsVAT(Base):
230
244
  __tablename__ = "humanitarian_needs_vat"
231
245
  resource_hdx_id: Mapped[str] = mapped_column(String(36))
232
246
  admin2_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
247
+ provider_admin1_name: Mapped[str] = mapped_column(
248
+ String(512), primary_key=True
249
+ )
250
+ provider_admin2_name: Mapped[str] = mapped_column(
251
+ String(512), primary_key=True
252
+ )
233
253
  gender: Mapped[Gender] = mapped_column(
234
254
  build_enum_using_values(Gender), primary_key=True
235
255
  )
@@ -274,6 +294,12 @@ class DBIDPsVAT(Base):
274
294
  __tablename__ = "idps_vat"
275
295
  resource_hdx_id: Mapped[str] = mapped_column(String(36))
276
296
  admin2_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
297
+ provider_admin1_name: Mapped[str] = mapped_column(
298
+ String(512), primary_key=True
299
+ )
300
+ provider_admin2_name: Mapped[str] = mapped_column(
301
+ String(512), primary_key=True
302
+ )
277
303
  assessment_type: Mapped[str] = mapped_column(String(32), primary_key=True)
278
304
  reporting_round: Mapped[int] = mapped_column(Integer, primary_key=True)
279
305
  operation: Mapped[str] = mapped_column(String, primary_key=True)
@@ -350,6 +376,12 @@ class DBOperationalPresenceVAT(Base):
350
376
  __tablename__ = "operational_presence_vat"
351
377
  resource_hdx_id: Mapped[str] = mapped_column(String(36))
352
378
  admin2_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
379
+ provider_admin1_name: Mapped[str] = mapped_column(
380
+ String(512), primary_key=True
381
+ )
382
+ provider_admin2_name: Mapped[str] = mapped_column(
383
+ String(512), primary_key=True
384
+ )
353
385
  org_acronym: Mapped[str] = mapped_column(String, primary_key=True)
354
386
  org_name: Mapped[str] = mapped_column(String, primary_key=True)
355
387
  sector_code: Mapped[str] = mapped_column(String(32), primary_key=True)
@@ -398,6 +430,12 @@ class DBPopulationVAT(Base):
398
430
  __tablename__ = "population_vat"
399
431
  resource_hdx_id: Mapped[str] = mapped_column(String(36))
400
432
  admin2_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
433
+ provider_admin1_name: Mapped[str] = mapped_column(
434
+ String(512), primary_key=True
435
+ )
436
+ provider_admin2_name: Mapped[str] = mapped_column(
437
+ String(512), primary_key=True
438
+ )
401
439
  gender: Mapped[Gender] = mapped_column(
402
440
  build_enum_using_values(Gender), primary_key=True
403
441
  )
@@ -406,7 +444,7 @@ class DBPopulationVAT(Base):
406
444
  max_age: Mapped[int] = mapped_column(Integer, nullable=True, index=True)
407
445
  population: Mapped[int] = mapped_column(Integer, index=True)
408
446
  reference_period_start: Mapped[datetime] = mapped_column(
409
- DateTime, index=True
447
+ DateTime, primary_key=True
410
448
  )
411
449
  reference_period_end: Mapped[datetime] = mapped_column(
412
450
  DateTime,
@@ -431,8 +469,9 @@ class DBPovertyRateVAT(Base):
431
469
  __tablename__ = "poverty_rate_vat"
432
470
  resource_hdx_id: Mapped[str] = mapped_column(String(36))
433
471
  admin1_ref: Mapped[int] = mapped_column(Integer, primary_key=True)
434
- admin1_name: Mapped[str] = mapped_column(
435
- String(512), primary_key=True, index=True
472
+ provider_admin1_name: Mapped[str] = mapped_column(
473
+ String(512),
474
+ primary_key=True,
436
475
  )
437
476
  mpi: Mapped[float] = mapped_column(Float)
438
477
  headcount_ratio: Mapped[float] = mapped_column(Float)
@@ -451,6 +490,7 @@ class DBPovertyRateVAT(Base):
451
490
  location_name: Mapped[str] = mapped_column(String(512), index=True)
452
491
  has_hrp: Mapped[bool] = mapped_column(Boolean)
453
492
  in_gho: Mapped[bool] = mapped_column(Boolean)
493
+ admin1_name: Mapped[str] = mapped_column(String(512))
454
494
  admin1_code: Mapped[str] = mapped_column(String(128))
455
495
  admin1_is_unspecified: Mapped[bool] = mapped_column(Boolean)
456
496
  location_ref: Mapped[int] = mapped_column(Integer, index=True)
@@ -565,6 +605,8 @@ class DBWfpMarketVAT(Base):
565
605
  __tablename__ = "wfp_market_vat"
566
606
  code: Mapped[str] = mapped_column(String(32), primary_key=True)
567
607
  admin2_ref: Mapped[int] = mapped_column(Integer)
608
+ provider_admin1_name: Mapped[str] = mapped_column(String(512), index=True)
609
+ provider_admin2_name: Mapped[str] = mapped_column(String(512), index=True)
568
610
  name: Mapped[str] = mapped_column(String(512), index=True)
569
611
  lat: Mapped[float] = mapped_column(Float, index=True)
570
612
  lon: Mapped[float] = mapped_column(Float, index=True)
@@ -20,6 +20,12 @@ class DBWFPMarket(Base):
20
20
  ForeignKey("admin2.id", onupdate="CASCADE"),
21
21
  nullable=False,
22
22
  )
23
+ provider_admin1_name: Mapped[str] = mapped_column(
24
+ String(512), nullable=False, index=True
25
+ )
26
+ provider_admin2_name: Mapped[str] = mapped_column(
27
+ String(512), nullable=False, index=True
28
+ )
23
29
  name: Mapped[str] = mapped_column(String(512), nullable=False, index=True)
24
30
  lat: Mapped[float] = mapped_column(Float, nullable=False, index=True)
25
31
  lon: Mapped[float] = mapped_column(Float, nullable=False, index=True)
@@ -74,6 +74,7 @@ class PriceFlag(str, PythonEnum):
74
74
 
75
75
  class PriceType(str, PythonEnum):
76
76
  FARM_GATE = "Farm Gate"
77
+ PRODUCER = "Producer"
77
78
  RETAIL = "Retail"
78
79
  WHOLESALE = "Wholesale"
79
80
 
@@ -4,6 +4,8 @@ data_conflict_event = [
4
4
  dict(
5
5
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
6
6
  admin2_ref=4,
7
+ provider_admin1_name="Provincia 01",
8
+ provider_admin2_name="Distrito A",
7
9
  event_type="political_violence",
8
10
  events=10,
9
11
  fatalities=2,
@@ -13,6 +15,8 @@ data_conflict_event = [
13
15
  dict(
14
16
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
15
17
  admin2_ref=1,
18
+ provider_admin1_name="Provincia 01",
19
+ provider_admin2_name="Distrito A",
16
20
  event_type="civilian_targeting",
17
21
  events=3,
18
22
  fatalities=0,
@@ -5,6 +5,8 @@ data_food_security = [
5
5
  dict(
6
6
  resource_hdx_id="62ad6e55-5f5d-4494-854c-4110687e9e25",
7
7
  admin2_ref=1,
8
+ provider_admin1_name="Provincia 01",
9
+ provider_admin2_name="Distrito A",
8
10
  ipc_phase="1",
9
11
  ipc_type="current",
10
12
  population_in_phase=500_000,
@@ -16,6 +18,8 @@ data_food_security = [
16
18
  dict(
17
19
  resource_hdx_id="62ad6e55-5f5d-4494-854c-4110687e9e25",
18
20
  admin2_ref=2,
21
+ provider_admin1_name="Provincia 01",
22
+ provider_admin2_name="Distrito A",
19
23
  ipc_phase="2",
20
24
  ipc_type="first projection",
21
25
  population_in_phase=40_000,
@@ -27,6 +31,8 @@ data_food_security = [
27
31
  dict(
28
32
  resource_hdx_id="62ad6e55-5f5d-4494-854c-4110687e9e25",
29
33
  admin2_ref=4,
34
+ provider_admin1_name="Provincia 01",
35
+ provider_admin2_name="Distrito A",
30
36
  ipc_phase="3",
31
37
  ipc_type="second projection",
32
38
  population_in_phase=3_000,
@@ -5,6 +5,8 @@ data_humanitarian_needs = [
5
5
  dict(
6
6
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
7
7
  admin2_ref=1,
8
+ provider_admin1_name="Provincia 01",
9
+ provider_admin2_name="Distrito B",
8
10
  gender="all",
9
11
  age_range="all",
10
12
  disabled_marker="all",
@@ -19,6 +21,8 @@ data_humanitarian_needs = [
19
21
  dict(
20
22
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
21
23
  admin2_ref=1,
24
+ provider_admin1_name="Provincia 01",
25
+ provider_admin2_name="Distrito B",
22
26
  gender="f",
23
27
  age_range="all",
24
28
  disabled_marker="n",
@@ -33,6 +37,8 @@ data_humanitarian_needs = [
33
37
  dict(
34
38
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
35
39
  admin2_ref=2,
40
+ provider_admin1_name="Provincia 01",
41
+ provider_admin2_name="Distrito B",
36
42
  gender="f",
37
43
  age_range="0-4",
38
44
  min_age=0,
@@ -49,6 +55,8 @@ data_humanitarian_needs = [
49
55
  dict(
50
56
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
51
57
  admin2_ref=4,
58
+ provider_admin1_name="Provincia 03",
59
+ provider_admin2_name="Distrito D",
52
60
  gender="all",
53
61
  age_range="80+",
54
62
  min_age=80,
@@ -4,6 +4,8 @@ data_idps = [
4
4
  dict(
5
5
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
6
6
  admin2_ref=2,
7
+ provider_admin1_name="Provincia 01",
8
+ provider_admin2_name="Distrito B",
7
9
  assessment_type="BA",
8
10
  reporting_round=18,
9
11
  operation="Operation",
@@ -4,6 +4,8 @@ data_operational_presence = [
4
4
  dict(
5
5
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
6
6
  admin2_ref=2,
7
+ provider_admin1_name="Provincia 01",
8
+ provider_admin2_name="Distrito A",
7
9
  org_acronym="ORG01",
8
10
  org_name="Organisation 1",
9
11
  sector_code="SHL",
@@ -12,6 +14,8 @@ data_operational_presence = [
12
14
  dict(
13
15
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
14
16
  admin2_ref=4,
17
+ provider_admin1_name="Provincia 01",
18
+ provider_admin2_name="Distrito A",
15
19
  org_acronym="ORG02",
16
20
  org_name="Organisation 2",
17
21
  sector_code="FSC",
@@ -20,6 +24,8 @@ data_operational_presence = [
20
24
  dict(
21
25
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
22
26
  admin2_ref=4,
27
+ provider_admin1_name="Provincia 01",
28
+ provider_admin2_name="Distrito A",
23
29
  org_acronym="ORG03",
24
30
  org_name="Organisation 3",
25
31
  sector_code="WSH",
@@ -28,6 +34,8 @@ data_operational_presence = [
28
34
  dict(
29
35
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
30
36
  admin2_ref=6,
37
+ provider_admin1_name="Provincia 01",
38
+ provider_admin2_name="Distrito A",
31
39
  org_acronym="ORG03",
32
40
  org_name="Organisation 3",
33
41
  sector_code="HEA",
@@ -36,6 +44,8 @@ data_operational_presence = [
36
44
  dict(
37
45
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
38
46
  admin2_ref=1,
47
+ provider_admin1_name="Provincia 01",
48
+ provider_admin2_name="Distrito A",
39
49
  org_acronym="ORG02",
40
50
  org_name="Organisation 2",
41
51
  sector_code="WSH",
@@ -5,6 +5,8 @@ data_population = [
5
5
  dict(
6
6
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
7
7
  admin2_ref=1,
8
+ provider_admin1_name="Provincia 01",
9
+ provider_admin2_name="Distrito A",
8
10
  gender="all",
9
11
  age_range="all",
10
12
  population=1_000_000,
@@ -15,6 +17,8 @@ data_population = [
15
17
  dict(
16
18
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
17
19
  admin2_ref=1,
20
+ provider_admin1_name="Provincia 01",
21
+ provider_admin2_name="Distrito A",
18
22
  gender="f",
19
23
  age_range="all",
20
24
  population=500_000,
@@ -25,6 +29,8 @@ data_population = [
25
29
  dict(
26
30
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
27
31
  admin2_ref=2,
32
+ provider_admin1_name="Provincia 01",
33
+ provider_admin2_name="Distrito A",
28
34
  gender="f",
29
35
  age_range="0-4",
30
36
  min_age=0,
@@ -37,6 +43,8 @@ data_population = [
37
43
  dict(
38
44
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
39
45
  admin2_ref=4,
46
+ provider_admin1_name="Provincia 01",
47
+ provider_admin2_name="Distrito A",
40
48
  gender="all",
41
49
  age_range="80+",
42
50
  min_age=80,
@@ -3,8 +3,8 @@ from datetime import datetime
3
3
  data_poverty_rate = [
4
4
  dict(
5
5
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
6
- admin1_ref=1,
7
- admin1_name="Province 01", # not p-coded/normalised yet
6
+ admin1_ref=2,
7
+ provider_admin1_name="Provincia 01",
8
8
  mpi=0.617442,
9
9
  headcount_ratio=85.4,
10
10
  intensity_of_deprivation=72.3,
@@ -2,6 +2,8 @@ data_wfp_market = [
2
2
  dict(
3
3
  code="001",
4
4
  admin2_ref=4,
5
+ provider_admin1_name="Provincia 01",
6
+ provider_admin2_name="Distrito A",
5
7
  name="Market #1",
6
8
  lat=0.1, # Foolandia is in the middle of the Gulf of Guinea :)
7
9
  lon=-0.1,
@@ -19,6 +19,8 @@ def test_conflict_event_view(run_view_test):
19
19
  whereclause=(
20
20
  view_conflict_event.c.resource_hdx_id
21
21
  == "90deb235-1bf5-4bae-b231-3393222c2d01",
22
+ view_conflict_event.c.provider_admin1_name == "Provincia 01",
23
+ view_conflict_event.c.provider_admin2_name == "Distrito A",
22
24
  view_conflict_event.c.location_name == "Foolandia",
23
25
  view_conflict_event.c.admin1_name == "Province 01",
24
26
  view_conflict_event.c.admin2_name == "District A",
@@ -46,6 +48,8 @@ def _sample_data():
46
48
  return dict(
47
49
  resource_hdx_id="90deb235-1bf5-4bae-b231-3393222c2d01",
48
50
  admin2_ref=4,
51
+ provider_admin1_name="Province 01",
52
+ provider_admin2_name="District A",
49
53
  event_type="political_violence",
50
54
  events=10,
51
55
  fatalities=2,
@@ -17,6 +17,8 @@ def test_food_price_view(run_view_test):
17
17
  whereclause=(
18
18
  view_food_price.c.resource_hdx_id
19
19
  == "90deb235-1bf5-4bae-b231-3393222c2d01",
20
+ view_food_price.c.provider_admin1_name == "Provincia 01",
21
+ view_food_price.c.provider_admin2_name == "Distrito A",
20
22
  view_food_price.c.commodity_code == "001",
21
23
  view_food_price.c.currency_code == "FOO",
22
24
  view_food_price.c.price_flag == "actual",