doris-barbell: seed john split and routine board
This commit is contained in:
@@ -6,29 +6,152 @@ from pathlib import Path
|
||||
from typing import Any
|
||||
from uuid import uuid4
|
||||
|
||||
DEFAULT_STATE = {
|
||||
'users': {
|
||||
'john': {
|
||||
'id': 'john',
|
||||
'display_name': 'John',
|
||||
'is_stub': False,
|
||||
'measurement_system': 'imperial',
|
||||
'height_inches': 68.5,
|
||||
'goal_weight_lbs': None,
|
||||
'notes': 'Seeded with John default height assumption from current intake.',
|
||||
},
|
||||
'manndra': {
|
||||
'id': 'manndra',
|
||||
'display_name': 'Manndra',
|
||||
'is_stub': True,
|
||||
'measurement_system': 'imperial',
|
||||
'height_inches': None,
|
||||
'goal_weight_lbs': None,
|
||||
'notes': 'Stubbed for future shared use.',
|
||||
},
|
||||
DEFAULT_USERS = {
|
||||
'john': {
|
||||
'id': 'john',
|
||||
'display_name': 'John',
|
||||
'is_stub': False,
|
||||
'measurement_system': 'imperial',
|
||||
'height_inches': 68.5,
|
||||
'goal_weight_lbs': None,
|
||||
'notes': 'Seeded with John default height assumption from current intake.',
|
||||
},
|
||||
'exercise_templates': [],
|
||||
'routines': [],
|
||||
'manndra': {
|
||||
'id': 'manndra',
|
||||
'display_name': 'Manndra',
|
||||
'is_stub': True,
|
||||
'measurement_system': 'imperial',
|
||||
'height_inches': None,
|
||||
'goal_weight_lbs': None,
|
||||
'notes': 'Stubbed for future shared use.',
|
||||
},
|
||||
}
|
||||
|
||||
SEEDED_EXERCISE_TEMPLATES = [
|
||||
{'name': 'Bench Press', 'primary_muscle': 'chest', 'equipment': 'barbell'},
|
||||
{'name': 'Incline Bench Press', 'primary_muscle': 'upper chest', 'equipment': 'barbell'},
|
||||
{'name': 'Decline Bench Press', 'primary_muscle': 'lower chest', 'equipment': 'barbell'},
|
||||
{'name': 'Butterflies', 'primary_muscle': 'chest', 'equipment': 'machine'},
|
||||
{'name': 'Lat Pulldowns', 'primary_muscle': 'back', 'equipment': 'cable'},
|
||||
{'name': 'Bent-Over Supported Rows', 'primary_muscle': 'back', 'equipment': 'machine'},
|
||||
{'name': 'Landmine Rows', 'primary_muscle': 'back', 'equipment': 'barbell'},
|
||||
{'name': 'Seated Machine Rows', 'primary_muscle': 'back', 'equipment': 'machine'},
|
||||
{'name': 'Resistance Band Ab Holds', 'primary_muscle': 'abs', 'equipment': 'band'},
|
||||
{'name': 'Lat Pulldown Drop Set', 'primary_muscle': 'back', 'equipment': 'cable'},
|
||||
{'name': 'Bicep Curls', 'primary_muscle': 'biceps', 'equipment': 'dumbbells'},
|
||||
{'name': 'Front Tricep Extensions', 'primary_muscle': 'triceps', 'equipment': 'cable'},
|
||||
{'name': 'Overhead Tricep Extensions', 'primary_muscle': 'triceps', 'equipment': 'cable'},
|
||||
{'name': 'Incline Barbell Curls', 'primary_muscle': 'biceps', 'equipment': 'barbell'},
|
||||
{'name': 'Isolation Bicep Curls', 'primary_muscle': 'biceps', 'equipment': 'machine'},
|
||||
{'name': '7-7-7 Barbell Curl', 'primary_muscle': 'biceps', 'equipment': 'barbell'},
|
||||
{'name': 'Suitcase Carry', 'primary_muscle': 'abs', 'equipment': 'dumbbell'},
|
||||
{'name': 'Shoulder Press', 'primary_muscle': 'shoulders', 'equipment': 'machine'},
|
||||
{'name': 'Arnold Press', 'primary_muscle': 'shoulders', 'equipment': 'dumbbells'},
|
||||
{'name': 'Side Lateral Raise', 'primary_muscle': 'shoulders', 'equipment': 'dumbbells'},
|
||||
{'name': 'Front Lateral Raise', 'primary_muscle': 'shoulders', 'equipment': 'dumbbells'},
|
||||
{'name': 'Upright Row', 'primary_muscle': 'shoulders', 'equipment': 'barbell'},
|
||||
{'name': 'Shoulder Shrugs', 'primary_muscle': 'traps', 'equipment': 'dumbbells'},
|
||||
{'name': '7-7-7 Shoulder Press', 'primary_muscle': 'shoulders', 'equipment': 'machine'},
|
||||
{'name': 'Resistance Band Punch-Out Holds', 'primary_muscle': 'abs', 'equipment': 'band'},
|
||||
{'name': 'Squats', 'primary_muscle': 'legs', 'equipment': 'barbell'},
|
||||
{'name': 'Leg Extensions', 'primary_muscle': 'quads', 'equipment': 'machine'},
|
||||
{'name': 'Step Ups', 'primary_muscle': 'legs', 'equipment': 'bodyweight'},
|
||||
{'name': 'Deadlifts', 'primary_muscle': 'posterior chain', 'equipment': 'barbell'},
|
||||
{'name': 'Calf Raises', 'primary_muscle': 'calves', 'equipment': 'machine'},
|
||||
{'name': 'Resistance Band Crunches', 'primary_muscle': 'abs', 'equipment': 'band'},
|
||||
]
|
||||
|
||||
SEEDED_ROUTINES = [
|
||||
{
|
||||
'user_id': 'john',
|
||||
'name': 'Monday: Chest',
|
||||
'notes': "Imported from John's current routine. Default prescription is 3 sets of 10 reps. Weights are still TBD.",
|
||||
'exercises': [
|
||||
{'exercise_name': 'Bench Press', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Incline Bench Press', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Decline Bench Press', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Butterflies', 'target_sets': 3, 'target_reps': '10'},
|
||||
],
|
||||
},
|
||||
{
|
||||
'user_id': 'john',
|
||||
'name': 'Tuesday: Back',
|
||||
'notes': "Imported from John's current routine. Default prescription is 3 sets of 10 reps. Weights are still TBD.",
|
||||
'exercises': [
|
||||
{'exercise_name': 'Lat Pulldowns', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Bent-Over Supported Rows', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Landmine Rows', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Seated Machine Rows', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Resistance Band Ab Holds', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Lat Pulldown Drop Set', 'target_sets': 3, 'target_reps': '10'},
|
||||
],
|
||||
},
|
||||
{
|
||||
'user_id': 'john',
|
||||
'name': 'Wednesday: Arms',
|
||||
'notes': "Imported from John's current routine. Default prescription is 3 sets of 10 reps. Weights are still TBD. Includes Bis and Tris focus plus suitcase carries for abs.",
|
||||
'exercises': [
|
||||
{'exercise_name': 'Bicep Curls', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Front Tricep Extensions', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Overhead Tricep Extensions', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Incline Barbell Curls', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Isolation Bicep Curls', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': '7-7-7 Barbell Curl', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Suitcase Carry', 'target_sets': 3, 'target_reps': '10'},
|
||||
],
|
||||
},
|
||||
{
|
||||
'user_id': 'john',
|
||||
'name': 'Thursday: Shoulders',
|
||||
'notes': "Imported from John's current routine. Default prescription is 3 sets of 10 reps. Weights are still TBD. Includes resistance band punch-out ab holds.",
|
||||
'exercises': [
|
||||
{'exercise_name': 'Shoulder Press', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Arnold Press', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Side Lateral Raise', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Front Lateral Raise', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Upright Row', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Shoulder Shrugs', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': '7-7-7 Shoulder Press', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Resistance Band Punch-Out Holds', 'target_sets': 3, 'target_reps': '10'},
|
||||
],
|
||||
},
|
||||
{
|
||||
'user_id': 'john',
|
||||
'name': 'Friday: Legs',
|
||||
'notes': "Imported from John's current routine. Default prescription is 3 sets of 10 reps. Weights are still TBD. Includes resistance band crunches for abs.",
|
||||
'exercises': [
|
||||
{'exercise_name': 'Squats', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Leg Extensions', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Step Ups', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Deadlifts', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Calf Raises', 'target_sets': 3, 'target_reps': '10'},
|
||||
{'exercise_name': 'Resistance Band Crunches', 'target_sets': 3, 'target_reps': '10'},
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
DEFAULT_STATE = {
|
||||
'users': DEFAULT_USERS,
|
||||
'exercise_templates': [
|
||||
{
|
||||
'id': f'seed-template-{index + 1:02d}',
|
||||
'name': template['name'],
|
||||
'primary_muscle': template.get('primary_muscle'),
|
||||
'equipment': template.get('equipment'),
|
||||
'notes': template.get('notes'),
|
||||
}
|
||||
for index, template in enumerate(SEEDED_EXERCISE_TEMPLATES)
|
||||
],
|
||||
'routines': [
|
||||
{
|
||||
'id': f'seed-routine-{index + 1:02d}',
|
||||
'user_id': routine['user_id'],
|
||||
'name': routine['name'],
|
||||
'notes': routine.get('notes'),
|
||||
'exercises': [dict(exercise) for exercise in routine['exercises']],
|
||||
}
|
||||
for index, routine in enumerate(SEEDED_ROUTINES)
|
||||
],
|
||||
'weight_entries': [],
|
||||
'measurement_entries': [],
|
||||
'workout_sessions': [],
|
||||
@@ -42,6 +165,11 @@ class JSONStore:
|
||||
self.state_dir.mkdir(parents=True, exist_ok=True)
|
||||
if not self.state_path.exists():
|
||||
self._write(deepcopy(DEFAULT_STATE))
|
||||
return
|
||||
state = self._read()
|
||||
seeded_state = _ensure_seeded_library(state)
|
||||
if seeded_state != state:
|
||||
self._write(seeded_state)
|
||||
|
||||
def _read(self) -> dict[str, Any]:
|
||||
return json.loads(self.state_path.read_text())
|
||||
@@ -243,11 +371,13 @@ class JSONStore:
|
||||
key=lambda item: item['performed_at'],
|
||||
reverse=True,
|
||||
)[:5]
|
||||
recent_templates = list(reversed(state['exercise_templates'][-5:]))
|
||||
routine_board = _routine_board(state['routines'])
|
||||
return {
|
||||
'users': users,
|
||||
'recent_workouts': recent_workouts,
|
||||
'exercise_templates': self.list_exercise_templates()[:5],
|
||||
'routines': self.list_routines()[:5],
|
||||
'exercise_templates': recent_templates,
|
||||
'routines': routine_board,
|
||||
'counts': {
|
||||
'exercise_templates': len(state['exercise_templates']),
|
||||
'measurement_entries': len(state['measurement_entries']),
|
||||
@@ -276,6 +406,76 @@ def _history_for_user(entries: list[dict[str, Any]], user_id: str, sort_key: str
|
||||
return sorted(matches, key=lambda item: item[sort_key], reverse=True)
|
||||
|
||||
|
||||
def _ensure_seeded_library(state: dict[str, Any]) -> dict[str, Any]:
|
||||
payload = deepcopy(state)
|
||||
payload.setdefault('users', deepcopy(DEFAULT_USERS))
|
||||
payload.setdefault('exercise_templates', [])
|
||||
payload.setdefault('routines', [])
|
||||
payload.setdefault('weight_entries', [])
|
||||
payload.setdefault('measurement_entries', [])
|
||||
payload.setdefault('workout_sessions', [])
|
||||
|
||||
existing_template_names = {
|
||||
item.get('name', '').strip().lower()
|
||||
for item in payload['exercise_templates']
|
||||
if item.get('name')
|
||||
}
|
||||
for index, template in enumerate(SEEDED_EXERCISE_TEMPLATES, start=1):
|
||||
normalized_name = template['name'].strip().lower()
|
||||
if normalized_name in existing_template_names:
|
||||
continue
|
||||
payload['exercise_templates'].append(
|
||||
{
|
||||
'id': f'seed-template-{index:02d}',
|
||||
'name': template['name'],
|
||||
'primary_muscle': template.get('primary_muscle'),
|
||||
'equipment': template.get('equipment'),
|
||||
'notes': template.get('notes'),
|
||||
}
|
||||
)
|
||||
existing_template_names.add(normalized_name)
|
||||
|
||||
existing_routines = {
|
||||
item.get('name', '').strip().lower(): item
|
||||
for item in payload['routines']
|
||||
if item.get('name')
|
||||
}
|
||||
for index, routine in enumerate(SEEDED_ROUTINES, start=1):
|
||||
normalized_name = routine['name'].strip().lower()
|
||||
existing_routine = existing_routines.get(normalized_name)
|
||||
seeded_exercises = [dict(exercise) for exercise in routine['exercises']]
|
||||
if existing_routine is not None:
|
||||
existing_routine['user_id'] = routine['user_id']
|
||||
existing_routine['notes'] = routine.get('notes')
|
||||
existing_routine['exercises'] = seeded_exercises
|
||||
continue
|
||||
new_routine = {
|
||||
'id': f'seed-routine-{index:02d}',
|
||||
'user_id': routine['user_id'],
|
||||
'name': routine['name'],
|
||||
'notes': routine.get('notes'),
|
||||
'exercises': seeded_exercises,
|
||||
}
|
||||
payload['routines'].append(new_routine)
|
||||
existing_routines[normalized_name] = new_routine
|
||||
|
||||
return payload
|
||||
|
||||
|
||||
def _routine_board(routines: list[dict[str, Any]]) -> list[dict[str, Any]]:
|
||||
by_name = {
|
||||
routine.get('name', '').strip().lower(): routine
|
||||
for routine in routines
|
||||
if routine.get('name')
|
||||
}
|
||||
ordered = []
|
||||
for seeded_routine in SEEDED_ROUTINES:
|
||||
matched = by_name.get(seeded_routine['name'].strip().lower())
|
||||
if matched is not None:
|
||||
ordered.append(matched)
|
||||
return ordered
|
||||
|
||||
|
||||
def _trim_measurement_entry(entry: dict[str, Any] | None) -> dict[str, Any] | None:
|
||||
if entry is None:
|
||||
return None
|
||||
|
||||
@@ -171,28 +171,35 @@
|
||||
</article>
|
||||
|
||||
<article class="card evidence-board">
|
||||
<div class="case-legend"><span class="section-label">Library snapshot</span><span class="pill">Scaffold</span></div>
|
||||
<h2>Template and routine scaffold</h2>
|
||||
<p class="muted">You can start building the library now, even before the real split lands tomorrow.</p>
|
||||
<div class="case-legend"><span class="section-label">Current split</span><span class="pill">Routine board</span></div>
|
||||
<h2>Current routine board</h2>
|
||||
<p class="muted">John's current five-day split is now loaded as the default routine library with a default prescription of 3 sets of 10 reps. Weights are still TBD.</p>
|
||||
<ul class="list case-list">
|
||||
<li>Exercise templates: {{ summary.counts.exercise_templates }}</li>
|
||||
<li>Routines: {{ summary.counts.routines }}</li>
|
||||
</ul>
|
||||
{% if summary.exercise_templates %}
|
||||
<p><strong>Templates</strong></p>
|
||||
<ul class="list">
|
||||
{% for template in summary.exercise_templates %}
|
||||
<li>{{ template.name }}{% if template.equipment %} · {{ template.equipment }}{% endif %}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
{% if summary.routines %}
|
||||
<p><strong>Routines</strong></p>
|
||||
<ul class="list">
|
||||
{% for routine in summary.routines %}
|
||||
<li>{{ routine.name }} · {{ routine.exercises|length }} exercises</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<div class="history-block">
|
||||
<h3>Loaded routine days</h3>
|
||||
<ul class="list">
|
||||
{% for routine in summary.routines %}
|
||||
<li>
|
||||
<strong>{{ routine.name }}</strong>
|
||||
<p class="muted">{{ routine.exercises|length }} exercises{% if routine.notes %} · {{ routine.notes }}{% endif %}</p>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if summary.exercise_templates %}
|
||||
<div class="history-block">
|
||||
<h3>Template snapshot</h3>
|
||||
<ul class="list">
|
||||
{% for template in summary.exercise_templates %}
|
||||
<li>{{ template.name }}{% if template.equipment %} · {{ template.equipment }}{% endif %}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
</article>
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user