Merge origin/master: integrate auto-populate suggestions and set renumbering
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 36s
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 36s
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,6 +14,7 @@ from sqlmodel import Session
|
||||
from app.database import get_db_session
|
||||
from app.models.user import User
|
||||
from app.services.log_service import LogService
|
||||
from app.services.progression_service import ProgressionService
|
||||
from app.services.workout_session_service import WorkoutSessionService
|
||||
from app.utils.auth import require_active_profile, get_active_profile_id
|
||||
|
||||
@@ -25,7 +26,7 @@ router = APIRouter(prefix="/log", tags=["logging"])
|
||||
def _normalize_weight(raw: str) -> str:
|
||||
"""Convert numeric weight input to display format.
|
||||
|
||||
'0' or '' → 'BW', bare number → '{n} lbs', already formatted → pass through.
|
||||
'0' or '' -> 'BW', bare number -> '{n} lbs', already formatted -> pass through.
|
||||
"""
|
||||
raw = raw.strip()
|
||||
if not raw or raw == "0":
|
||||
@@ -39,6 +40,30 @@ def _normalize_weight(raw: str) -> str:
|
||||
return raw
|
||||
|
||||
|
||||
def _get_prefill_values(
|
||||
logs: list,
|
||||
session: Session,
|
||||
profile_id: int,
|
||||
exercise_id: int,
|
||||
) -> tuple:
|
||||
"""Get pre-fill values for the next set form.
|
||||
|
||||
If sets have already been logged this session, use the last logged
|
||||
set's values (users typically repeat the same reps/weight across sets).
|
||||
Otherwise, use the progression engine's suggestion.
|
||||
|
||||
Returns:
|
||||
(suggested_reps, suggested_weight) tuple.
|
||||
"""
|
||||
if logs:
|
||||
last = logs[-1]
|
||||
return last.reps_completed, last.weight_used
|
||||
|
||||
progression = ProgressionService(session)
|
||||
suggestion = progression.get_suggestion(profile_id, exercise_id)
|
||||
return suggestion.get("suggested_reps"), suggestion.get("suggested_weight")
|
||||
|
||||
|
||||
@router.post("", response_class=HTMLResponse)
|
||||
async def log_set(
|
||||
request: Request,
|
||||
@@ -80,6 +105,9 @@ async def log_set(
|
||||
# Return updated logs for this exercise
|
||||
logs = log_service.list_logs_for_exercise(ws.id, exercise_id)
|
||||
next_set = len(logs) + 1
|
||||
suggested_reps, suggested_weight = _get_prefill_values(
|
||||
logs, session, profile.id, exercise_id,
|
||||
)
|
||||
|
||||
templates = request.app.state.templates
|
||||
return templates.TemplateResponse("partials/log_entry.html", {
|
||||
@@ -89,6 +117,8 @@ async def log_set(
|
||||
"workout_day_id": workout_day_id,
|
||||
"next_set": next_set,
|
||||
"session_id": ws.id,
|
||||
"suggested_reps": suggested_reps,
|
||||
"suggested_weight": suggested_weight,
|
||||
})
|
||||
|
||||
|
||||
@@ -115,6 +145,13 @@ async def edit_log(
|
||||
logs = log_service.list_logs_for_exercise(log.session_id, log.exercise_id)
|
||||
next_set = len(logs) + 1
|
||||
|
||||
active_profile_id = get_active_profile_id(request)
|
||||
suggested_reps, suggested_weight = None, None
|
||||
if active_profile_id:
|
||||
suggested_reps, suggested_weight = _get_prefill_values(
|
||||
logs, session, active_profile_id, log.exercise_id,
|
||||
)
|
||||
|
||||
templates = request.app.state.templates
|
||||
return templates.TemplateResponse("partials/log_entry.html", {
|
||||
"request": request,
|
||||
@@ -123,6 +160,8 @@ async def edit_log(
|
||||
"workout_day_id": 0,
|
||||
"next_set": next_set,
|
||||
"session_id": log.session_id,
|
||||
"suggested_reps": suggested_reps,
|
||||
"suggested_weight": suggested_weight,
|
||||
})
|
||||
|
||||
|
||||
@@ -145,6 +184,13 @@ async def delete_log(
|
||||
logs = log_service.list_logs_for_exercise(session_id, exercise_id)
|
||||
next_set = len(logs) + 1
|
||||
|
||||
active_profile_id = get_active_profile_id(request)
|
||||
suggested_reps, suggested_weight = None, None
|
||||
if active_profile_id:
|
||||
suggested_reps, suggested_weight = _get_prefill_values(
|
||||
logs, session, active_profile_id, exercise_id,
|
||||
)
|
||||
|
||||
templates = request.app.state.templates
|
||||
return templates.TemplateResponse("partials/log_entry.html", {
|
||||
"request": request,
|
||||
@@ -153,6 +199,8 @@ async def delete_log(
|
||||
"workout_day_id": 0,
|
||||
"next_set": next_set,
|
||||
"session_id": session_id,
|
||||
"suggested_reps": suggested_reps,
|
||||
"suggested_weight": suggested_weight,
|
||||
})
|
||||
|
||||
return HTMLResponse("")
|
||||
|
||||
Reference in New Issue
Block a user