Federate official Belgium data sources
This commit is contained in:
@@ -509,6 +509,10 @@ def parse_geometry_archive(content: bytes, year: int) -> GeometryArchiveData:
|
||||
|
||||
def _validate_scope(scope: GeographicScope, geometry: GeometryArchiveData, population: PopulationArchiveData) -> None:
|
||||
requested = set(scope.nis_codes)
|
||||
if scope.all_municipalities:
|
||||
if not geometry.municipality_by_sector or not population.rows:
|
||||
_fail("STATBEL_SCOPE_REJECTED", "National geographic scope has no source municipalities.")
|
||||
return
|
||||
if not requested or any(not MUNICIPALITY_CODE_PATTERN.fullmatch(value) for value in requested):
|
||||
_fail("STATBEL_SCOPE_REJECTED", "Approved geographic scope contains invalid NIS codes.")
|
||||
geometry_codes = set(geometry.municipality_by_sector.values())
|
||||
@@ -540,7 +544,16 @@ def _baseline_summary(path: Path | None, *, year: int, scope: GeographicScope) -
|
||||
baseline_year=baseline_year,
|
||||
candidate_year=year,
|
||||
)
|
||||
if set(str(value) for value in payload.get("member_nis_codes") or []) != set(scope.nis_codes):
|
||||
baseline_scope = payload.get("coverage_scope")
|
||||
if (
|
||||
(scope.all_municipalities and baseline_scope != scope.key)
|
||||
or (not scope.all_municipalities and baseline_scope not in {None, scope.key})
|
||||
):
|
||||
_fail("STATBEL_BASELINE_SCOPE_MISMATCH", "Baseline snapshot does not use the same approved scope.")
|
||||
if (
|
||||
not scope.all_municipalities
|
||||
and set(str(value) for value in payload.get("member_nis_codes") or []) != set(scope.nis_codes)
|
||||
):
|
||||
_fail("STATBEL_BASELINE_SCOPE_MISMATCH", "Baseline snapshot does not use the same approved scope.")
|
||||
features = payload.get("features")
|
||||
if not isinstance(features, list) or not features:
|
||||
@@ -625,7 +638,11 @@ def validate_statbel_release(
|
||||
national_unlocated_total = sum(int(population.rows[code]["TOTAL"]) for code in population_without_geometry)
|
||||
if national_spatial_total + national_unlocated_total != population.population_total:
|
||||
_fail("STATBEL_TOTAL_RECONCILIATION_FAILED", "National population accounting does not reconcile.")
|
||||
requested = set(scope.nis_codes)
|
||||
requested = (
|
||||
set(geometry.municipality_by_sector.values())
|
||||
if scope.all_municipalities
|
||||
else set(scope.nis_codes)
|
||||
)
|
||||
scope_spatial_codes = {
|
||||
code for code in geometry_codes if geometry.municipality_by_sector[code] in requested
|
||||
}
|
||||
@@ -700,8 +717,8 @@ def validate_statbel_release(
|
||||
"scope_accounting": {
|
||||
"scope_key": scope.key,
|
||||
"scope_display_name": scope.display_name,
|
||||
"member_count": len(scope.members),
|
||||
"member_nis_codes": list(scope.nis_codes),
|
||||
"member_count": len(requested),
|
||||
"member_nis_codes": sorted(requested),
|
||||
"spatial_sector_count": len(scope_spatial_codes),
|
||||
"spatial_population_total": scope_spatial_total,
|
||||
"unlocated_row_count": len(scope_unlocated_codes),
|
||||
|
||||
Reference in New Issue
Block a user