hapi-schema 0.9.3__tar.gz → 0.9.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/.config/pre-commit-config.yaml +3 -3
  2. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/PKG-INFO +1 -2
  3. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/changelog.md +6 -0
  4. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/pyproject.toml +3 -0
  5. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/requirements.txt +5 -5
  6. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/_version.py +2 -2
  7. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_conflict_event.py +3 -0
  8. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_food_price.py +3 -0
  9. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_food_security.py +3 -0
  10. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_funding.py +1 -0
  11. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_humanitarian_needs.py +3 -0
  12. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_idps.py +3 -0
  13. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_national_risk.py +1 -0
  14. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_operational_presence.py +3 -0
  15. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_population.py +3 -0
  16. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_poverty_rate.py +3 -0
  17. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_refugees.py +1 -0
  18. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_returnees.py +1 -0
  19. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_views_as_tables.py +9 -0
  20. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/views.py +41 -2
  21. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_conflict_event.py +2 -0
  22. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_food_price.py +2 -0
  23. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_food_security.py +2 -0
  24. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_humanitarian_needs.py +2 -0
  25. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_idps.py +2 -0
  26. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_operational_presence.py +2 -0
  27. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_population.py +2 -0
  28. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_poverty_rate.py +2 -0
  29. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/.config/coveragerc +0 -0
  30. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/.config/pytest.ini +0 -0
  31. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/.config/ruff.toml +0 -0
  32. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/.github/workflows/publish.yaml +0 -0
  33. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/.github/workflows/run-python-tests.yaml +0 -0
  34. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/.gitignore +0 -0
  35. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/LICENSE +0 -0
  36. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/README.md +0 -0
  37. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/contributing.md +0 -0
  38. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/docker/docker-compose.yml +0 -0
  39. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/initialize_test_db.sh +0 -0
  40. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/__init__.py +0 -0
  41. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_admin1.py +0 -0
  42. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_admin2.py +0 -0
  43. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_currency.py +0 -0
  44. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_dataset.py +0 -0
  45. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_location.py +0 -0
  46. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_org.py +0 -0
  47. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_org_type.py +0 -0
  48. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_patch.py +0 -0
  49. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_resource.py +0 -0
  50. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_sector.py +0 -0
  51. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_wfp_commodity.py +0 -0
  52. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/db_wfp_market.py +0 -0
  53. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/utils/__init__.py +0 -0
  54. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/utils/base.py +0 -0
  55. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/utils/constraints.py +0 -0
  56. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/utils/enums.py +0 -0
  57. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/utils/hapi_views_code_generator.py +0 -0
  58. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/utils/view_as_table_code_generator.py +0 -0
  59. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/utils/view_as_table_definitions.toml +0 -0
  60. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/src/hapi_schema/utils/view_params.py +0 -0
  61. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/conftest.py +0 -0
  62. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/__init__.py +0 -0
  63. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_admin1.py +0 -0
  64. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_admin2.py +0 -0
  65. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_conflict_event.py +0 -0
  66. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_currency.py +0 -0
  67. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_dataset.py +0 -0
  68. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_food_price.py +0 -0
  69. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_food_security.py +0 -0
  70. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_funding.py +0 -0
  71. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_humanitarian_needs.py +0 -0
  72. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_idps.py +0 -0
  73. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_location.py +0 -0
  74. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_national_risk.py +0 -0
  75. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_operational_presence.py +0 -0
  76. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_org.py +0 -0
  77. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_org_type.py +0 -0
  78. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_patch.py +0 -0
  79. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_population.py +0 -0
  80. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_poverty_rate.py +0 -0
  81. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_refugees.py +0 -0
  82. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_resource.py +0 -0
  83. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_returnees.py +0 -0
  84. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_sector.py +0 -0
  85. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_wfp_commodity.py +0 -0
  86. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/sample_data/data_wfp_market.py +0 -0
  87. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_admin1.py +0 -0
  88. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_admin2.py +0 -0
  89. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_currency.py +0 -0
  90. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_dataset.py +0 -0
  91. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_funding.py +0 -0
  92. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_location.py +0 -0
  93. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_national_risk.py +0 -0
  94. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_org.py +0 -0
  95. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_org_type.py +0 -0
  96. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_patch.py +0 -0
  97. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_refugees.py +0 -0
  98. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_resource.py +0 -0
  99. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_returnees.py +0 -0
  100. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_sector.py +0 -0
  101. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_views_as_tables.py +0 -0
  102. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_wfp_commodity.py +0 -0
  103. {hapi_schema-0.9.3 → hapi_schema-0.9.4}/tests/test_wfp_market.py +0 -0
