Add matched training signals, daily recovery and performance analysis
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
"""Private training preferences and session observations."""
|
||||
|
||||
from flask import Blueprint, abort, flash, redirect, request, url_for
|
||||
from flask_login import current_user, login_required
|
||||
|
||||
from .extensions import db
|
||||
from .models import Activity
|
||||
|
||||
training = Blueprint("training", __name__)
|
||||
|
||||
|
||||
@training.post("/training/bands")
|
||||
@login_required
|
||||
def bands():
|
||||
raw = [request.form.get("lower", "").strip(), request.form.get("upper", "").strip()]
|
||||
if not any(raw):
|
||||
current_user.hr_bands = None
|
||||
else:
|
||||
try:
|
||||
low, high = [int(v) for v in raw]
|
||||
except ValueError:
|
||||
abort(400)
|
||||
if not 30 <= low < high <= 240:
|
||||
abort(400)
|
||||
current_user.hr_bands = [low, high]
|
||||
db.session.commit()
|
||||
flash("Personal heart-rate bands saved.")
|
||||
return redirect(url_for("web.settings"))
|
||||
|
||||
|
||||
@training.post("/activities/<int:activity_id>/context")
|
||||
@login_required
|
||||
def context(activity_id):
|
||||
row = db.first_or_404(db.select(Activity).where(Activity.id == activity_id,
|
||||
Activity.owner_id == current_user.id))
|
||||
values = {}
|
||||
for field, low in (("perceived_effort", 1), ("fatigue", 0)):
|
||||
raw = request.form.get(field, "").strip()
|
||||
if raw:
|
||||
try:
|
||||
value = int(raw)
|
||||
except ValueError:
|
||||
abort(400)
|
||||
if not low <= value <= 10:
|
||||
abort(400)
|
||||
values[field] = value
|
||||
notes = request.form.get("notes", "").strip()
|
||||
if len(notes) > 2000:
|
||||
abort(400)
|
||||
values["notes"] = notes
|
||||
row.session_context = values
|
||||
db.session.commit()
|
||||
flash("Private session context saved.")
|
||||
return redirect(url_for("web.activity", activity_id=row.id))
|
||||
Reference in New Issue
Block a user