Prefer governed orthophoto editions in source status
This commit is contained in:
@@ -4,6 +4,7 @@ from collections import defaultdict
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from pathlib import Path
|
||||
import re
|
||||
from typing import Iterable
|
||||
from uuid import UUID
|
||||
|
||||
@@ -51,6 +52,7 @@ SOURCE_POLICIES: dict[str, SourcePolicy] = {
|
||||
}
|
||||
|
||||
DEFAULT_POLICY = SourcePolicy("Niet-geclassificeerde bron", "edition")
|
||||
_ORTHOPHOTO_EDITION = re.compile(r"^20\d{2}\.\d{2}$")
|
||||
|
||||
|
||||
def _as_utc(value: datetime | None) -> datetime | None:
|
||||
@@ -81,10 +83,16 @@ def _latest_dataset(datasets: list[Dataset]) -> Dataset:
|
||||
)
|
||||
|
||||
|
||||
def _latest_source_version(policy: SourcePolicy, datasets: list[Dataset]) -> str | None:
|
||||
def _latest_source_version(source_name: str, policy: SourcePolicy, datasets: list[Dataset]) -> str | None:
|
||||
versioned = [item for item in datasets if item.source_version]
|
||||
if not versioned:
|
||||
return None
|
||||
if source_name == "digitaal_vlaanderen_orthophoto":
|
||||
official_editions = [
|
||||
item for item in versioned if _ORTHOPHOTO_EDITION.fullmatch((item.source_version or "").strip())
|
||||
]
|
||||
if official_editions:
|
||||
return _latest_dataset(official_editions).source_version
|
||||
if policy.refresh_policy == "rolling_snapshot":
|
||||
named_current = [
|
||||
item
|
||||
@@ -258,7 +266,7 @@ class SourceFreshnessService:
|
||||
version_count=sum(len(versions_by_dataset.get(item.id, [])) for item in source_datasets),
|
||||
latest_imported_at=_latest_datetime(item.imported_at for item in source_datasets),
|
||||
latest_observed_at=_latest_datetime(item.observed_at for item in source_datasets),
|
||||
latest_source_version=_latest_source_version(policy, source_datasets),
|
||||
latest_source_version=_latest_source_version(source_name, policy, source_datasets),
|
||||
refresh_policy=policy.refresh_policy,
|
||||
review_interval_days=policy.review_interval_days,
|
||||
next_review_at=next_review_at,
|
||||
|
||||
Reference in New Issue
Block a user