Skip to content

fix: wire metrics service to existing methods#1

Closed
Yurzi wants to merge 2 commits into
mainfrom
fix/metrics-service-method-mismatch
Closed

fix: wire metrics service to existing methods#1
Yurzi wants to merge 2 commits into
mainfrom
fix/metrics-service-method-mismatch

Conversation

@Yurzi

@Yurzi Yurzi commented Jun 10, 2026

Copy link
Copy Markdown
Owner

背景

重构整个项目为新架构(e46b634)之后,webui/services/metrics_service.py 里残留了对已不存在方法的调用,导致三个 WebUI 指标接口实际上一直失效:

调用的方法 实际情况
intelligence_metrics_service.calculate_metrics() 不存在,真实方法是 calculate_learning_efficiency(...)
database_manager.get_diversity_metrics() 不存在,无对应数据源
database_manager.get_affection_metrics() 不存在,真实方法是 get_all_user_affections()

由于调用都包在 try/except 内,不会崩溃,但每次请求都抛 AttributeError、刷错误日志,并返回全 0 兜底数据

修改内容(webui/services/metrics_service.py

  • 智能指标:先经 get_detailed_metrics / get_all_user_affections 收集输入,再调用真实的 calculate_learning_efficiency(...),并将 LearningEfficiencyMetrics 映射为约定的 {overall_score, dimensions, trends}
  • 好感度指标:改用 get_all_user_affections(group_id),真实计算平均好感度、用户数、高/低好感度人数(≥70 / ≤30)及五档分布。
  • 多样性指标:当前架构无独立数据源,基于风格模式数做透明近似估算,保持返回结构、不再刷错误日志。

验证

现有测试未覆盖 MetricsService,建议启动后手动请求确认日志不再报 AttributeError

  • GET /api/intelligence_metrics?group_id=<群号>
  • GET /api/diversity_metrics?group_id=<群号>
  • GET /api/affection_metrics?group_id=<群号>

🤖 Generated with Claude Code

Yurzi and others added 2 commits June 10, 2026 21:18
The big architecture refactor (e46b634) left MetricsService calling
methods that no longer exist:

- intelligence_metrics_service.calculate_metrics()
- database_manager.get_diversity_metrics()
- database_manager.get_affection_metrics()

Each call raised AttributeError on every request, spamming error logs
and making the three WebUI metrics endpoints always return zeroed
fallback data.

Rewire the three methods to the real APIs:

- intelligence: gather inputs via get_detailed_metrics /
  get_all_user_affections, then call calculate_learning_efficiency and
  map LearningEfficiencyMetrics to {overall_score, dimensions, trends}
- affection: compute from get_all_user_affections (average, user count,
  high/low counts, distribution buckets)
- diversity: best-effort estimate from style patterns, no error spam

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Update the stale conftest mocks that mirrored the removed methods
(get_diversity_metrics / get_affection_metrics / calculate_metrics) to
the real API now used by MetricsService (get_detailed_metrics /
get_all_user_affections / calculate_learning_efficiency).

Add integration tests for /api/intelligence_metrics, /api/affection_metrics
and /api/diversity_metrics asserting they return real computed data with no
error key, guarding against the AttributeError regression.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@Yurzi

Yurzi commented Jun 10, 2026

Copy link
Copy Markdown
Owner Author

改为向上游仓库提交:NickCharlie#193

@Yurzi Yurzi closed this Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant