Spaces:
Running
Running
File size: 2,194 Bytes
d64fd55 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | from tools.helpers import serialize_charts
def serialize_snapshot(snapshot):
if not snapshot:
return None
def _safe_dump(obj):
if obj is None: return None
if isinstance(obj, dict): return obj
if hasattr(obj, "model_dump"): return obj.model_dump()
return str(obj)
return {
"id": str(snapshot.id) if snapshot.id else None,
"week_start": str(snapshot.week_start) if snapshot.week_start else None,
"training_state": snapshot.training_state,
"health_signal": snapshot.health_signal,
"positioning_status": snapshot.positioning_status,
"positioning_change": snapshot.positioning_change,
"goal_trajectory": snapshot.goal_trajectory,
"goal_progress_pct": snapshot.goal_progress_pct,
"next_run": snapshot.next_run,
"training_focus": snapshot.training_focus,
"training_why": snapshot.training_why,
"key_insight": snapshot.key_insight,
"forward_focus": snapshot.forward_focus,
"weekly_distance_km": snapshot.weekly_distance_km,
"num_runs": snapshot.num_runs,
"run_count": snapshot.run_count,
"consistency_score": snapshot.consistency_score,
"avg_pace": snapshot.avg_pace,
"avg_hr": snapshot.avg_hr,
"structure_status": _safe_dump(snapshot.structure_status),
"performance_brief": snapshot.performance_brief,
"performance_focus": snapshot.performance_focus,
"trend": _safe_dump(snapshot.trend),
"weekly_trend": _safe_dump(snapshot.weekly_trend),
"positioning": _safe_dump(snapshot.positioning),
"positioning_view": _safe_dump(snapshot.positioning_view),
"goal_trajectory_data": _safe_dump(snapshot.goal_trajectory_data),
"insights": _safe_dump(snapshot.insights),
"plan": snapshot.plan,
"recommendation": _safe_dump(snapshot.recommendation),
"charts": serialize_charts(snapshot.charts),
"weekly_brief": snapshot.weekly_brief,
"weekly_focus": snapshot.weekly_focus,
"active_goal": _safe_dump(snapshot.active_goal),
"goal_view": _safe_dump(snapshot.goal_view),
}
|