- Plan takes rpe_targets, one RPE per week; its length sets the block length. - src/language/opengym.py converts a plan into OpenGym routines queued as a rotation and pushes them through the API, with a state backup before each write. - scratch.py gains --opengym, --opengym-dry-run, --opengym-replace, --opengym-migrate and --opengym-accessories, plus the current block's numbers and accessory layout. - Fix the kg-to-lb factor in scratch.py (2.20462).
83 lines
4.0 KiB
Python
83 lines
4.0 KiB
Python
import argparse
|
|
import os
|
|
import sys
|
|
from datetime import date
|
|
|
|
from language import Plan, Lift, LiftGoal
|
|
from language import opengym
|
|
|
|
sample_plan = Plan(squat_plan = [LiftGoal.VOLUME, LiftGoal.VOLUME, LiftGoal.STRENGTH],
|
|
bench_plan = [LiftGoal.VOLUME, LiftGoal.VOLUME, LiftGoal.STRENGTH],
|
|
deadlift_plan = [LiftGoal.VOLUME, LiftGoal.VOLUME, LiftGoal.STRENGTH],
|
|
squat_targets=(3100, 2000),
|
|
bench_targets=(2500, 1650),
|
|
deadlift_targets=(3100, 2000),
|
|
squat_1rm=142, bench_1rm=115, deadlift_1rm=155,
|
|
rpe_targets=[7.0, 7.5, 8.0, 8.5], num_workouts=4
|
|
)
|
|
|
|
# Accessories by day of the week, in every week but the taper/mock meet week:
|
|
# (name in opengym.ACCESSORY_IDS, sets, reps, insert before this exercise id, or None for the end).
|
|
BENCH = opengym.EXERCISE_IDS[Lift.BENCH]
|
|
ACCESSORIES = {
|
|
1: [("external rotation", 1, 10, BENCH), ("triceps pushdown", 2, 10, None), ("reverse fly", 2, 10, None)],
|
|
2: [("incline curl", 2, 10, None)],
|
|
3: [("triceps pushdown", 2, 10, None), ("lateral raise", 2, 10, None)],
|
|
}
|
|
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--opengym", action="store_true", help="push the plan to OpenGym as a rotation")
|
|
parser.add_argument("--opengym-dry-run", action="store_true", help="show what --opengym would change, write nothing")
|
|
parser.add_argument("--opengym-replace", action="store_true", help="replace routines from an earlier push")
|
|
parser.add_argument("--opengym-migrate", nargs=2, metavar=("OLD_ID", "NEW_ID"),
|
|
help="re-file logged history from one exercise id to another (with --opengym or --opengym-dry-run)")
|
|
parser.add_argument("--opengym-accessories", action="store_true",
|
|
help="add ACCESSORIES to routines already pushed, leaving the queue alone")
|
|
parser.add_argument("--start", type=date.fromisoformat, default=date.today(), help="first day of the block")
|
|
parser.add_argument("--label", default="Powerlifting block", help="rotation name in OpenGym")
|
|
args = parser.parse_args()
|
|
|
|
full_plan = sample_plan.generate_full_plan()
|
|
for (i, week) in enumerate(full_plan):
|
|
print()
|
|
print(f"Week {i + 1}:")
|
|
for (j, day) in enumerate(week):
|
|
print(f" Workout Day {j + 1}:")
|
|
total_volume = sum(lift.total_volume for lift in day)
|
|
for lift in day:
|
|
print(f" {lift.lift}: {lift.sets}")
|
|
print(f" Total Volume: {total_volume * 2.20462:.2f} lbs")
|
|
|
|
sample_plan.to_csv("sample_plan.csv")
|
|
|
|
if args.opengym or args.opengym_dry_run or args.opengym_accessories:
|
|
client = opengym.Client(os.environ.get("OPENGYM_URL") or opengym.resolve_base_url())
|
|
client.login(*opengym.rbw_credentials(os.environ.get("OPENGYM_RBW_ENTRY", "gym.rcjohnstone.com")))
|
|
routines = opengym.plan_to_routines(full_plan)
|
|
|
|
def change(state):
|
|
if args.opengym_accessories:
|
|
opengym.add_accessories(state["routines"], ACCESSORIES, state.get("exWeights") or {})
|
|
return
|
|
opengym.add_accessories(routines, ACCESSORIES, state.get("exWeights") or {})
|
|
if args.opengym_migrate:
|
|
n = opengym.migrate_exercise(state, *args.opengym_migrate)
|
|
print(f"migrate: {n} workouts re-filed from {args.opengym_migrate[0]} to {args.opengym_migrate[1]}")
|
|
print(opengym.describe_change(state, routines))
|
|
opengym.apply_plan(state, routines, args.start, args.label, args.opengym_replace)
|
|
|
|
print()
|
|
if args.opengym_dry_run:
|
|
state, rev = client.get_state()
|
|
change(state)
|
|
if args.opengym_accessories:
|
|
for r in state["routines"]:
|
|
print(r["name"], [e["id"] for e in r["ex"]])
|
|
print(f"dry run against rev {rev}: nothing written")
|
|
sys.exit(0)
|
|
rev = client.update_state(change)
|
|
if args.opengym_accessories:
|
|
print(f"added accessories; OpenGym is now at rev {rev}")
|
|
sys.exit(0)
|
|
print(f"pushed {len(routines)} routines starting {args.start}; OpenGym is now at rev {rev}")
|