Workout Program

Lester Vecsey

Overview

A workout program that shows the times that you should exercise with a warmup period, intensity period, and a cooldown period. It is based on your current weight which is input to the program. If you are near your maximum weight, it will give you a reasonable or light workout. As you get to lighter weights the workouts will be a little longer.

Installing python

You can install python from https://www.python.org/downloads/ including on Windows 11

Code

#!/usr/bin/python3

import os
import sys
import time

def calc_seconds(range, percent):
    
    start_seconds, end_seconds = range

    final_seconds = ((1.0 - percent) * start_seconds) + (percent * end_seconds)

    return final_seconds

def strtime_fromseconds(total_seconds):

        section_seconds = int(total_seconds)
        
        min = int(section_seconds / 60)
        sec = section_seconds - (min * 60)

        result_str = str(min) + 'm ' + str(sec) + 's'
        
        return result_str

def percent_fromweight(weight_range, current_weight):

        weight_max, weight_min = weight_range
        
        weight_span = (weight_max - weight_min)

        percent = (weight_max - current_weight) / weight_span

        return percent

def show_arraydata(warmup_secs, middle_secs, cooldown_secs):

        str_warmupsecs = '{:.3f}'.format(warmup_secs)
        str_middlesecs = '{:.3f}'.format(middle_secs)
        str_cooldownsecs = '{:.3f}'.format(cooldown_secs)

        data_array = [ str_warmupsecs, str_middlesecs, str_cooldownsecs ]

        data_str = ''
        
        for seconds in data_array:
                data_str += (seconds + ' ')
                
        print('Workout parameters: [ ' + data_str + ']')
        
def main():

        weight_range = 220.0, 195.0

        warmup_range = 12 * 60, 15 * 60
        middle_range = 15 * 60, 25 * 60
        cooldown_range = 15 * 60, 20 * 60
        
        args = sys.argv[1:]
        
        weight_lbs = float(args[0])

        print('Using weight ' + str(weight_lbs) + 'lbs.')
        
        percent = percent_fromweight(weight_range, current_weight = weight_lbs)

        warmup_secs = calc_seconds(warmup_range, percent)
        middle_secs = calc_seconds(middle_range, percent)
        cooldown_secs = calc_seconds(cooldown_range, percent)

        show_arraydata(warmup_secs, middle_secs, cooldown_secs)
                
        print('Warmup: ' + strtime_fromseconds(warmup_secs))
        print('Intensity: ' + strtime_fromseconds(middle_secs))
        print('Cooldown: ' + strtime_fromseconds(cooldown_secs))

if __name__ == '__main__':
        main()

Adjusting the code

You will want to adjust the weight_range setting in the program which is the maximum weight to be considered, followed by the minimum weight.

You can set them to something like +5 and -5 lbs from your current weight, or +5 lbs and -10 lbs from your current weight.

Running the code

Use chmod 755 workout.py to set the permissions on the Python file.

You may need to edit it to adjust the path to the python3 program.

Run the program as ./workout.py 215.2 replacing the value with your current weight in lbs.