feat: 题材涨幅前20存历史(原前10)

- daily_collector TOP_THEME_LIMIT 10 → 20
- 同步 routes/collector 注释与 spec/plan 文档
- 实测 2026-08-10 题材前20入库 20 条,themes/history 返回 20 条

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Sakurasan
2026-08-10 21:27:54 +08:00
co-authored by Claude
parent 1c434a208a
commit 23644a9c77
5 changed files with 20 additions and 20 deletions
@@ -2,7 +2,7 @@
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** 每日收盘后采集核心股前100(按涨幅)+所属题材、题材涨幅前10存历史,并提供「活跃核心股×最近10个A股交易日」涨幅矩阵展示页。
**Goal:** 每日收盘后采集核心股前100(按涨幅)+所属题材、题材涨幅前20存历史,并提供「活跃核心股×最近10个A股交易日」涨幅矩阵展示页。
**Architecture:** 后端新增 asyncio 后台定时采集任务(`lifespan` 启动),复用现有 `services/themes.py``fetch_theme_list`/`fetch_theme_graph` 拿数据,写入 3 张新表;新增 `GET /api/core-stocks/active` 接口计算活跃窗口;前端新增 `/core-stocks` 路由渲染股票×10日涨幅矩阵。
@@ -103,7 +103,7 @@ git add backend/database.py && git commit -m "feat: 新增每日核心股/题材
- [ ] **Step 1: 新建采集服务**
```python
"""每日热点数据采集:核心股前100 + 题材涨幅前10,收盘后自动入库
"""每日热点数据采集:核心股前100 + 题材涨幅前20,收盘后自动入库
由 main.lifespan 启动后台任务;幂等(按交易日 UNIQUE 去重)。
"""
@@ -121,7 +121,7 @@ _CST = timezone(timedelta(hours=8))
CHECK_INTERVAL_SECONDS = 300
COLLECT_AFTER_TIME = dtime(15, 0) # 收盘后 15:00 开始允许采集
CORE_STOCK_LIMIT = 100 # 核心股前100
TOP_THEME_LIMIT = 10 # 题材前10
TOP_THEME_LIMIT = 20 # 题材涨幅前20
def _is_trading_day(d: datetime) -> bool:
@@ -178,11 +178,11 @@ async def collect_daily(trade_date: str, dry_run: bool = False) -> dict:
stock_map.values(), key=lambda x: -(x["f3"] or 0)
)[:_CORE_STOCK_LIMIT]
# 3. 题材前10bf3 降序
# 3. 题材涨幅前20bf3 降序
top_themes = sorted(themes, key=lambda x: -(x.get("bf3") or 0))[:_TOP_THEME_LIMIT]
if dry_run:
print(f"[collector] {trade_date} 核心股 {len(core_stocks)} 只,题材前10 {len(top_themes)}")
print(f"[collector] {trade_date} 核心股 {len(core_stocks)} 只,题材前20 {len(top_themes)}")
return {"core_count": len(core_stocks), "theme_count": len(top_themes), "skipped": False}
# 4. 入库(事务,UNIQUE 幂等)
@@ -202,7 +202,7 @@ async def collect_daily(trade_date: str, dry_run: bool = False) -> dict:
finally:
conn.close()
print(f"[collector] {trade_date} 已采集:核心股 {len(core_stocks)} 只,题材前10 {len(top_themes)}")
print(f"[collector] {trade_date} 已采集:核心股 {len(core_stocks)} 只,题材前20 {len(top_themes)}")
return {"core_count": len(core_stocks), "theme_count": len(top_themes), "skipped": False}
@@ -278,7 +278,7 @@ git add backend/services/daily_collector.py && git commit -m "feat: 每日核心
- [ ] **Step 1: 新建路由**
```python
"""核心股历史接口:活跃核心股 + 指定日核心股/题材前10"""
"""核心股历史接口:活跃核心股 + 指定日核心股/题材前20"""
from fastapi import APIRouter, Query
from fastapi.responses import JSONResponse