fix
This commit is contained in:
@@ -18,6 +18,7 @@ from backend.app.services.fit_parser import parse_fit_file
|
||||
from backend.app.services.metrics import calculate_metrics
|
||||
from backend.app.services.intervals import detect_intervals
|
||||
from backend.app.services.power_curve import calculate_power_curve
|
||||
from backend.app.services.coaching import link_activity_to_plan
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -57,27 +58,34 @@ async def process_fit_upload(content: bytes, rider: Rider) -> Activity:
|
||||
# Re-attach rider to this session
|
||||
rider = await session.get(Rider, rider.id)
|
||||
|
||||
activity, data_points = parse_fit_file(content, rider.id, str(file_path))
|
||||
activity, data_points, exercise_sets = parse_fit_file(content, rider.id, str(file_path))
|
||||
if exercise_sets:
|
||||
activity.exercise_sets = exercise_sets
|
||||
|
||||
# Auto-link to training plan
|
||||
await link_activity_to_plan(activity, rider.id, session)
|
||||
|
||||
session.add(activity)
|
||||
await session.flush()
|
||||
|
||||
for dp in data_points:
|
||||
dp.activity_id = activity.id
|
||||
session.add_all(data_points)
|
||||
if data_points:
|
||||
for dp in data_points:
|
||||
dp.activity_id = activity.id
|
||||
session.add_all(data_points)
|
||||
|
||||
metrics = calculate_metrics(data_points, activity, ftp=rider.ftp)
|
||||
if metrics:
|
||||
session.add(metrics)
|
||||
metrics = calculate_metrics(data_points, activity, ftp=rider.ftp)
|
||||
if metrics:
|
||||
session.add(metrics)
|
||||
|
||||
intervals = detect_intervals(data_points, ftp=rider.ftp)
|
||||
for interval in intervals:
|
||||
interval.activity_id = activity.id
|
||||
session.add_all(intervals)
|
||||
intervals = detect_intervals(data_points, ftp=rider.ftp)
|
||||
for interval in intervals:
|
||||
interval.activity_id = activity.id
|
||||
session.add_all(intervals)
|
||||
|
||||
curve_data = calculate_power_curve(data_points)
|
||||
if curve_data:
|
||||
pc = PowerCurve(activity_id=activity.id, curve_data=curve_data)
|
||||
session.add(pc)
|
||||
curve_data = calculate_power_curve(data_points)
|
||||
if curve_data:
|
||||
pc = PowerCurve(activity_id=activity.id, curve_data=curve_data)
|
||||
session.add(pc)
|
||||
|
||||
await session.commit()
|
||||
await session.refresh(activity)
|
||||
@@ -134,7 +142,7 @@ async def handle_document(message: Message, bot: Bot):
|
||||
|
||||
m = activity.metrics
|
||||
lines = [
|
||||
f"*{activity.name or 'Ride'}*",
|
||||
f"*{activity.name or 'Workout'}*",
|
||||
f"Duration: {format_duration(activity.duration)}",
|
||||
]
|
||||
|
||||
@@ -156,6 +164,22 @@ async def handle_document(message: Message, bot: Bot):
|
||||
lines.append(f"Avg HR: {m.avg_hr} bpm")
|
||||
if m.avg_cadence:
|
||||
lines.append(f"Avg Cadence: {m.avg_cadence} rpm")
|
||||
if m.calories:
|
||||
lines.append(f"Calories: {m.calories} kcal")
|
||||
|
||||
# Exercise sets for strength workouts
|
||||
if activity.exercise_sets:
|
||||
exercises: dict[str, list] = {}
|
||||
for s in activity.exercise_sets:
|
||||
name = s.get("exercise_name", "Unknown")
|
||||
exercises.setdefault(name, []).append(s)
|
||||
lines.append("")
|
||||
for name, sets in exercises.items():
|
||||
reps_str = " / ".join(
|
||||
f"{s.get('repetitions', '?')}x{s.get('weight', 0):.0f}kg" if s.get('weight') else f"{s.get('repetitions', '?')} reps"
|
||||
for s in sets
|
||||
)
|
||||
lines.append(f" {name}: {reps_str}")
|
||||
|
||||
intervals_count = len(activity.intervals or [])
|
||||
if intervals_count > 0:
|
||||
|
||||
Reference in New Issue
Block a user