"""산출 요약 — 값의 **크기가 말이 되나**를 한눈에 보이는 자리 (2026-09-07 조율 창 권고). 왜 있나 서브 창이 씨앗뿜어붙이기를 **합계 68.8원**으로 세워 두고도 몰랐던 일이 있었다. 값이 **있기는 하니** 어떤 시험도 안 잡는다. 자릿수가 어긋난 것은 사람이 훑어야 보이고, 훑으려면 **최솟값·중앙값·최댓값이 표 옆에 떠 있어야** 한다. ⚠ 이것은 검사가 아니라 **눈에 띄게 하는 장치**다 기준을 정해 놓고 걸러 내지 않는다 — 임도 물량은 ㎥·㎡·m·ton·개가 섞여 있어 「얼마 이하면 이상하다」를 한 벌로 못 정한다. **단위별로 나눠** 내고 판단은 사람에게 맡긴다. """ from __future__ import annotations from statistics import median from typing import Any, Iterable def spread(values: Iterable[float]) -> dict[str, float] | None: """최솟값·중앙값·최댓값. 값이 없으면 `None` — 0 으로 만들지 않는다.""" numbers = [float(v) for v in values if isinstance(v, (int, float))] if not numbers: return None return { "min": min(numbers), "median": float(median(numbers)), "max": max(numbers), "count": len(numbers), } def spread_by_unit( rows: Iterable[dict[str, Any]], *, value_key: str ) -> dict[str, dict[str, float]]: """단위별로 갈라 낸다. ㎥ 와 ton 을 한 통에 넣으면 최솟값이 뜻을 잃는다.""" buckets: dict[str, list[float]] = {} for row in rows: value = row.get(value_key) if not isinstance(value, (int, float)): continue buckets.setdefault(str(row.get("unit") or "?"), []).append(float(value)) result: dict[str, dict[str, float]] = {} for unit, numbers in buckets.items(): found = spread(numbers) if found: result[unit] = found return result