feat: enhance achievement display and update API documentation
This commit is contained in:
+57
-3
@@ -136,10 +136,9 @@ curl -X POST 'http://127.0.0.1:8080/api/v1/smoke/logs' \
|
||||
"next_suggested_clock": "10:30",
|
||||
"suggestion_source": "default"
|
||||
},
|
||||
"summary": {
|
||||
"summary": {
|
||||
"today_count": 3,
|
||||
"daily_target": 10,
|
||||
"resisted_count": 1,
|
||||
"reduced_from_yesterday": 2,
|
||||
"exceeded_yesterday": false
|
||||
},
|
||||
@@ -158,7 +157,6 @@ curl -X POST 'http://127.0.0.1:8080/api/v1/smoke/logs' \
|
||||
- `timer.suggestion_source`:建议来源(`default`/`ai`)。
|
||||
- `summary.today_count`:今日吸烟支数累加。
|
||||
- `summary.daily_target`:每日目标。
|
||||
- `summary.resisted_count`:今日忍住次数。
|
||||
- `summary.reduced_from_yesterday`:与昨日的绝对差值(非负)。
|
||||
- `summary.exceeded_yesterday`:是否比昨天多。
|
||||
- `daily_summary`:当天已缓存的 AI 日总结;无缓存时为 `null`。
|
||||
@@ -372,3 +370,59 @@ AI 生成说明:
|
||||
- `money.expected_total`:按“统计周期内有记录的天数”×`baseline_cigs_per_day` 计算;不统计无日志的天数。
|
||||
- `money.saved_cent`:按 `max(expected_total - actual_total, 0)` 计算,避免出现负值。
|
||||
- `health.available=false`:表示无历史记录。
|
||||
|
||||
## 15) 成就主题与当前称号
|
||||
|
||||
`GET /api/v1/smoke/achievement/themes`
|
||||
|
||||
返回 onboarding 可选择的称号主题。每个主题包含 `icon/name/key/levels`,前端在“重填问卷”中展示。
|
||||
|
||||
`GET /api/v1/smoke/achievement`
|
||||
|
||||
返回当前用户所选主题下的当前等级、下一等级和进度。记录抽烟模式使用“少抽积分”进阶;戒烟打卡模式仍使用连续记录天数进阶。
|
||||
|
||||
记录模式少抽积分算法:
|
||||
- 统计窗口:从 `onboarding_completed_at` 到今天,最多回看最近 90 天。
|
||||
- 只统计有记录的日期,避免无记录日期被误判为 0 根。
|
||||
- 每日基础分:`max(0, baseline_cigs_per_day - 当日抽烟支数)`。
|
||||
- 当日少抽比例 `>=30%` 额外 `+1` 分。
|
||||
- 当日少抽比例 `>=60%` 额外 `+2` 分。
|
||||
- 当日抽烟支数为 `0` 额外 `+3` 分。
|
||||
- 总积分用于匹配所选主题的等级阈值;`fa_achievement_level.required_days` 在记录模式下作为 `required_score` 使用。
|
||||
|
||||
成功响应示例:
|
||||
```json
|
||||
{
|
||||
"code": 200,
|
||||
"message": "success",
|
||||
"data": {
|
||||
"achievement": {
|
||||
"theme_id": 1,
|
||||
"theme_name": "意志骑士",
|
||||
"theme_key": "knight",
|
||||
"theme_icon": "🛡️",
|
||||
"metric_type": "score",
|
||||
"score": 48,
|
||||
"metrics": {
|
||||
"baseline_cigs_per_day": 10,
|
||||
"scored_days": 7,
|
||||
"total_reduced_cigs": 36,
|
||||
"today_reduced_cigs": 4,
|
||||
"today_reduce_percent": 40,
|
||||
"stable_days": 6
|
||||
},
|
||||
"current": {
|
||||
"name": "见习骑士",
|
||||
"icon": "🛡️",
|
||||
"required_score": 30
|
||||
},
|
||||
"next": {
|
||||
"name": "白银骑士",
|
||||
"icon": "⚔️",
|
||||
"required_score": 80
|
||||
},
|
||||
"progress": 0.36
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user