feat: add ops-map text summaries for leverage and move periods

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-02 09:43:56 +08:00
parent 74021dae08
commit f798c11cf9
5 changed files with 327 additions and 9 deletions
+32
View File
@@ -0,0 +1,32 @@
"""对齐前端 opsSummary 规则的轻量逻辑测试(Python 镜像)。"""
MIN_N = 3
TOP_K = 5
def leverage_summary_week(buckets, min_leverage=100):
active = [b for b in buckets if b["n"] > 0]
ranked = sorted(
[b for b in active if b["n"] >= MIN_N and b.get("pct_ge_min") is not None],
key=lambda b: (b["pct_ge_min"], b["n"], b.get("mean") or 0),
reverse=True,
)[:TOP_K]
return ranked
def test_week_ranks_by_pct_ge_min():
buckets = [
{"label": "09:00", "n": 10, "mean": 110, "pct_ge_min": 0.5},
{"label": "14:00", "n": 10, "mean": 105, "pct_ge_min": 0.8},
{"label": "21:00", "n": 2, "mean": 200, "pct_ge_min": 1.0}, # n 不足
]
ranked = leverage_summary_week(buckets)
assert [b["label"] for b in ranked] == ["14:00", "09:00"]
def test_day_keeps_small_n():
active = [b for b in [
{"label": "09:00", "n": 1, "mean": 118, "pct_ge_min": 1.0},
] if b["n"] > 0]
assert len(active) == 1