feat: add avatar metrics tracking feature (#111)
* feat: add avatar metrics tracking feature (#110) Add AvatarMetrics dataclass for tracking avatar state snapshots - Add AvatarMetrics dataclass for recording monthly snapshots - Add metrics_history field to Avatar with opt-in tracking - Implement automatic monthly snapshot recording in Simulator - Add backward compatibility support for existing save files - Set default tracking limit to 1200 months (100 years) - Add comprehensive tests with 100% coverage - Move documentation to specs directory with simplified chinese * fix: convert Traditional Chinese comments to Simplified Chinese 修正程式碼中的繁體中文註解為簡體中文,以符合專案規範。 Fix Traditional Chinese comments to Simplified Chinese in codebase.
This commit is contained in:
@@ -53,6 +53,7 @@ class AvatarLoadMixin:
|
||||
from src.classes.magic_stone import MagicStone
|
||||
from src.classes.action_runtime import ActionPlan
|
||||
from src.classes.elixir import elixirs_by_id, ConsumedElixir
|
||||
from src.classes.avatar_metrics import AvatarMetrics
|
||||
|
||||
# 重建基本对象
|
||||
gender = Gender(data["gender"])
|
||||
@@ -226,6 +227,14 @@ class AvatarLoadMixin:
|
||||
# 恢复临时效果
|
||||
avatar.temporary_effects = data.get("temporary_effects", [])
|
||||
|
||||
# 重建 metrics_history
|
||||
metrics_history_data = data.get("metrics_history", [])
|
||||
avatar.metrics_history = [
|
||||
AvatarMetrics.from_save_dict(metrics_data)
|
||||
for metrics_data in metrics_history_data
|
||||
]
|
||||
avatar.enable_metrics_tracking = data.get("enable_metrics_tracking", False)
|
||||
|
||||
# 加载完成后重新计算effects(确保数值正确)
|
||||
avatar.recalc_effects()
|
||||
|
||||
|
||||
@@ -107,7 +107,14 @@ class AvatarSaveMixin:
|
||||
} if self.long_term_objective else None,
|
||||
"_action_cd_last_months": self._action_cd_last_months,
|
||||
"known_regions": list(self.known_regions),
|
||||
|
||||
|
||||
# 状态追踪
|
||||
"metrics_history": [
|
||||
metrics.to_save_dict()
|
||||
for metrics in self.metrics_history
|
||||
] if self.enable_metrics_tracking else [],
|
||||
"enable_metrics_tracking": self.enable_metrics_tracking,
|
||||
|
||||
# 丹药
|
||||
"elixirs": [
|
||||
{
|
||||
|
||||
@@ -480,6 +480,11 @@ class Simulator:
|
||||
"""
|
||||
本轮步进的最终归档:去重、入库、打日志、推进时间。
|
||||
"""
|
||||
# 0. 为启用追踪的 Avatar 记录每月快照
|
||||
for avatar in self.world.avatar_manager.avatars.values():
|
||||
if avatar.enable_metrics_tracking:
|
||||
avatar.record_metrics()
|
||||
|
||||
# 1. 基于 ID 去重(防止同一个事件对象被多次添加)
|
||||
unique_events: dict[str, Event] = {}
|
||||
for e in events:
|
||||
|
||||
Reference in New Issue
Block a user