fix: show expiry-filter sample stats so ops map filter effect is visible

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-02 10:48:40 +08:00
parent 3e492eb46c
commit 56f58a12bd
6 changed files with 143 additions and 27 deletions
+33 -5
View File
@@ -15,18 +15,46 @@ def hours_to_expiry_at(ts_ms: int, expiry_ymd: str) -> float | None:
return (ems - int(ts_ms)) / 3_600_000.0
def hours_stats(rows: Iterable[dict[str, Any]]) -> dict[str, Any]:
"""样本在采样时刻的距到期小时分布。"""
vals: list[float] = []
for r in rows:
h = hours_to_expiry_at(int(r.get("ts_ms") or 0), str(r.get("expiry_ymd") or ""))
if h is not None:
vals.append(float(h))
if not vals:
return {"n": 0, "min_hours": None, "max_hours": None}
return {
"n": len(vals),
"min_hours": min(vals),
"max_hours": max(vals),
}
def filter_rows_min_hours_to_expiry(
rows: Iterable[dict[str, Any]],
*,
min_hours: float,
) -> list[dict[str, Any]]:
"""保留采样时距到期 ≥ min_hours 的样本。"""
out: list[dict[str, Any]] = []
) -> tuple[list[dict[str, Any]], dict[str, Any]]:
"""保留采样时距到期 ≥ min_hours 的样本;附带过滤前后统计"""
raw = list(rows)
before = hours_stats(raw)
mh = float(min_hours)
for r in rows:
out: list[dict[str, Any]] = []
for r in raw:
h = hours_to_expiry_at(int(r.get("ts_ms") or 0), str(r.get("expiry_ymd") or ""))
if h is None:
continue
if h >= mh:
out.append(r)
return out
after = hours_stats(out)
meta = {
"min_hours_filter": mh,
"raw_sample_count": before["n"],
"filtered_sample_count": after["n"],
"raw_hours_min": before["min_hours"],
"raw_hours_max": before["max_hours"],
"filtered_hours_min": after["min_hours"],
"filtered_hours_max": after["max_hours"],
}
return out, meta