feat: add governed nationwide AOI orchestration and CUDA enforcement
This commit is contained in:
@@ -452,10 +452,12 @@ class CoverageRegistryService:
|
||||
theme: str,
|
||||
zone: str,
|
||||
selection: Any,
|
||||
) -> list[Dataset]:
|
||||
) -> tuple[list[Dataset], bool]:
|
||||
if definition.operational_themes and theme not in definition.operational_themes:
|
||||
return []
|
||||
return [], False
|
||||
matches: list[Dataset] = []
|
||||
bounded_scopes: list[Any] = []
|
||||
zone_scoped_materialization = False
|
||||
for dataset in datasets:
|
||||
if dataset.status != "ready" or dataset.source_name not in definition.materialized_source_names:
|
||||
continue
|
||||
@@ -484,13 +486,21 @@ class CoverageRegistryService:
|
||||
acquired_scope = box(*(float(value) for value in acquired_bbox))
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
if not acquired_scope.is_valid or not acquired_scope.covers(selection):
|
||||
if not acquired_scope.is_valid or not acquired_scope.intersects(selection):
|
||||
continue
|
||||
bounded_scopes.append(acquired_scope)
|
||||
elif definition.contract.acquisition_mode == "bounded_api" and coverage_zones:
|
||||
zone_scoped_materialization = zone in coverage_zones or "belgium" in coverage_zones
|
||||
layer_matches = not layer_names or dataset.reference_layer_name in layer_names
|
||||
zone_matches = not coverage_zones or zone in coverage_zones or "belgium" in coverage_zones
|
||||
if layer_matches and zone_matches:
|
||||
matches.append(dataset)
|
||||
return matches
|
||||
if not matches:
|
||||
return [], False
|
||||
fully_covered = True
|
||||
if definition.contract.acquisition_mode == "bounded_api":
|
||||
fully_covered = zone_scoped_materialization or (bool(bounded_scopes) and unary_union(bounded_scopes).covers(selection))
|
||||
return matches, fully_covered
|
||||
|
||||
@staticmethod
|
||||
def _resolve_item(
|
||||
@@ -516,10 +526,11 @@ class CoverageRegistryService:
|
||||
)
|
||||
|
||||
materialized: list[Dataset] = []
|
||||
evidence: list[dict[str, Any]] = []
|
||||
source_statuses: list[str] = []
|
||||
limitations: list[str] = []
|
||||
for definition in definitions:
|
||||
matches = CoverageRegistryService._matching_datasets(
|
||||
matches, fully_covered = CoverageRegistryService._matching_datasets(
|
||||
datasets,
|
||||
definition,
|
||||
theme,
|
||||
@@ -527,8 +538,28 @@ class CoverageRegistryService:
|
||||
selection,
|
||||
)
|
||||
materialized.extend(matches)
|
||||
if matches:
|
||||
for dataset in matches:
|
||||
metadata = dataset.source_metadata if isinstance(getattr(dataset, "source_metadata", None), dict) else {}
|
||||
observed_at = getattr(dataset, "observed_at", None)
|
||||
published_at = metadata.get("published_at") or metadata.get("publication_date") or metadata.get("published_on")
|
||||
evidence.append({
|
||||
"dataset_id": dataset.id,
|
||||
"source_name": str(dataset.source_name or definition.contract.source_name),
|
||||
"authority_level": definition.contract.authority_level,
|
||||
"source_version": getattr(dataset, "source_version", None),
|
||||
"observed_at": observed_at.isoformat() if hasattr(observed_at, "isoformat") else (str(observed_at) if observed_at else None),
|
||||
"published_at": str(published_at) if published_at else None,
|
||||
"crs": getattr(dataset, "crs", None) or metadata.get("source_crs"),
|
||||
"resolution": getattr(dataset, "resolution_json", None),
|
||||
"coverage_bbox_epsg4326": metadata.get("bbox_epsg4326"),
|
||||
"attribution": metadata.get("attribution") or definition.contract.attribution,
|
||||
"license_note": metadata.get("license_note") or definition.contract.license_note,
|
||||
"checksum_sha256": getattr(dataset, "checksum_sha256", None),
|
||||
})
|
||||
if matches and fully_covered:
|
||||
source_statuses.append("operational")
|
||||
elif matches:
|
||||
source_statuses.append("partial")
|
||||
elif (
|
||||
definition.contract.integration_status == "operational"
|
||||
and (not definition.operational_themes or theme in definition.operational_themes)
|
||||
@@ -549,6 +580,7 @@ class CoverageRegistryService:
|
||||
status=best_status,
|
||||
source_names=[definition.contract.source_name for definition in definitions],
|
||||
materialized_dataset_ids=list(dict.fromkeys(dataset.id for dataset in materialized)),
|
||||
evidence=list({str(item["dataset_id"]): item for item in evidence}.values()),
|
||||
limitation_message=" ".join(dict.fromkeys(limitations)),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user