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. The DynamicExercise class is part of what makes streprogen dynamic.
  • Day: A Day class is a container for exercises associated with the same day.
  • Program: This is where the magic happens. The Program class is a container for Day``s (and therefore also instances of ``StaticExercise and DynamicExercise). The algorithms used to render the program is also contained in the Program class. The most important method is the Program.render() method, which renders the dynamic exercises.

The DynamicExercise class

class streprogen.DynamicExercise(name, start_weight=None, final_weight=None, min_reps=None, max_reps=None, percent_inc_per_week=None, reps=None, intensity=None, round_to=None, shift=0)

Class for dynamic exercises.

__init__(name, start_weight=None, final_weight=None, min_reps=None, max_reps=None, percent_inc_per_week=None, reps=None, intensity=None, round_to=None, shift=0)

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.
  • final_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. If set, this overrides the optional percent_inc_per_week parameter.
  • 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.
  • percent_inc_per_week – If final_weight is not set, this value will be used. The increase is additive, not multipliactive. For instance, if the increase is set to percent_inc_per_week=2, then after 2 weeks the increase is 4, not (1.02 * 1.02 - 1) * 100 = 4.04. The final_weight parameter must be set to None for this parameter to have effect.
  • 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 rep_scaler_func parameter in the training program.
  • intensity – The average intensity for this exercise. If set, this will override the intensity parameter in the training program. The intensity will still be scaled by the intensity_scaler_func parameter.
  • round_to – Round the output to the closest multiple of this number, e.g. 2.5. Alternatively, a callable can be passed. The callable must take a number as input and return a rounded number as output.
  • shift – Shift evaluation of repetitions, intensity and progress shift weeks ahead in time. An exercise shifted by 1 will have its reps, intensity and strength evalated at week i + 1 instead of in week i.

Examples

>>> bench = DynamicExercise('Bench press', 100, 120, 3, 8)
>>> bench2 = DynamicExercise('Bench press', 100, 120, 3, 8)
>>> bench == bench2
True
classmethod deserialize(data)

Create a new object from a dictionary.

max_reps

Return max reps. If a Program attribute it set and the exercise attribute is None, use the program attribute.

min_reps

Return min reps. If a Program attribute it set and the exercise attribute is None, use the program attribute.

serialize()

Export the object to a dictionary.

Examples

>>> bench = DynamicExercise('Bench press', start_weight=100)
>>> bench.serialize() == {'start_weight': 100, 'name': 'Bench press'}
True

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:

StaticExercise

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.

Examples

>>> monday = Day(name='Monday')
>>> curls = StaticExercise('Curls', '3 x 12')
>>> monday.add_exercises(curls)
>>> curls in monday.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.exercises
True
>>> pulldowns in monday.exercises
True
classmethod deserialize(data)

Create a new object from a dictionary.

serialize()

Export the object to a dictionary.

The Program class

class streprogen.Program(name: str = 'Untitled', duration: int = 8, reps_per_exercise: int = 25, min_reps: int = 3, max_reps: int = 8, rep_scaler_func: Callable[[int], float] = None, intensity: float = 83, intensity_scaler_func: Callable[[int], float] = None, units: str = 'kg', round_to: Union[float, Callable] = 2.5, percent_inc_per_week: float = 1.5, progression_func: Callable = None, reps_to_intensity_func: Callable[[int], float] = None, verbose: bool = False)

The program class is a container for days and exercises, along with the methods and functions used to create training programs.

__init__(name: str = 'Untitled', duration: int = 8, reps_per_exercise: int = 25, min_reps: int = 3, max_reps: int = 8, rep_scaler_func: Callable[[int], float] = None, intensity: float = 83, intensity_scaler_func: Callable[[int], float] = None, units: str = 'kg', round_to: Union[float, Callable] = 2.5, percent_inc_per_week: float = 1.5, progression_func: Callable = None, reps_to_intensity_func: Callable[[int], float] = None, verbose: bool = False)

Initialize a new program.

Parameters:
  • name – The name of the training program, e.g. ‘TommyAugust2017’.
  • 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 [15, 30].
  • min_reps – The minimum number of repetitions for the exercises, e.g. 3. This value can be set globally for the program, or for a specific dynamic exercise. If set at the dynamic exercise level, it will override the global program value.
  • max_reps – The maximum number of repetitions for the exercises, e.g. 8. This value can be set globally for the program, or for a specific dynamic exercise. If set at the dynamic exercise level, it will override the global program value.
  • rep_scaler_func – A function mapping from a week in the range [1, duration] to a scaling value (factor). The scaling value will be multiplied with the reps_per_exercise parameter for that week. Should typically return factors between 0.7 and 1.3. Alternatively, a list of length duration may be passed.
  • 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 80.
  • intensity_scaler_func – A function mapping from a week in the range [1, duration] to a scaling value (factor). The scaling value will be multiplied with the intensity parameter for that week. Should typically return factors between 0.9 and 1.1. Alternatively, a list of length duration may be passed.
  • 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. A callable can alternatively be passed. This value can be set globally for the program, or for a specific dynamic exercise. If set at the dynamic exercise level, it will override the global program value.
  • percent_inc_per_week – If final_weight is not set, this value will be used. Percentage increase per week can be set globally for the program, or for each dynamic exercise. If set at the dynamic exercise level, it will override the global program value. The increase is additive, not multipliactive. For instance, if the increase is set to percent_inc_per_week=2, then after 2 weeks the increase is 4, not (1.02 * 1.02 - 1) * 100 = 4.04. The final_weight parameter must be set to None for this parameter to have effect.
  • progression_func

    The function used to model overall 1RM progression in the training program. The function must have a signature like:

    func(week, start_weight, final_weight, start_week, end_week)
  • reps_to_intensity_func – The function used to model the relationship between repetitions and intensity. Maps from a repetition to an intensity in the range 0-100.
  • verbose – If True, information will be outputted as the program is created.
Returns:

A Program instance.

Return type:

Program

Examples

>>> program = Program('My training program')
>>> program._rendered
False
Day(name: str = None)
A day object is a container for exercises associated with the specific day.

See streprogen.Day for accurate signature.

DynamicExercise(name, start_weight=None, final_weight=None, min_reps=None, max_reps=None, percent_inc_per_week=None, reps=None, intensity=None, round_to=None, shift=0)

Class for dynamic exercises. See streprogen.DynamicExercise for accurate signature.

StaticExercise(name, sets_reps='4 x 10')
Class for static exercises.

See streprogen.StaticExercise for accurate signature.

add_days(*days)

Add one or several days to the program.

Parameters:*days – Iterable containing streprogen.Day instances.

Examples

>>> program = Program('My training program')
>>> day1, day2 = Day(), Day()
>>> program.add_days(day1, day2)
>>> program.add_days(day1)
classmethod deserialize(data: dict)

Create a new object from a dictionary.

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.
serialize() → dict

Export the object to a dictionary.

set_optimization_params(reps_slack=None, max_diff=None, max_unique=None)

Set default parameters.

Passing None for a paramter will get use the defaults in RepSchemeGenerator.

Parameters:
  • reps_slack (int, optional) – Maximum deviation from the repetition goal.
  • max_diff (int, optional) – Maximum difference between two consecutive sets.
  • max_unique (int, optional) – Maximum unique sets in the solution.
to_dict()

Write the rendered program information to a dictionary.

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, clear_pages=False)

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 width of the .tex code.
  • clear_pages – If True, the page will be cleared after each week is printed.
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