@@ -2,13 +2,13 @@ default_language_version:
2
2
  python: python3.12
3
3
  repos:
4
4
  - repo: https://github.com/pre-commit/pre-commit-hooks
5
- rev: v4.6.0
5
+ rev: v5.0.0
6
6
  hooks:
7
7
  - id: trailing-whitespace
8
8
  - id: end-of-file-fixer
9
9
  - id: check-ast
10
10
  - repo: https://github.com/astral-sh/ruff-pre-commit
11
- rev: v0.6.9
11
+ rev: v0.7.0
12
12
  hooks:
13
13
  # Run the linter.
14
14
  - id: ruff
@@ -17,7 +17,7 @@ repos:
17
17
  - id: ruff-format
18
18
  args: [--config, .config/ruff.toml]
19
19
  - repo: https://github.com/astral-sh/uv-pre-commit
20
- rev: 0.4.18
20
+ rev: 0.4.24
21
21
  hooks:
22
22
  # Run the pip compile
23
23
  - id: pip-compile
@@ -1,11 +1,10 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: hapi-schema
3
- Version: 0.9.3
3
+ Version: 0.9.4
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>
7
7
  License: MIT
8
- License-File: LICENSE
9
8
  Keywords: HDX,hapi,schema
10
9
  Classifier: Intended Audience :: Developers
11
10
  Classifier: License :: OSI Approved :: MIT License
@@ -5,6 +5,12 @@ 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.4
9
+
10
+ ### Added
11
+
12
+ - Admin_level to views
13
+
8
14
  ## 0.9.3
9
15
 
10
16
  ### Fixed
@@ -85,6 +85,9 @@ run = """
85
85
  --cov-report=lcov --cov-report=term-missing
86
86
  """
87
87
 
88
+ [tool.hatch.envs.hatch-static-analysis]
89
+ dependencies = ["ruff==0.7.0"]
90
+
88
91
  [tool.hatch.envs.hatch-static-analysis.scripts]
89
92
  format-check = ["ruff format --config .config/ruff.toml --check --diff {args:.}",]
90
93
  format-fix = ["ruff format --config .config/ruff.toml {args:.}",]
@@ -2,7 +2,7 @@
2
2
  # uv pip compile pyproject.toml --resolver=backtracking --all-extras -o requirements.txt
3
3
  cfgv==3.4.0
4
4
  # via pre-commit
5
- coverage==7.6.4
5
+ coverage==7.6.8
6
6
  # via pytest-cov
7
7
  distlib==0.3.9
8
8
  # via virtualenv
@@ -12,13 +12,13 @@ greenlet==3.1.1
12
12
  # via sqlalchemy
13
13
  hdx-python-database==1.3.4
14
14
  # via hapi-schema (pyproject.toml)
15
- identify==2.6.1
15
+ identify==2.6.3
16
16
  # via pre-commit
17
17
  iniconfig==2.0.0
18
18
  # via pytest
19
19
  nodeenv==1.9.1
20
20
  # via pre-commit
21
- packaging==24.1
21
+ packaging==24.2
22
22
  # via pytest
23
23
  platformdirs==4.3.6
24
24
  # via virtualenv
@@ -34,7 +34,7 @@ pytest==8.3.3
34
34
  # via
35
35
  # hapi-schema (pyproject.toml)
36
36
  # pytest-cov
37
- pytest-cov==5.0.0
37
+ pytest-cov==6.0.0
38
38
  # via hapi-schema (pyproject.toml)
39
39
  pyyaml==6.0.2
40
40
  # via pre-commit
@@ -46,5 +46,5 @@ typing-extensions==4.12.2
46
46
  # via
47
47
  # psycopg
48
48
  # sqlalchemy
