chore: audit RF4 media quality
This commit is contained in:
@@ -251,6 +251,45 @@ def media_coverage(root: Path) -> dict:
|
||||
return {"baseline_date": baseline["verified_at"], "entities": result}
|
||||
|
||||
|
||||
def media_quality_report(root: Path, *, minimum_dimension: int = 256, display_dimension: int = 180) -> dict:
|
||||
"""Report published raster quality and known higher-quality source alternatives offline."""
|
||||
manifest = json.loads((root / "manifest.json").read_text(encoding="utf-8"))
|
||||
assets = manifest.get("assets", [])
|
||||
approved = [item for item in assets if item.get("status") == "approved" and item.get("entity_type") == "fish"]
|
||||
low = [item for item in approved if min(int(item.get("width") or 0), int(item.get("height") or 0)) < minimum_dimension]
|
||||
upsampled = [item for item in approved if min(int(item.get("width") or 0), int(item.get("height") or 0)) < display_dimension]
|
||||
low_urls = {item.get("asset_url") for item in low}
|
||||
alternatives = [
|
||||
item for item in assets
|
||||
if item.get("entity_type") == "fish"
|
||||
and item.get("status") in {"duplicate", "queued"}
|
||||
and (item.get("duplicate_of") in low_urls or item.get("status") == "queued")
|
||||
]
|
||||
|
||||
by_source: dict[str, dict[str, int]] = {}
|
||||
for item in approved:
|
||||
host = urlsplit(str(item.get("asset_url") or "")).hostname or "unknown"
|
||||
summary = by_source.setdefault(host, {"published": 0, "below_minimum": 0, "upsampled_in_cards": 0})
|
||||
summary["published"] += 1
|
||||
summary["below_minimum"] += item in low
|
||||
summary["upsampled_in_cards"] += item in upsampled
|
||||
|
||||
return {
|
||||
"entity_type": "fish",
|
||||
"minimum_dimension": minimum_dimension,
|
||||
"display_dimension": display_dimension,
|
||||
"published": len(approved),
|
||||
"below_minimum": len(low),
|
||||
"upsampled_in_cards": len(upsampled),
|
||||
"known_alternative_urls": len(alternatives),
|
||||
"by_source": by_source,
|
||||
"examples": [
|
||||
{"label": item.get("label"), "width": item.get("width"), "height": item.get("height"), "asset_url": item.get("asset_url")}
|
||||
for item in sorted(low, key=lambda row: str(row.get("label") or ""))[:20]
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
def inspect_image(body: bytes) -> tuple[int, int, str]:
|
||||
try:
|
||||
with Image.open(io.BytesIO(body)) as image:
|
||||
|
||||
Reference in New Issue
Block a user