56 lines
2.1 KiB
Python
56 lines
2.1 KiB
Python
from typing import Any
|
||
|
||
from sqlalchemy.orm import Session
|
||
|
||
from app.fitness.service import FitnessService
|
||
|
||
|
||
def get_fitness_snapshot(db: Session) -> dict[str, Any]:
|
||
return FitnessService(db).snapshot()
|
||
|
||
|
||
def format_fitness_context(snapshot: dict[str, Any]) -> str:
|
||
lines = ["[Фитнес — сводка на сегодня]"]
|
||
|
||
profile = snapshot.get("profile")
|
||
if not profile:
|
||
lines.append("Профиль не настроен. set_fitness_profile для целей ккал/БЖУ/воды.")
|
||
else:
|
||
lines.append(
|
||
f"Цели: {profile.get('calorie_target')} ккал, "
|
||
f"Б {profile.get('protein_g')} / Ж {profile.get('fat_g')} / У {profile.get('carbs_g')} г, "
|
||
f"вода {profile.get('water_l')} л"
|
||
)
|
||
if profile.get("goal"):
|
||
lines.append(
|
||
f"Цель: {profile.get('goal')}, вес {profile.get('weight_kg')} кг, "
|
||
f"рост {profile.get('height_cm')} см"
|
||
)
|
||
|
||
today = snapshot.get("today") or {}
|
||
totals = today.get("totals") or {}
|
||
targets = today.get("targets") or {}
|
||
water_l = totals.get("water_ml", 0) / 1000
|
||
water_target = targets.get("water_ml", 2500) / 1000
|
||
|
||
lines.append("")
|
||
lines.append(
|
||
f"Съедено: {totals.get('calories', 0):.0f}/{targets.get('calories', 0):.0f} ккал · "
|
||
f"Б {totals.get('protein_g', 0):.0f}/{targets.get('protein_g', 0):.0f} · "
|
||
f"Ж {totals.get('fat_g', 0):.0f}/{targets.get('fat_g', 0):.0f} · "
|
||
f"У {totals.get('carbs_g', 0):.0f}/{targets.get('carbs_g', 0):.0f} г"
|
||
)
|
||
lines.append(f"Вода: {water_l:.1f}/{water_target:.1f} л")
|
||
|
||
workouts = today.get("workouts") or []
|
||
if workouts:
|
||
lines.append(f"Тренировок сегодня: {len(workouts)}")
|
||
|
||
lines.append("")
|
||
lines.append(
|
||
"Правила: log_meal, log_water, log_weight, log_workout, get_fitness_summary, "
|
||
"set_fitness_profile, calc_fitness_targets, lookup_food, lookup_exercise. "
|
||
"Еда — оценка LLM (≈), пользователь может уточнить."
|
||
)
|
||
return "\n".join(lines)
|