Weekly results for every team — workouts, weight change, check-ins and bonus points rolled into one score.
Each team logs one row per week. Baseline (week 0) is weights only. Everything below is stored per team, not per person, so it's fast to enter and private enough to share.
Total sessions logged by the whole team that week. Target is 5 per member.
25 → +10 pts eachSum of member weights (kg) at the end of the week. The dashboard shows kg lost against the week-0 baseline.
8.8 kg lost → +20 pts per kgHow many members submitted their weekly check-in (photo + numbers). Shown as a % of the team.
80% → +1 pt per %Weekly challenges, habit streaks, step goals — whatever the coaches set. Awarded per team.
+25score = workouts × 10 + checkin_% + kg_lost × 20 + bonus_points
Weights are deliberately simple so anyone can sanity-check the leaderboard by hand. Change them in one place — the v_team_week view in db/schema.sql — and every week recalculates.
Coaches enter one row per team each week. Re-submitting the same team + week overwrites it, so fixes are painless.
/api/results.POST to /api/teams with the admin key:
curl -X POST https://YOUR-SITE.pages.dev/api/teams \
-H "x-admin-key: $ADMIN_KEY" -H "content-type: application/json" \
-d '{"name":"Iron Wolves","captain":"Mitch","member_count":5}'
Run against the D1 database from your laptop:
npx wrangler d1 execute ub-challenge-db --remote --command \ "INSERT INTO weekly_results (team_id, week, workouts, total_weight_kg, checkins, bonus_points) VALUES (1, 5, 23, 451.0, 5, 20) ON CONFLICT (team_id, week) DO UPDATE SET workouts=excluded.workouts, total_weight_kg=excluded.total_weight_kg, checkins=excluded.checkins, bonus_points=excluded.bonus_points;"
curl -X POST https://YOUR-SITE.pages.dev/api/results \
-H "x-admin-key: $ADMIN_KEY" -H "content-type: application/json" \
-d '{"team_id":1,"week":5,"workouts":23,"total_weight_kg":451.0,
"checkins":5,"bonus_points":20}'
DB → ub-challenge-db (or keep wrangler.toml).ADMIN_KEY (long random string). Share it only with coaches.