fix: wire metrics service to existing methods#1
Closed
Yurzi wants to merge 2 commits into
Closed
Conversation
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>
Owner
Author
|
改为向上游仓库提交:NickCharlie#193 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
重构整个项目为新架构(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