API: Classes¶
Brief introduction to classes¶
There are four classes available:
StaticExercise
: For exercises schemes such as “3 x 12”, “5 x 5 @ 80kg” or “stretch for 5 mins”. In other words, this class is merely a container for an exercise name and a string.DynamicExercise
: For exercises where you wish to render a dynamic set/rep scheme. TheDynamicExercise
class is part of what makes streprogen dynamic.Day
: ADay
class is a container for exercises associated with the same day.Program
: This is where the magic happens. TheProgram
class is a container forDay``s (and therefore also instances of ``StaticExercise
andDynamicExercise
). The algorithms used to render the program is also contained in theProgram
class. The most important method is theProgram.render()
method, which renders the dynamic exercises.
The DynamicExercise class¶
-
class
streprogen.
DynamicExercise
(name, start_weight, end_weight, min_reps=3, max_reps=8, reps=None, avg_intensity=None, round_to=None)¶ Class for dynamic exercises.
-
__init__
(name, start_weight, end_weight, min_reps=3, max_reps=8, reps=None, avg_intensity=None, round_to=None)¶ Initialize a new dynamic exercise. A dynamic exercise is rendered by the program, and the set/rep scheme will vary from week to week.
Parameters: - name – The name of the exercise, e.g. ‘Squats’.
- start_weight – Maximum weight you can lift at the start of the program, e.g. 80.
- end_weight – The goal weight to work towards during the program. This should be set in relation to the duration of the training program, e.g. 90.
- min_reps – The minimum number of repetitions for this exercise, e.g. 3.
- max_reps – The maximum number of repetitions for this exercise, e.g. 8.
- reps – The number of baseline repetitions for this exercise. If this parameter is set, it will override the global ‘reps_per_exercise’ parameter for the training program. The repetitions will still be scaled by the ‘reps_scalers’ parameter in the training program.
- avg_intensity – The average intensity for this exercise. If set, this will override the ‘avg_intensity’ parameter in the training program. The intensity will still be scaled by the ‘intensity_scalers’ parameter.
- round_to – Round the output to the closest multiple of this number, e.g. 2.5.
Returns: A DynamicExercise object.
Return type: Examples
>>> bench = DynamicExercise('Bench press', 100, 120, 3, 8)
-
weekly_growth
(weeks)¶ Calculate the weekly growth in percentage, and rounds to one digit.
Parameters: weeks – Number of weeks to calculate growth over. Returns: A real number such that start * growth_factor** weeks = end. Return type: growth_factor Examples
>>> bench = DynamicExercise('Bench press', 100, 120, 3, 8) >>> bench.weekly_growth(8) 2.3 >>> bench.weekly_growth(4) 4.7
-
The StaticExercise class¶
-
class
streprogen.
StaticExercise
(name, sets_reps='4 x 10')¶ Class for static exercises.
-
__init__
(name, sets_reps='4 x 10')¶ Initialize a new static exercise. A static exercise is simply a placeholder for some text.
Parameters: - name – The name of the exercise, e.g. ‘Curls’.
- sets_reps – A static set/rep scheme, e.g. ‘4 x 10’, or ‘10 minutes’. This paramter can also be a function of one parameter, the current week. The function must return a string for that specific week.
Returns: A StaticExercise object.
Return type: Examples
>>> curls = StaticExercise('Curls', '4 x 10') >>> stretching = StaticExercise('Stretching', '10 minutes')
-
The Day class¶
-
class
streprogen.
Day
(name=None, exercises=None)¶ A day object is a container for exercises associated with the specific day.
-
__init__
(name=None, exercises=None)¶ Initialize a new day object.
Parameters: - name – The name of the day, e.g. ‘Day A’. If no name is given then the day will automatically be given a numeric name such as ‘Day 1’, ‘Day 2’, etc.
- exercises – A list of exercises. Exercises can also be associated with a day using the ‘add_exercises’ method later on.
Returns: A day object.
Return type: Examples
>>> monday = Day(name = 'Monday') >>> curls = StaticExercise('Curls', '3 x 12') >>> monday.add_exercises(curls) >>> curls in monday.static_exercises True
-
add_exercises
(*exercises)¶ Add the exercises to the day. The method will automatically infer whether a static or dynamic exercise is passed to it.
Parameters: *exercises – An unpacked tuple of exercises. Examples
>>> monday = Day(name = 'Monday') >>> curls = StaticExercise('Curls', '3 x 12') >>> pulldowns = StaticExercise('Pulldowns', '4 x 10') >>> monday.add_exercises(curls, pulldowns) >>> curls in monday.static_exercises True >>> pulldowns in monday.static_exercises True
-
The Program class¶
-
class
streprogen.
Program
(name='Untitled', duration=8, reps_per_exercise=25, rep_scalers=None, intensity=75, intensity_scalers=None, units='kg', round_to=2.5, progress_func=None, reps_to_intensity_func=None, min_reps_consistency=None, minimum_percentile=0.2, go_to_min=False, verbose=False)¶ The program class is a container for days and exercises, along with the methods and functions used to create training programs.
-
__init__
(name='Untitled', duration=8, reps_per_exercise=25, rep_scalers=None, intensity=75, intensity_scalers=None, units='kg', round_to=2.5, progress_func=None, reps_to_intensity_func=None, min_reps_consistency=None, minimum_percentile=0.2, go_to_min=False, verbose=False)¶ Initialize a new program.
Parameters: - name – The name of the training program, e.g. ‘Tommy_August_2017’.
- duration – The duration of the training program in weeks, e.g. 8.
- reps_per_exercise – The baseline number of repetitions per dynamic exercise. Typically a value in the range [20, ..., 35].
- rep_scalers – A list of factors of length ‘duration’, e.g. [1, 0.9, 1.1, ...]. For each week, the baseline number of repetitions is multiplied by the corresponding factor, adding variation to the training program. Each factor is typically in the range [0.7, ..., 1.3]. If None, a list of random factors is generated.
- intensity – The baseline intensity for each dynamic exercise. The intensity of an exercise for a given week is how heavy the average repetition is compared to the expected 1RM (max weight one can lift) for that given week. Typically a value around 75.
- intensity_scalers – A list of factors of length ‘duration’, e.g. [1, 0.95, 1.05, ...]. For each week, the baseline intensity is multiplied by the corresponding factor, adding variation to the training program. Each factor is typically in the range [0.95, ..., 1.05]. If None, a list of random factors is generated.
- units – The units used for exporting and printing the program, e.g. ‘kg’.
- round_to – Round the dynamic exercise to the nearest multiple of this parameter. Typically 2.5, 5 or 10.
- progress_func – The function used to model overall 1RM progression in the
training program. If None, the program uses
streprogen.progression_sinusoidal()
. Custom functions may be used, but they must implement arguments like thestreprogen.progression_sinusoidal()
andstreprogen.progression_linear()
functions. - reps_to_intensity_func – The function used to model the relationship between repetitions
and intensity. If None, the program uses
streprogen.reps_to_intensity()
. Custom functions may be used, and the functionsstreprogen.reps_to_intensity_tight()
andstreprogen.reps_to_intensity_relaxed()
are available. - min_reps_consistency –
This is an advanced feature. By default, the program will examine the dynamic exercises and try to set a minimum repetition consistency mode. If all dynamic exercises in the program use the same repetition range, it will be set to ‘weekly’. If all dynamic exercises in each day use the same repetition range, it will be set to ‘daily’. If neither, it will be set to ‘exercise’.
The minimum reps consistency mode tells the program how often it should draw a new random value for the minimum repetition to work up to. If ‘min_reps_consistency’ is ‘weekly’ and the ‘go_to_min’ parameter is set to True, you can expect that every exercise will work up to the same minimum number of repetitions.
The ‘min_reps_consistency’ argument will override the program default. If, for example, every exercise is set to the repetition range 3-8 but you wish to work up to different minimum values, set ‘min_reps_consistency’ to ‘daily’ or ‘exercise’.
- minimum_percentile –
This is an advanced feature. To protect the athlete against often working up to heavy weights, the repetition range is “clipped” randomly. A repetition range 1-8 might be clipped to, say, 3-8, 2-8 or 1-8. If clipped to 3-8, the repetitions are drawn from [3, ..., 8] instead of [1, ..., 8].
The ‘minimum_percentile’ determines the percentile of the repetition range to clip away. If 0, no clipping occurs. If 0.5, half the repetition range could potentially be clipped away. How often the range is clipped and a new minimum repetition value is computed is determined by the minimum repetition consistency mode, which may be controlled by the ‘minimum_percentile’ argument.
- go_to_min – This is an advanced feature. Whether or not to force the program to work up to the minimum repetition possible for a given dynamic exercise. Consider a program where ‘minimum_percentile’ is 0.2, and a dynamic exercise has a repetition range 1-8. The program will drawn repetitions in ranges 1-8, 2-8 or 3-8. If ‘go_to_min’ is True, the program will be forced to work up to 1, 2 or 3 repetitions respectively. If ‘go_to_min’ is False, the same range will be used, but the program need not go to the minimum number of repeitions.
- verbose – If True, information will be outputted as the program is created.
Returns: A Program instance.
Return type: Examples
>>> program = Program('My training program') >>> program._rendered False
-
add_days
(*days)¶ Add one or several days to the program.
Parameters: *days – Unpacked tuple containing streprogen.Day
instances.Examples
>>> program = Program('My training program') >>> day1, day2 = Day(), Day() >>> program.add_days(day1, day2)
-
render
(validate=True)¶ Render the training program to perform the calculations. The program can be rendered several times to produce new information given the same input parameters.
Parameters: validate – Boolean that indicates whether or not to run a validation heurestic on the program before rendering. The validation will warn the user if inputs seem unreasonable.
-
static
repstring_penalty
(reps, intensities, desired_reps, desired_intensity, minimum_rep)¶ Penalty function which calculates how “bad” a set of reps and intensities is, compared to the desired repetitions, the desired intensity level and the minimum repetitions. Advanced users may substitute this function for their own version.
Parameters: - reps – A list of repetitions (sorted), e.g. [8, 6, 5, 2].
- intensities – A list of intensities corresponding to the repetitions, e.g. [64.7, 72.3, 76.25, 88.7].
- desired_reps – Desired number of repetitions in total, e.g. 25.
- desired_intensity – The desired average intensity, e.g. 75.
- minimum_rep – The minimum repetition which is allowed, e.g. 2.
Returns: A penalty, a positive real number.
Return type: float
Examples
>>> desired_reps = 25 >>> desired_intensity = 75 >>> minimum_rep = 1 >>> high = Program().repstring_penalty([8, 8, 8], [60, 60, 60], ... desired_reps, desired_intensity, ... minimum_rep) >>> low = Program().repstring_penalty([8, 6, 5, 4, 2], [64, 72, 75, 80, 88], ... desired_reps, desired_intensity, ... minimum_rep) >>> high > low True
-
to_html
(table_width=5)¶ Write the program information to HTML code, which can be saved, printed and brought to the gym.
Parameters: table_width – The table with of the HTML code. Returns: HTML code. Return type: string
-
to_tex
(text_size='large', table_width=5)¶ Write the program information to a .tex file, which can be rendered to .pdf running pdflatex. The program can then be printed and brought to the gym.
Parameters: - text_size – The tex text size, e.g. ‘small’, ‘normalsize’, ‘large’, ‘Large’ or ‘LARGE’.
- table_width – The table with of the .tex code.
Returns: Program as tex.
Return type: string
-
to_txt
(verbose=False)¶ Write the program information to text, which can be printed in a terminal.
Parameters: verbose – If True, more information is shown. Returns: Program as text. Return type: string
-