fix: separate demo seed from catalog facts

This commit is contained in:
ik
2026-09-22 20:05:09 +07:00
parent a357988f93
commit a8321536cc
5 changed files with 11 additions and 5 deletions
+4 -2
View File
@@ -3,18 +3,20 @@ from __future__ import annotations
from sqlalchemy import func, or_, select
from sqlalchemy.orm import Session
from .models import CatchReport, ExternalObservation, Fish, SourceType, Spot, Waterbody
from .models import CatchReport, ExternalObservation, Fish, ModerationStatus, SourceType, Spot, Waterbody
def audit_catalog(db: Session) -> dict[str, int]:
count = lambda model: db.scalar(select(func.count()).select_from(model)) or 0
demo_reports = db.scalar(select(func.count()).select_from(CatchReport).where(CatchReport.source_external_id.like("seed:%"))) or 0
approved_reports = db.scalar(select(func.count()).select_from(CatchReport).where(CatchReport.moderation_status == ModerationStatus.approved, or_(CatchReport.source_external_id.is_(None), CatchReport.source_external_id.not_like("seed:%")))) or 0
failures = {
"invalid_weights": db.scalar(select(func.count()).select_from(CatchReport).where(or_(CatchReport.weight_g <= 0, CatchReport.weight_g > 3_000_000))) or 0,
"invalid_coordinates": db.scalar(select(func.count()).select_from(Spot).where(or_(Spot.x < -10_000, Spot.x > 10_000, Spot.y < -10_000, Spot.y > 10_000))) or 0,
"incomplete_official_records": db.scalar(select(func.count()).select_from(CatchReport).where(CatchReport.source_type == SourceType.official_record, or_(CatchReport.caught_at.is_(None), CatchReport.source_url.is_(None)))) or 0,
"incomplete_published_staging": db.scalar(select(func.count()).select_from(ExternalObservation).where(ExternalObservation.status == "published", or_(ExternalObservation.fish_id.is_(None), ExternalObservation.waterbody_id.is_(None), ExternalObservation.x.is_(None), ExternalObservation.y.is_(None), ExternalObservation.weight_g.is_(None), ExternalObservation.catch_report_id.is_(None)))) or 0,
}
return {"fishes": count(Fish), "waterbodies": count(Waterbody), "reports": count(CatchReport), "staging": count(ExternalObservation), **failures, "failures": sum(failures.values())}
return {"fishes": count(Fish), "waterbodies": count(Waterbody), "reports": count(CatchReport), "demo_reports": demo_reports, "approved_confirmed_reports": approved_reports, "staging": count(ExternalObservation), **failures, "failures": sum(failures.values())}
def audit_waterbody_catalog(db: Session, expected_ids: set[str]) -> dict:
+3 -2
View File
@@ -47,8 +47,9 @@ def seed() -> None:
db.flush()
return item
spot1 = spot(vyunok, "spot1", 110, 103, "Кромка травы у северного берега")
spot2 = spot(kuori, "spot2", 85, 92, "Свальчик в глубину")
spot_description = settings.seed_demo_data
spot1 = spot(vyunok, "spot1", 110, 103, "Кромка травы у северного берега" if spot_description else None)
spot2 = spot(kuori, "spot2", 85, 92, "Свальчик в глубину" if spot_description else None)
if not settings.seed_demo_data:
return
now = datetime.now(timezone.utc)