diff --git a/tests/test_ops_summary_logic.py b/tests/test_ops_summary_logic.py new file mode 100644 index 0000000..d470055 --- /dev/null +++ b/tests/test_ops_summary_logic.py @@ -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 diff --git a/web/dist/index.html b/web/dist/index.html index 2c91a2f..4faef97 100644 --- a/web/dist/index.html +++ b/web/dist/index.html @@ -38,6 +38,16 @@ .chart-wrap { background: var(--panel); border: 1px solid #243041; border-radius: 10px; padding: 0.75rem 0.5rem; margin-top: 0.5rem; } .chart-title { padding: 0 0.75rem 0.25rem; color: var(--muted); font-size: 0.85rem; } .chart-svg { width: 100%; height: auto; display: block; } + .chart-summary { + margin: 0.65rem 0 0; + padding: 0.75rem 0.9rem; + background: #0c1117; + border: 1px solid #243041; + border-radius: 8px; + color: var(--muted); + font-size: 0.88rem; + line-height: 1.55; + } .hidden { display: none; } pre { background: var(--panel); border: 1px solid #243041; border-radius: 10px; padding: 1rem; overflow: auto; font-size: 0.78rem; color: #b7c5d4; } .center-page { display: flex; justify-content: center; align-items: flex-start; min-height: 50vh; padding: 1.5rem 0 3rem; } @@ -123,6 +133,7 @@
上图 · 时段杠杆均值
+

@@ -134,7 +145,7 @@
下图 · 时段→到期波动
-

+