Files
zhixing-system/.trellis/tasks/09-21-radar-weighted-score-rank-change/research/code-evidence.md
T

3.4 KiB
Raw Blame History

现有实现与改动定位

只读研究已完成:/root/radar_storage_research、/root/radar_ui_research,主会话另行阅读领域算法、models、read、build 和 HTTP 相关契约。

领域与应用

  • domain/metrics.py:140 起,旧 SwingEqualThreeToTenStrategy 取 3–10 日八个窗口的累计净额/累计成交额,再等权平均;需采用新版本,不能把它误认作前置研究的两个窗口。
  • domain/ranking.py:42 的排序键按 observation.value 排序;with_rank_changes 同版本过去名次减当前名次;select_rank_change_side 已实现 ceil(N×10%),不需另写重复算法。
  • application/build.py:694 的 _rank 读取 9 个历史成功日期再拼当前日;历史排名取前 5 次成功发布,并非严格前 5 交易日。
  • application/build.py:753 的 input_hash 包含策略版本;重算可沿用版本隔离与幂等思路。
  • application/read.py 的 _METRIC_DEFINITIONS 和 application/details.py:25 的 _METRIC_VERSIONS 都硬编码当前策略;升级必须让旧发布保持可读。
  • application/read.py:289 的 extras 只服务 amount/ratio,swing/rank_change 的涨跌幅、净额和辅助字段需要补齐。
  • application/details.py:173 的 history_data 已按发布来源中的交易日历补出缺口,适合统一严格交易日语义;必须避免每行单独查库。

存储

  • domain/persistence.py:294–355 定义 aggregate、ranking、history 读写契约。
  • infrastructure/postgres.py:532–710 为事务发布,:741–778 为 ranking 批写,:1145–1173 为序列化,:1239–1267 为固定列反序列化。
  • ranking SELECT 位于 postgres.py:871–964、:996–1033,当前只含 metric_value,没有 score。
  • postgres.py:966–994 的 aggregate history 只返回原始金额/coverage,不包含 publication_id、pct_change、leading_code,离线重算需要精确来源记录。
  • 最新迁移为 0009_radar_sector_detail。新增 score 应采用独立 migration,旧值可空。
  • 单测 tests/unit/sector_radar/test_postgres_repository.py:43–65 使用 17 列 fake row,必须随查询同步。现有集成测试尚未覆盖 ranking/aggregate 往返。

前端

  • pages/sector-radar-page.tsx:209–229 已有两个下拉,分别为变化指标/对比区间;改为截图的按钮组与统计天数次行。
  • pages/sector-radar-page.tsx:406–428 顶部双榜和中央标题仍是普通资金榜文案。
  • pages/sector-radar-page.tsx:430–463、:643–708 是单日/波段镜像列,无 score。
  • pages/sector-radar-page.tsx:465–500 的变化榜目前只显示样本、排名百分位与一个变化值;应展示涨跌幅及另外两项指标变化。
  • api/sector-radar.types.ts:61–114 与 api/sector-radar.api.ts:277–377 仅承载单个 rank_change,需扩展。
  • 路由与 query key 已保存基准/天数,保留这一结构;URL 显式值优先。
  • 页面测试 sector-radar-page.test.tsx:654–683 已覆盖正变化/缺历史,需增加评分、三基准五窗口、镜像辅助列、侧内排序与截图文案。

参考站核对

本会话下载的 /tmp/onechart-public-evidence/index.html 中::1197 默认 Swing/1 日,:1380 附近 mirrorMetricLabel 随基准变,:1397–1427 的 mirrorAuxColumns 在变化榜显示另外两个基准,在单日/波段榜显示 score/净额/在榜。前置研究完整来源和数值证据位于已归档的评分研究任务。