feat: 档案统计独立卡片、共用交易日历与四所统计页日历
内照明心统计表移至顶部卡片,右侧为日历/图表/交易记录;日历样式适配浅深主题,四所统计分析页同步展示按月盈亏日历。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
|
||||
from trade_stats_calendar_lib import build_trade_stats_calendar
|
||||
|
||||
|
||||
def _row(**kwargs):
|
||||
base = {
|
||||
"monitor_type": "",
|
||||
"key_signal_type": "",
|
||||
"exchange_turnover_usdt": None,
|
||||
"exchange_commission_usdt": None,
|
||||
}
|
||||
base.update(kwargs)
|
||||
return SimpleNamespace(**base)
|
||||
|
||||
|
||||
def _matches_all(row, segment_key):
|
||||
return segment_key == "all"
|
||||
|
||||
|
||||
def _matches_manual(row, segment_key):
|
||||
if segment_key == "all":
|
||||
return True
|
||||
if segment_key == "manual":
|
||||
return (row.monitor_type or "").strip() == "手动" and not (row.key_signal_type or "").strip()
|
||||
return False
|
||||
|
||||
|
||||
class TradeStatsCalendarLibTests(unittest.TestCase):
|
||||
def test_groups_by_trading_day_and_segment(self):
|
||||
pnls = [
|
||||
(10.0, None, "2026-06-18", _row(monitor_type="手动")),
|
||||
(-3.0, None, "2026-06-18", _row(monitor_type="手动")),
|
||||
(5.0, None, "2026-06-19", _row(monitor_type="自动", key_signal_type="箱体突破")),
|
||||
]
|
||||
payload = build_trade_stats_calendar(
|
||||
pnls,
|
||||
2026,
|
||||
6,
|
||||
"manual",
|
||||
_matches_manual,
|
||||
reset_hour=8,
|
||||
)
|
||||
self.assertEqual(payload["month"], 6)
|
||||
self.assertEqual(payload["month_open_count"], 2)
|
||||
days = payload["days"]
|
||||
self.assertIn("2026-06-18", days)
|
||||
self.assertNotIn("2026-06-19", days)
|
||||
self.assertEqual(days["2026-06-18"]["open_count"], 2)
|
||||
self.assertAlmostEqual(days["2026-06-18"]["pnl_total"], 7.0)
|
||||
|
||||
def test_invalid_month_raises(self):
|
||||
with self.assertRaises(ValueError):
|
||||
build_trade_stats_calendar([], 2026, 13, "all", _matches_all)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user