Getting started¶
This tutorial was written using a Jupyter Notebook.
Minimal working example¶
This example shows to to use the Program
,
StaticExercise
and Day
classes to create a simple static strength training program. The example may not look impressive, but it shows how to create a working strength training program. The Program.render()
method is very important, because it populates all the days and weeks in the program with calculations.
In [1]:
from streprogen import StaticExercise, Day, Program
# Create a 3 week training program
program = Program('Minimal program', duration = 3)
# Create a static exercise to a day
squats = StaticExercise('Squats', '5 x 5 @ 80kg')
day = Day(exercises = [squats])
# Add the day to the program and render it
program.add_days(day)
program.render()
print(program)
----------------------------------------------------------------
Program: Minimal program
Program parameters
duration: 3
reps_per_exercise: 25
avg_intensity: 75
reps_scalers: 1, 0.8, 0.8
intensity_scalers: 1, 1, 0.9
units: kg
----------------------------------------------------------------
Exercise information 6
Day 1
Squats 5 x 5 @ 80kg
----------------------------------------------------------------
Program
Week 1
Day 1
Squats 5 x 5 @ 80kg
Week 2
Day 1
Squats 5 x 5 @ 80kg
Week 3
Day 1
Squats 5 x 5 @ 80kg
----------------------------------------------------------------
Using dynamic exercises¶
This example introduces the DynamicExercise
class, and also shows how to save a program as a .html
file. Three output methods are supported:
- To
txt
with theto_txt()
method. - To
html
with theto_html()
method. - To
tex
with theto_tex()
method.
In [2]:
from streprogen import StaticExercise, DynamicExercise, Day, Program
# Create a 8 week training program
program = Program('Program with dynamic exercise', duration = 8)
# Create a dynamic exercise, with start weight 100, end weight 110
# and repetitions between 4 and 8 (inclusive)
squats = DynamicExercise('Squats', 100, 110, min_reps = 4, max_reps = 8)
biceps = StaticExercise('Biceps', '3 x 12')
day = Day(exercises = [squats, biceps])
# Add the day to the program and render it
program.add_days(day)
program.render()
# Save the program as a HTML file
with open('program_with_dynamic_ex.html', 'w', encoding = 'utf-8') as file:
# The table width can be controlled by passing the 'table_width' argument
file.write(program.to_html(table_width = 8))
The output file generated by the code above is:
Several days¶
This example introduces several new features:
- Controlling repetitions per exercise using
reps_per_exercise
. - Controlling the average intensity (% of maximum weight) using
avg_intensity
. - Controlling the rounding globally with
round_to
.
In [3]:
from streprogen import StaticExercise, DynamicExercise, Day, Program
# Create a 6 week training program with 20 reps per exercise
program = Program('Program with dynamic exercise', duration = 8, reps_per_exercise = 20, intensity = 70, round_to = 5)
# Create the first day
squats = DynamicExercise('Squats', 100, 120, min_reps = 4, max_reps = 8)
bench = DynamicExercise('Bench press', 80, 95, min_reps = 4, max_reps = 8)
dayA = Day('Day A', exercises = [squats, bench])
# Create the second day
squats = DynamicExercise('Squats', 100, 110, min_reps = 4, max_reps = 8)
deadlifts = DynamicExercise('Deadlifts', 120, 135, min_reps = 4, max_reps = 8)
dayB = Day('Day B', exercises = [squats, bench])
# Add the day to the program and render it
program.add_days(dayA, dayB)
program.render()
# Save a .html file
with open('program__with_several_days.html', 'w', encoding = 'utf-8') as file:
# The table width can be controlled by passing the 'table_width' argument
file.write(program.to_html(table_width = 8))
The output file generated by the code above is:
A realistic program¶
Here is a realistic program that was used in real life. It’s a three-week, full body program. A function (named f
in the code below) was used to set the end_weight parameter. The StaticExercise
class can also take a function (of one parameter, the current week) as input.
In [4]:
from streprogen import StaticExercise, DynamicExercise, Day, Program
import subprocess # Used to run pdflatex
# Create a function to map from start weights to end weights
def f(initial):
# Function to return final weight,
# increasing the weights by 2% per day
return int(initial*1.02**duration)
# Create a function for the static exercise
def dips_scheme(week):
if week <= 4:
return '4 x 10 @ bodyweight'
else:
return '4 x 12 @ bodyweight + 10kg'
# Create the program
duration = 8
program = Program('A realistic program', units='', round_to=2.5)
# The first day
day1 = Day('Monday')
squats = DynamicExercise('Squats', 95, f(95))
chins = DynamicExercise('Chins (light)', 100, f(100))
press = DynamicExercise('Military press',50, f(50))
day1.add_exercises(squats, chins, press)
# The second day
day2 = Day('Wednesday')
deadlifts = DynamicExercise('Deadlifts', 120, f(120))
bench_press = DynamicExercise('Bench', 70, f(70))
chin_ups = DynamicExercise('Chin ups', 100, f(100))
dips = StaticExercise('Dips', dips_scheme) # Notice that a function is used here
day2.add_exercises(deadlifts, bench_press, chin_ups, dips)
# The third day
day3 = Day('Friday')
squats = DynamicExercise('Squats', 85, f(85))
bench = DynamicExercise('Bench (light)', 85, f(85))
rows = DynamicExercise('Rows', 65, f(85))
day3.add_exercises(squats, chins, press)
# Add the days and render the program
program.add_days(day1, day2, day3)
program.render()
# Save a .html file
with open('realistic_program.html', 'w', encoding = 'utf-8') as file:
file.write(program.to_html(table_width = 6))
# Save a .tex file
with open('realistic_program.tex', 'w', encoding = 'utf-8') as file:
file.write(program.to_tex(table_width = 8))
# Use pdflatex to create a .pdf from the .tex file
ret = subprocess.call(['pdflatex', 'realistic_program.tex'], shell=False)
The output file generated by the code above is: