feat: show ops-map summaries as detailed period tables

Replace paragraph text with day-hit stats (days/days_hit/pct) so leverage and move charts list each hour with counts.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-08-05 17:12:23 +08:00
parent e213db8d2d
commit 270e114658
8 changed files with 513 additions and 210 deletions
+24
View File
@@ -61,5 +61,29 @@ def test_aggregate_leverage_buckets():
assert b14["n"] == 2
assert b14["mean"] == 150
assert b14["label"] == "14:00"
assert b14["days"] == 1
assert b14["days_hit"] == 1
assert b14["pct_days_hit"] == 1.0
empty = next(b for b in buckets if b["bucket_start_min"] == 0)
assert empty["n"] == 0
assert empty["days"] == 0
assert empty["days_hit"] == 0
def test_aggregate_leverage_days_hit():
from datetime import datetime
from zoneinfo import ZoneInfo
sh = ZoneInfo("Asia/Shanghai")
ts1 = int(datetime(2026, 7, 30, 11, 10, tzinfo=sh).timestamp() * 1000)
ts2 = int(datetime(2026, 7, 31, 11, 20, tzinfo=sh).timestamp() * 1000)
rows = [
{"ts_ms": ts1, "side": "C", "leverage": 120}, # day1 hit
{"ts_ms": ts2, "side": "C", "leverage": 80}, # day2 miss
]
buckets = aggregate_leverage(rows, bucket_minutes=60, min_leverage=100, side="C")
b11 = next(b for b in buckets if b["bucket_start_min"] == 11 * 60)
assert b11["days"] == 2
assert b11["days_hit"] == 1
assert b11["pct_days_hit"] == 0.5
assert b11["n"] == 2