49
- virtualenv==20.27.0
49
+ virtualenv==20.28.0
50
50
  # via pre-commit
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.9.3'
16
- __version_tuple__ = version_tuple = (0, 9, 3)
15
+ __version__ = version = '0.9.4'
16
+ __version_tuple__ = version_tuple = (0, 9, 4)
@@ -21,6 +21,7 @@ from hapi_schema.utils.constraints import (
21
21
  )
22
22
  from hapi_schema.utils.enums import EventType, build_enum_using_values
23
23
  from hapi_schema.utils.view_params import ViewParams
24
+ from hapi_schema.views import get_admin2_case
24
25
 
25
26
 
26
27
  # normalised table
@@ -77,6 +78,7 @@ view_params_conflict_event = ViewParams(
77
78
  DBAdmin2.name.label("admin2_name"),
78
79
  DBAdmin2.is_unspecified.label("admin2_is_unspecified"),
79
80
  DBAdmin2.admin1_ref.label("admin1_ref"),
81
+ get_admin2_case(DBConflictEvent),
80
82
  ).select_from(
81
83
  # Join risk to admin2
82
84
  DBConflictEvent.__table__.join(
@@ -108,6 +110,7 @@ availability_stmt_conflict_event = (
108
110
  DBAdmin1.code.label("admin1_code"),
109
111
  DBAdmin2.name.label("admin2_name"),
110
112
  DBAdmin2.code.label("admin2_code"),
113
+ get_admin2_case(DBConflictEvent),
111
114
  DBResource.hapi_updated_date,
112
115
  )
113
116
  .select_from(
@@ -27,6 +27,7 @@ from hapi_schema.utils.enums import (
27
27
  build_enum_using_values,
28
28
  )
29
29
  from hapi_schema.utils.view_params import ViewParams
30
+ from hapi_schema.views import get_admin2_case
30
31
 
31
32
  # normalised table
32
33
 
@@ -100,6 +101,7 @@ view_params_food_price = ViewParams(
100
101
  DBAdmin2.code.label("admin2_code"),
101
102
  DBAdmin2.name.label("admin2_name"),
102
103
  DBAdmin2.is_unspecified.label("admin2_is_unspecified"),
104
+ get_admin2_case(DBWFPMarket),
103
105
  ).select_from(
104
106
  # the admin2 comes from wfp_market
105
107
  DBFoodPrice.__table__.join(
@@ -142,6 +144,7 @@ availability_stmt_food_price = (
142
144
  DBAdmin1.code.label("admin1_code"),
143
145
  DBAdmin2.name.label("admin2_name"),
144
146
  DBAdmin2.code.label("admin2_code"),
147
+ get_admin2_case(DBWFPMarket),
145
148
  DBResource.hapi_updated_date,
146
149
  )
147
150
  .select_from(
@@ -24,6 +24,7 @@ from hapi_schema.utils.constraints import (
24
24
  )
25
25
  from hapi_schema.utils.enums import IPCPhase, IPCType, build_enum_using_values
26
26
  from hapi_schema.utils.view_params import ViewParams
27
+ from hapi_schema.views import get_admin2_case
27
28
 
28
29
 
29
30
  class DBFoodSecurity(Base):
@@ -80,6 +81,7 @@ view_params_food_security = ViewParams(
80
81
  DBAdmin2.name.label("admin2_name"),
81
82
  DBAdmin2.is_unspecified.label("admin2_is_unspecified"),
82
83
  DBAdmin2.admin1_ref.label("admin1_ref"),
84
+ get_admin2_case(DBFoodSecurity),
83
85
  ).select_from(
84
86
  # Join pop to admin2 to admin1 to loc
85
87
  DBFoodSecurity.__table__.join(
@@ -112,6 +114,7 @@ availability_stmt_food_security = (
112
114
  DBAdmin1.code.label("admin1_code"),
113
115
  DBAdmin2.name.label("admin2_name"),
114
116
  DBAdmin2.code.label("admin2_code"),
117
+ get_admin2_case(DBFoodSecurity),
115
118
  DBResource.hapi_updated_date,
116
119
  )
117
120
  .select_from(
@@ -107,6 +107,7 @@ availability_stmt_funding = (
107
107
  literal("").label("admin1_code"),
108
108
  literal("").label("admin2_name"),
109
109
  literal("").label("admin2_code"),
110
+ literal(0).label("admin_level"),
110
111
  DBResource.hapi_updated_date,
111
112
  )
112
113
  .select_from(
@@ -26,6 +26,7 @@ from hapi_schema.utils.enums import (
26
26
  build_enum_using_values,
27
27
  )
28
28
  from hapi_schema.utils.view_params import ViewParams
29
+ from hapi_schema.views import get_admin2_case
29
30
 
30
31
 
31
32
  class DBHumanitarianNeeds(Base):
@@ -85,6 +86,7 @@ view_params_humanitarian_needs = ViewParams(
85
86
  DBAdmin2.name.label("admin2_name"),
86
87
  DBAdmin2.is_unspecified.label("admin2_is_unspecified"),
87
88
  DBAdmin2.admin1_ref.label("admin1_ref"),
89
+ get_admin2_case(DBHumanitarianNeeds),
88
90
  ).select_from(
89
91
  # Join pop to admin2 to admin1 to loc
90
92
  DBHumanitarianNeeds.__table__.join(
@@ -122,6 +124,7 @@ availability_stmt_humanitarian_needs = (
122
124
  DBAdmin1.code.label("admin1_code"),
123
125
  DBAdmin2.name.label("admin2_name"),
124
126
  DBAdmin2.code.label("admin2_code"),
127
+ get_admin2_case(DBHumanitarianNeeds),
125
128
  DBResource.hapi_updated_date,
126
129
  )
127
130
  .select_from(
@@ -23,6 +23,7 @@ from hapi_schema.utils.constraints import (
23
23
  )
24
24
  from hapi_schema.utils.enums import DTMAssessmentType, build_enum_using_values
25
25
  from hapi_schema.utils.view_params import ViewParams
26
+ from hapi_schema.views import get_admin2_case
26
27
 
27
28
 
28
29
  class DBIDPs(Base):
@@ -82,6 +83,7 @@ view_params_idps = ViewParams(
82
83
  DBAdmin2.name.label("admin2_name"),
83
84
  DBAdmin2.is_unspecified.label("admin2_is_unspecified"),
84
85
  DBAdmin2.admin1_ref.label("admin1_ref"),
86
+ get_admin2_case(DBIDPs),
85
87
  ).select_from(
86
88
  DBIDPs.__table__.join(
87
89
  DBAdmin2.__table__,
@@ -112,6 +114,7 @@ availability_stmt_idps = (
112
114
  DBAdmin1.code.label("admin1_code"),
113
115
  DBAdmin2.name.label("admin2_name"),
114
116
  DBAdmin2.code.label("admin2_code"),
117
+ get_admin2_case(DBIDPs),
115
118
  DBResource.hapi_updated_date,
116
119
  )
117
120
  .select_from(
@@ -110,6 +110,7 @@ availability_stmt_national_risk = (
110
110
  literal("").label("admin1_code"),
111
111
  literal("").label("admin2_name"),
112
112
  literal("").label("admin2_code"),
113
+ literal(0).label("admin_level"),
113
114
  DBResource.hapi_updated_date,
114
115
  )
115
116
  .select_from(
@@ -21,6 +21,7 @@ from hapi_schema.db_sector import DBSector
21
21
  from hapi_schema.utils.base import Base
22
22
  from hapi_schema.utils.constraints import reference_period_constraint
23
23
  from hapi_schema.utils.view_params import ViewParams
24
+ from hapi_schema.views import get_admin2_case
24
25
 
25
26
 
26
27
  class DBOperationalPresence(Base):
@@ -81,6 +82,7 @@ view_params_operational_presence = ViewParams(
81
82
  DBAdmin2.name.label("admin2_name"),
82
83
  DBAdmin2.is_unspecified.label("admin2_is_unspecified"),
83
84
  DBAdmin2.admin1_ref.label("admin1_ref"),
85
+ get_admin2_case(DBOperationalPresence),
84
86
  ).select_from(
85
87
  # Join op to admin2 to admin1 to loc
86
88
  DBOperationalPresence.__table__.join(
@@ -131,6 +133,7 @@ availability_stmt_operational_presence = (
131
133
  DBAdmin1.code.label("admin1_code"),
132
134
  DBAdmin2.name.label("admin2_name"),
133
135
  DBAdmin2.code.label("admin2_code"),
136
+ get_admin2_case(DBOperationalPresence),
134
137
  DBResource.hapi_updated_date,
135
138
  )
136
139
  .select_from(
@@ -24,6 +24,7 @@ from hapi_schema.utils.constraints import (
24
24
  )
25
25
  from hapi_schema.utils.enums import Gender, build_enum_using_values
26
26
  from hapi_schema.utils.view_params import ViewParams
27
+ from hapi_schema.views import get_admin2_case
27
28
 
28
29
 
29
30
  class DBPopulation(Base):
@@ -82,6 +83,7 @@ view_params_population = ViewParams(
82
83
  DBAdmin2.name.label("admin2_name"),
83
84
  DBAdmin2.is_unspecified.label("admin2_is_unspecified"),
84
85
  DBAdmin2.admin1_ref.label("admin1_ref"),
86
+ get_admin2_case(DBPopulation),
85
87
  ).select_from(
86
88
  # Join pop to admin2 to admin1 to loc
87
89
  DBPopulation.__table__.join(
@@ -113,6 +115,7 @@ availability_stmt_population = (
113
115
  DBAdmin1.code.label("admin1_code"),
114
116
  DBAdmin2.name.label("admin2_name"),
115
117
  DBAdmin2.code.label("admin2_code"),
118
+ get_admin2_case(DBPopulation),
116
119
  DBResource.hapi_updated_date,
117
120
  )
118
121
  .select_from(
@@ -21,6 +21,7 @@ from hapi_schema.utils.constraints import (
21
21
  reference_period_constraint,
22
22
  )
23
23
  from hapi_schema.utils.view_params import ViewParams
24
+ from hapi_schema.views import get_admin1_case
24
25
 
25
26
 
26
27
  # normalised table
@@ -86,6 +87,7 @@ view_params_poverty_rate = ViewParams(
86
87
  DBAdmin1.code.label("admin1_code"),
87
88
  DBAdmin1.is_unspecified.label("admin1_is_unspecified"),
88
89
  DBAdmin1.location_ref.label("location_ref"),
90
+ get_admin1_case(DBPovertyRate),
89
91
  ).select_from(
90
92
  # Join PR to admin1 to loc
91
93
  DBPovertyRate.__table__.join(
@@ -111,6 +113,7 @@ availability_stmt_poverty_rate = (
111
113
  DBAdmin1.code.label("admin1_code"),
112
114
  literal("").label("admin2_name"),
113
115
  literal("").label("admin2_code"),
116
+ get_admin1_case(DBPovertyRate),
114
117
  DBResource.hapi_updated_date,
115
118
  )
116
119
  .select_from(
@@ -120,6 +120,7 @@ availability_stmt_refugees = (
120
120
  literal("").label("admin1_code"),
121
121
  literal("").label("admin2_name"),
122
122
  literal("").label("admin2_code"),
123
+ literal(0).label("admin_level"),
123
124
  DBResource.hapi_updated_date,
124
125
  )
125
126
  .select_from(
@@ -120,6 +120,7 @@ availability_stmt_returnees = (
120
120
  literal("").label("admin1_code"),
121
121
  literal("").label("admin2_name"),
122
122
  literal("").label("admin2_code"),
123
+ literal(0).label("admin_level"),
123
124
  DBResource.hapi_updated_date,
124
125
  )
125
126
  .select_from(
@@ -109,6 +109,7 @@ class DBConflictEventVAT(Base):
109
109
  admin2_name: Mapped[str] = mapped_column(String(512), index=True)
110
110
  admin2_is_unspecified: Mapped[bool] = mapped_column(Boolean)
111
111
  admin1_ref: Mapped[int] = mapped_column(Integer)
112
+ admin_level: Mapped[int] = mapped_column(Integer)
112
113
 
113
114
 
114
115
  class DBCurrencyVAT(Base):
@@ -174,6 +175,7 @@ class DBFoodPriceVAT(Base):
174
175
  admin2_code: Mapped[str] = mapped_column(String(128), index=True)
175
176
  admin2_name: Mapped[str] = mapped_column(String(512), index=True)
176
177
  admin2_is_unspecified: Mapped[bool] = mapped_column(Boolean)
178
+ admin_level: Mapped[int] = mapped_column(Integer)
177
179
 
178
180
 
179
181
  class DBFoodSecurityVAT(Base):
@@ -214,6 +216,7 @@ class DBFoodSecurityVAT(Base):
214
216
  admin2_name: Mapped[str] = mapped_column(String(512), index=True)
215
217
  admin2_is_unspecified: Mapped[bool] = mapped_column(Boolean)
216
218
  admin1_ref: Mapped[int] = mapped_column(Integer)
219
+ admin_level: Mapped[int] = mapped_column(Integer)
217
220
 
218
221
 
219
222
  class DBFundingVAT(Base):
@@ -276,6 +279,7 @@ class DBHumanitarianNeedsVAT(Base):
276
279
  admin2_name: Mapped[str] = mapped_column(String(512), index=True)
277
280
  admin2_is_unspecified: Mapped[bool] = mapped_column(Boolean)
278
281
  admin1_ref: Mapped[int] = mapped_column(Integer)
282
+ admin_level: Mapped[int] = mapped_column(Integer)
279
283
 
280
284
 
281
285
  class DBIDPsVAT(Base):
@@ -312,6 +316,7 @@ class DBIDPsVAT(Base):
312
316
  admin2_name: Mapped[str] = mapped_column(String(512), index=True)
313
317
  admin2_is_unspecified: Mapped[bool] = mapped_column(Boolean)
314
318
  admin1_ref: Mapped[int] = mapped_column(Integer)
319
+ admin_level: Mapped[int] = mapped_column(Integer)
315
320
 
316
321
 
317
322
  class DBLocationVAT(Base):
@@ -396,6 +401,7 @@ class DBOperationalPresenceVAT(Base):
396
401
  admin2_name: Mapped[str] = mapped_column(String(512), index=True)
397
402
  admin2_is_unspecified: Mapped[bool] = mapped_column(Boolean)
398
403
  admin1_ref: Mapped[int] = mapped_column(Integer)
404
+ admin_level: Mapped[int] = mapped_column(Integer)
399
405
 
400
406
 
401
407
  class DBOrgTypeVAT(Base):
@@ -451,6 +457,7 @@ class DBPopulationVAT(Base):
451
457
  admin2_name: Mapped[str] = mapped_column(String(512), index=True)
452
458
  admin2_is_unspecified: Mapped[bool] = mapped_column(Boolean)
453
459
  admin1_ref: Mapped[int] = mapped_column(Integer)
460
+ admin_level: Mapped[int] = mapped_column(Integer)
454
461
 
455
462
 
456
463
  class DBPovertyRateVAT(Base):
@@ -482,6 +489,7 @@ class DBPovertyRateVAT(Base):
482
489
  admin1_code: Mapped[str] = mapped_column(String(128))
483
490
  admin1_is_unspecified: Mapped[bool] = mapped_column(Boolean)
484
491
  location_ref: Mapped[int] = mapped_column(Integer, index=True)
492
+ admin_level: Mapped[int] = mapped_column(Integer)
485
493
 
486
494
 
487
495
  class DBRefugeesVAT(Base):
@@ -622,4 +630,5 @@ class DBAvailabilityVAT(Base):
622
630
  admin1_code: Mapped[str] = mapped_column(String(128), primary_key=True)
623
631
  admin2_name: Mapped[str] = mapped_column(String(512), primary_key=True)
624
632
  admin2_code: Mapped[str] = mapped_column(String(128), primary_key=True)
633
+ admin_level: Mapped[int] = mapped_column(Integer)
625
634
  hapi_updated_date: Mapped[datetime] = mapped_column(DateTime, index=True)
@@ -1,11 +1,13 @@
1
1
  import inspect
2
2
  import os
3
3
  from importlib import import_module
4
- from typing import Dict
4
+ from typing import Any, Dict, Tuple
5
5
 
6
- from sqlalchemy import TableClause
6
+ from sqlalchemy import ColumnElement, Label, TableClause, and_, case, or_
7
7
  from sqlalchemy.sql.expression import union_all
8
8
 
9
+ from hapi_schema.db_admin1 import DBAdmin1
10
+ from hapi_schema.db_admin2 import DBAdmin2
9
11
  from hapi_schema.utils.base import Base
10
12
  from hapi_schema.utils.view_params import ViewParams
11
13
 
@@ -55,3 +57,40 @@ def prepare_hapi_views() -> Dict[str, TableClause]:
55
57
  view_params_availability.__dict__
56
58
  )
57
59
  return views
60
+
61
+
62
+ def get_admin1_when(table: Any) -> Tuple[ColumnElement, int]:
63
+ return (
64
+ or_(
65
+ and_(
66
+ table.provider_admin1_name.is_not(None),
67
+ table.provider_admin1_name != "",
68
+ ),
69
+ DBAdmin1.is_unspecified.is_(False),
70
+ ),
71
+ 1,
72
+ )
73
+
74
+
75
+ def get_admin1_case(table: Any) -> Label:
76
+ return case(
77
+ get_admin1_when(table),
78
+ else_=0,
79
+ ).label("admin_level")
80
+
81
+
82
+ def get_admin2_case(table: Any) -> Label:
83
+ return case(
84
+ (
85
+ or_(
86
+ and_(
87
+ table.provider_admin2_name.is_not(None),
88
+ table.provider_admin2_name != "",
89
+ ),
90
+ DBAdmin2.is_unspecified.is_(False),
91
+ ),
92
+ 2,
93
+ ),
94
+ get_admin1_when(table),
95
+ else_=0,
96
+ ).label("admin_level")
@@ -24,6 +24,7 @@ def test_conflict_event_view(run_view_test):
24
24
  view_conflict_event.c.location_name == "Foolandia",
25
25
  view_conflict_event.c.admin1_name == "Province 01",
26
26
  view_conflict_event.c.admin2_name == "District A",
27
+ view_conflict_event.c.admin_level == 2,
27
28
  ),
28
29
  )
29
30
 
@@ -38,6 +39,7 @@ def test_conflict_event_availability(run_view_test):
38
39
  view_availability.c.location_code == "FOO",
39
40
  view_availability.c.admin1_name == "Province 01",
40
41
  view_availability.c.admin2_name == "District A",
42
+ view_availability.c.admin_level == 2,
41
43
  view_availability.c.hapi_updated_date == datetime(2023, 6, 1),
42
44
  ),
43
45
  )
@@ -34,6 +34,7 @@ def test_food_price_view(run_view_test):
34
34
  view_food_price.c.location_name == "Foolandia",
35
35
  view_food_price.c.admin1_name == "Province 01",
36
36
  view_food_price.c.admin2_name == "District A",
37
+ view_food_price.c.admin_level == 2,
37
38
  ),
38
39
  )
39
40
 
@@ -48,6 +49,7 @@ def test_food_price_availability(run_view_test):
48
49
  view_availability.c.location_code == "FOO",
49
50
  view_availability.c.admin1_name == "Province 01",
50
51
  view_availability.c.admin2_name == "District A",
52
+ view_availability.c.admin_level == 2,
51
53
  view_availability.c.hapi_updated_date == datetime(2023, 6, 1),
52
54
  ),
53
55
  )
@@ -24,6 +24,7 @@ def test_food_security_view(run_view_test):
24
24
  view_food_security.c.provider_admin2_name == "Distrito A",
25
25
  view_food_security.c.admin1_code == "FOO-001",
26
26
  view_food_security.c.location_code == "FOO",
27
+ view_food_security.c.admin_level == 2,
27
28
  ),
28
29
  )
29
30
 
@@ -38,6 +39,7 @@ def test_food_security_availability(run_view_test):
38
39
  view_availability.c.location_code == "FOO",
39
40
  view_availability.c.admin1_name == "Province 01",
40
41
  view_availability.c.admin2_name == "District A",
42
+ view_availability.c.admin_level == 2,
41
43
  view_availability.c.hapi_updated_date == datetime(2023, 8, 1),
42
44
  ),
43
45
  )
@@ -33,6 +33,7 @@ def test_humanitarian_needs_view(run_view_test):
33
33
  == "Female - Disabled - Baby - IDP",
34
34
  view_humanitarian_needs.c.sector_name
35
35
  == "Water Sanitation Hygiene",
36
+ view_humanitarian_needs.c.admin_level == 2,
36
37
  ),
37
38
  )
38
39
 
@@ -47,6 +48,7 @@ def test_humanitarian_needs_availability(run_view_test):
47
48
  view_availability.c.location_code == "FOO",
48
49
  view_availability.c.admin1_name == "Province 01",
49
50
  view_availability.c.admin2_name == "District A",
51
+ view_availability.c.admin_level == 2,
50
52
  view_availability.c.hapi_updated_date == datetime(2023, 6, 1),
51
53
  ),
52
54
  )
@@ -28,6 +28,7 @@ def test_idps_view(run_view_test):
28
28
  view_idps.c.admin2_code == "FOO-001-XXX",
29
29
  view_idps.c.admin1_code == "FOO-001",
30
30
  view_idps.c.location_code == "FOO",
31
+ view_idps.c.admin_level == 2,
31
32
  ),
32
33
  )
33
34
 
@@ -42,6 +43,7 @@ def test_idps_availability(run_view_test):
42
43
  view_availability.c.location_code == "FOO",
43
44
  view_availability.c.admin1_code == "FOO-001",
44
45
  view_availability.c.admin2_code == "FOO-001-XXX",
46
+ view_availability.c.admin_level == 2,
45
47
  view_availability.c.hapi_updated_date == datetime(2023, 6, 1),
46
48
  ),
47
49
  )
@@ -30,6 +30,7 @@ def test_operational_presence_view(run_view_test):
30
30
  == "International NGO",
31
31
  view_operational_presence.c.sector_name
32
32
  == "Water Sanitation Hygiene",
33
+ view_operational_presence.c.admin_level == 2,
33
34
  ),
34
35
  )
35
36
 
@@ -44,6 +45,7 @@ def test_operational_presence_availability(run_view_test):
44
45
  view_availability.c.location_code == "FOO",
45
46
  view_availability.c.admin1_name == "Province 01",
46
47
  view_availability.c.admin2_name == "District A",
48
+ view_availability.c.admin_level == 2,
47
49
  view_availability.c.hapi_updated_date == datetime(2023, 6, 1),
48
50
  ),
49
51
  )
@@ -22,6 +22,7 @@ def test_population_view(run_view_test):
22
22
  view_population.c.admin1_code == "FOO-001",
23
23
  view_population.c.location_code == "FOO",
24
24
  view_population.c.gender == "f",
25
+ view_population.c.admin_level == 2,
25
26
  ),
26
27
  )
27
28
 
@@ -36,6 +37,7 @@ def test_population_availability(run_view_test):
36
37
  view_availability.c.location_code == "FOO",
37
38
  view_availability.c.admin1_name == "Province 01",
38
39
  view_availability.c.admin2_name == "District A",
40
+ view_availability.c.admin_level == 2,
39
41
  view_availability.c.hapi_updated_date == datetime(2023, 6, 1),
40
42
  ),
41
43
  )
@@ -22,6 +22,7 @@ def test_poverty_rate_view(run_view_test):
22
22
  view_poverty_rate.c.location_name == "Foolandia",
23
23
  view_poverty_rate.c.provider_admin1_name == "Provincia 01",
24
24
  view_poverty_rate.c.admin1_name == "Province 01",
25
+ view_poverty_rate.c.admin_level == 1,
25
26
  ),
26
27
  )
27
28
 
@@ -36,6 +37,7 @@ def test_poverty_rate_availability(run_view_test):
36
37
  view_availability.c.location_code == "FOO",
37
38
  view_availability.c.admin1_name == "Province 01",
38
39
  view_availability.c.hapi_updated_date == datetime(2023, 6, 1),
40
+ view_availability.c.admin_level == 1,
39
41
  ),
40
42
  )
41
43
 
File without changes
File without changes
File without changes
File without changes