feat: add experience tag statistics API

- Added GET /api/v1/trade-review/experiences/tag-stats endpoint
- Returns tag name, count, tag_id, category, and is_preset flag
- Sorted by count descending using Counter
- Verified app imports and reflection tests pass
refactor3.0
Lxy 2 weeks ago
parent f6cde33909
commit d366a3e920

@ -1044,6 +1044,37 @@ def api_delete_experience(
return {"success": True, "message": "经验已删除"}
@router.get("/experiences/tag-stats")
def api_get_experience_tag_stats(
db: Session = Depends(get_analysis_db),
):
"""按标签统计经验数量"""
from collections import Counter
experiences = db.query(TradeExperience).all()
tag_counter = Counter()
for exp in experiences:
for tag in (exp.tags or []):
tag_counter[tag] += 1
# 同时返回所有标签的定义信息
tags = db.query(TradeTag).all()
tag_map = {t.name: {"id": t.id, "category": t.category, "is_preset": t.is_preset} for t in tags}
data = []
for name, count in tag_counter.most_common():
info = tag_map.get(name, {})
data.append({
"name": name,
"count": count,
"tag_id": info.get("id"),
"category": info.get("category", "custom"),
"is_preset": info.get("is_preset", False),
})
return {"success": True, "data": data}
# ==================== AI 重新分析 ====================
class ReanalyzeRequest(BaseModel):

@ -59,7 +59,7 @@
- [x] 7.2 实现按天获取交易+配对数据的前端调用
- [x] 7.3 实现交易配对卡片展示(开仓→平仓箭头样式)
- [x] 7.4 实现未配对交易单独展示
- [ ] 7.5 实现手动配对交互(选择开仓+平仓→确认配对)
- [x] 7.5 实现手动配对交互(选择开仓+平仓→确认配对)
- [x] 7.6 实现当天统计卡片(总盈亏、交易笔数、胜率等)
## 8. 前端 - 反思编辑面板
@ -81,7 +81,7 @@
## 10. 前端 - AI 分析结果展示
- [x] 10.1 创建 AI 分析结果展示面板
- [ ] 10.2 实现多版本分析结果切换
- [x] 10.2 实现多版本分析结果切换
- [x] 10.3 实现经验提炼建议展示和编辑
- [x] 10.4 实现经验保存交互
@ -96,8 +96,8 @@
- [x] 12.1 创建经验库独立页面/Tab
- [x] 12.2 实现经验列表视图(卡片样式)
- [x] 12.3 实现搜索框和筛选栏(标签筛选、类型筛选)
- [ ] 12.4 实现分页加载
- [ ] 12.5 实现经验详情弹窗(含来源交易链接)
- [x] 12.4 实现分页加载
- [x] 12.5 实现经验详情弹窗(含来源交易链接)
- [x] 12.6 实现时间线视图切换
- [x] 12.7 实现分类视图切换(按标签分组)

Loading…
Cancel
Save