pr-pro 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pr-pro might be problematic. Click here for more details.
- pr_pro/__init__.py +0 -0
- pr_pro/abbreviations.py +2 -0
- pr_pro/configs.py +8 -0
- pr_pro/example.py +221 -0
- pr_pro/exercise.py +158 -0
- pr_pro/exercises/common.py +21 -0
- pr_pro/functions.py +122 -0
- pr_pro/program.py +70 -0
- pr_pro/sets.py +148 -0
- pr_pro/streamlit_vis/__init__.py +6 -0
- pr_pro/streamlit_vis/session.py +44 -0
- pr_pro/streamlit_vis/sets.py +165 -0
- pr_pro/streamlit_vis/state.py +80 -0
- pr_pro/streamlit_vis/streamlit_app.py +71 -0
- pr_pro/streamlit_vis/workout_component.py +111 -0
- pr_pro/workout_component.py +248 -0
- pr_pro/workout_session.py +101 -0
- pr_pro-1.0.0.dist-info/METADATA +26 -0
- pr_pro-1.0.0.dist-info/RECORD +21 -0
- pr_pro-1.0.0.dist-info/WHEEL +4 -0
- pr_pro-1.0.0.dist-info/entry_points.txt +2 -0
pr_pro/__init__.py
ADDED
|
File without changes
|
pr_pro/abbreviations.py
ADDED
pr_pro/configs.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
from pydantic import BaseModel, ConfigDict
|
|
2
|
+
from pr_pro.functions import Brzycki1RMCalculator, OneRMCalculator
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class ComputeConfig(BaseModel):
|
|
6
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
7
|
+
|
|
8
|
+
one_rm_calculator: OneRMCalculator = Brzycki1RMCalculator()
|
pr_pro/example.py
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import datetime
|
|
2
|
+
|
|
3
|
+
from pr_pro.exercise import DurationExercise, RepsAndWeightsExercise, RepsExercise, RepsRPEExercise
|
|
4
|
+
from pr_pro.exercises.common import backsquat, bench_press, deadlift, pullup, pushup, split_squat
|
|
5
|
+
from pr_pro.program import Program
|
|
6
|
+
from pr_pro.workout_component import ExerciseGroup, SingleExercise
|
|
7
|
+
from pr_pro.workout_session import (
|
|
8
|
+
WorkoutSession,
|
|
9
|
+
exercise_group_from_prev_session,
|
|
10
|
+
single_exercise_from_prev_session,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def get_simple_example_program() -> Program:
|
|
15
|
+
pendlay_row = RepsAndWeightsExercise(name='Pendlay row')
|
|
16
|
+
|
|
17
|
+
program = Program(name='Test program').add_best_exercise_value(backsquat, 100)
|
|
18
|
+
program.add_best_exercise_value(pendlay_row, program.best_exercise_values[backsquat] * 0.6)
|
|
19
|
+
|
|
20
|
+
w1d1 = (
|
|
21
|
+
WorkoutSession(id='W1D1', notes='Power day.')
|
|
22
|
+
.add_component(
|
|
23
|
+
SingleExercise(exercise=backsquat).add_repeating_set(
|
|
24
|
+
4, backsquat.create_set(5, percentage=0.55)
|
|
25
|
+
)
|
|
26
|
+
)
|
|
27
|
+
.add_component(
|
|
28
|
+
ExerciseGroup(exercises=[pendlay_row, pushup]).add_repeating_group_sets(
|
|
29
|
+
4,
|
|
30
|
+
{
|
|
31
|
+
pendlay_row: pendlay_row.create_set(6, percentage=0.6),
|
|
32
|
+
pushup: pushup.create_set(10),
|
|
33
|
+
},
|
|
34
|
+
)
|
|
35
|
+
)
|
|
36
|
+
.add_component(
|
|
37
|
+
SingleExercise(exercise=pendlay_row).add_repeating_set(
|
|
38
|
+
4, pendlay_row.create_set(6, percentage=0.6)
|
|
39
|
+
)
|
|
40
|
+
)
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
program.add_workout_session(w1d1)
|
|
44
|
+
return program
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def get_example_program() -> Program:
|
|
48
|
+
box_jump = RepsExercise(name='Box jump')
|
|
49
|
+
pendlay_row = RepsAndWeightsExercise(name='Pendlay row')
|
|
50
|
+
dumbbell_shoulder_press = RepsRPEExercise(name='Dumbbell shoulder press')
|
|
51
|
+
hip_thrust = RepsAndWeightsExercise(name='Hip thrust')
|
|
52
|
+
side_plank_leg_raise = RepsExercise(name='Side plank leg raise')
|
|
53
|
+
cable_pulldown = RepsRPEExercise(name='Straight arm cable pulldown')
|
|
54
|
+
pallov_press = RepsRPEExercise(name='Pallov press')
|
|
55
|
+
squat_hold = DurationExercise(name='Squat hold')
|
|
56
|
+
hanging_knee_raise = RepsAndWeightsExercise(name='Hanging knee raise')
|
|
57
|
+
reverse_hyperextension = RepsExercise(name='Reverse hyperextension')
|
|
58
|
+
|
|
59
|
+
program = (
|
|
60
|
+
Program(name='Test program')
|
|
61
|
+
.add_best_exercise_value(backsquat, 55)
|
|
62
|
+
.add_best_exercise_value(deadlift, 90)
|
|
63
|
+
.add_best_exercise_value(bench_press, 50)
|
|
64
|
+
)
|
|
65
|
+
program.add_best_exercise_value(pendlay_row, program.best_exercise_values[deadlift] * 0.6)
|
|
66
|
+
|
|
67
|
+
w1d1 = (
|
|
68
|
+
WorkoutSession(id='W1D1', notes='Power day.')
|
|
69
|
+
.add_component(
|
|
70
|
+
SingleExercise(exercise=box_jump, notes='Good warmup please!').add_repeating_set(
|
|
71
|
+
5, box_jump.create_set(4)
|
|
72
|
+
)
|
|
73
|
+
)
|
|
74
|
+
.add_component(
|
|
75
|
+
SingleExercise(exercise=backsquat).add_repeating_set(
|
|
76
|
+
4, backsquat.create_set(5, percentage=0.55)
|
|
77
|
+
)
|
|
78
|
+
)
|
|
79
|
+
.add_component(
|
|
80
|
+
ExerciseGroup(
|
|
81
|
+
exercises=[pendlay_row, dumbbell_shoulder_press],
|
|
82
|
+
notes='Put down completely for pendlay row.',
|
|
83
|
+
).add_repeating_group_sets(
|
|
84
|
+
4,
|
|
85
|
+
{
|
|
86
|
+
pendlay_row: pendlay_row.create_set(6, percentage=0.6),
|
|
87
|
+
dumbbell_shoulder_press: dumbbell_shoulder_press.create_set(10, rpe=6),
|
|
88
|
+
},
|
|
89
|
+
)
|
|
90
|
+
)
|
|
91
|
+
.add_component(
|
|
92
|
+
ExerciseGroup(exercises=[hip_thrust, side_plank_leg_raise]).add_repeating_group_sets(
|
|
93
|
+
4,
|
|
94
|
+
{
|
|
95
|
+
hip_thrust: hip_thrust.create_set(8, weight=60),
|
|
96
|
+
side_plank_leg_raise: side_plank_leg_raise.create_set(10),
|
|
97
|
+
},
|
|
98
|
+
)
|
|
99
|
+
)
|
|
100
|
+
)
|
|
101
|
+
program.add_workout_session(w1d1)
|
|
102
|
+
|
|
103
|
+
w1d2 = (
|
|
104
|
+
WorkoutSession(id='W1D2')
|
|
105
|
+
.add_component(
|
|
106
|
+
SingleExercise(exercise=deadlift, notes='Squeeze glutes!').add_repeating_set(
|
|
107
|
+
3, deadlift.create_set(12, percentage=0.5)
|
|
108
|
+
)
|
|
109
|
+
)
|
|
110
|
+
.add_component(
|
|
111
|
+
SingleExercise(exercise=split_squat).add_repeating_set(
|
|
112
|
+
4, backsquat.create_set(6, weight=0)
|
|
113
|
+
)
|
|
114
|
+
)
|
|
115
|
+
.add_component(
|
|
116
|
+
ExerciseGroup(
|
|
117
|
+
exercises=[pullup, pushup], notes='Pullup with reverse grip'
|
|
118
|
+
).add_repeating_group_sets(
|
|
119
|
+
5,
|
|
120
|
+
{pullup: pullup.create_set(1), pushup: pushup.create_set(6)},
|
|
121
|
+
)
|
|
122
|
+
)
|
|
123
|
+
.add_component(
|
|
124
|
+
ExerciseGroup(exercises=[cable_pulldown, pallov_press]).add_repeating_group_sets(
|
|
125
|
+
4,
|
|
126
|
+
{
|
|
127
|
+
cable_pulldown: cable_pulldown.create_set(10, rpe=6),
|
|
128
|
+
pallov_press: pallov_press.create_set(10, rpe=6),
|
|
129
|
+
},
|
|
130
|
+
)
|
|
131
|
+
)
|
|
132
|
+
)
|
|
133
|
+
program.add_workout_session(w1d2)
|
|
134
|
+
|
|
135
|
+
w1d3 = (
|
|
136
|
+
WorkoutSession(id='W1D3')
|
|
137
|
+
.add_component(
|
|
138
|
+
SingleExercise(exercise=squat_hold).add_repeating_set(
|
|
139
|
+
3, squat_hold.create_set(duration=datetime.timedelta(minutes=1))
|
|
140
|
+
)
|
|
141
|
+
)
|
|
142
|
+
.add_component(
|
|
143
|
+
SingleExercise(exercise=backsquat).add_repeating_set(
|
|
144
|
+
4, backsquat.create_set(8, percentage=0.6)
|
|
145
|
+
)
|
|
146
|
+
)
|
|
147
|
+
.add_component(
|
|
148
|
+
SingleExercise(exercise=deadlift, notes='Every minute on the minute').add_repeating_set(
|
|
149
|
+
10, deadlift.create_set(2, percentage=0.5)
|
|
150
|
+
)
|
|
151
|
+
)
|
|
152
|
+
.add_component(
|
|
153
|
+
SingleExercise(exercise=bench_press).add_repeating_set(
|
|
154
|
+
4, bench_press.create_set(10, percentage=0.6)
|
|
155
|
+
)
|
|
156
|
+
)
|
|
157
|
+
.add_component(
|
|
158
|
+
ExerciseGroup(
|
|
159
|
+
exercises=[hanging_knee_raise, reverse_hyperextension]
|
|
160
|
+
).add_repeating_group_sets(
|
|
161
|
+
4,
|
|
162
|
+
{
|
|
163
|
+
hanging_knee_raise: hanging_knee_raise.create_set(6, weight=10),
|
|
164
|
+
reverse_hyperextension: reverse_hyperextension.create_set(6),
|
|
165
|
+
},
|
|
166
|
+
)
|
|
167
|
+
)
|
|
168
|
+
)
|
|
169
|
+
program.add_workout_session(w1d3)
|
|
170
|
+
|
|
171
|
+
w2d1 = (
|
|
172
|
+
WorkoutSession(id='W2D1')
|
|
173
|
+
.add_component(single_exercise_from_prev_session(w1d1, box_jump, reps=+1))
|
|
174
|
+
.add_component(single_exercise_from_prev_session(w1d1, backsquat, percentage=+0.1))
|
|
175
|
+
.add_component(
|
|
176
|
+
exercise_group_from_prev_session(
|
|
177
|
+
w1d1,
|
|
178
|
+
[pendlay_row, dumbbell_shoulder_press],
|
|
179
|
+
percentage=(+0.05, None),
|
|
180
|
+
rpe=(None, +1),
|
|
181
|
+
)
|
|
182
|
+
)
|
|
183
|
+
.add_component(exercise_group_from_prev_session(w1d1, [hip_thrust, side_plank_leg_raise]))
|
|
184
|
+
)
|
|
185
|
+
program.add_workout_session(w2d1)
|
|
186
|
+
|
|
187
|
+
w2d2 = (
|
|
188
|
+
WorkoutSession(id='W2D2')
|
|
189
|
+
.add_component(single_exercise_from_prev_session(w1d2, deadlift, percentage=+0.05, reps=-2))
|
|
190
|
+
.add_component(single_exercise_from_prev_session(w1d2, split_squat, weight=+10))
|
|
191
|
+
.add_component(exercise_group_from_prev_session(w1d2, [pullup, pushup], reps=(+1, +1)))
|
|
192
|
+
.add_component(
|
|
193
|
+
exercise_group_from_prev_session(w1d2, [cable_pulldown, pallov_press], rpe=(+1, +1))
|
|
194
|
+
)
|
|
195
|
+
)
|
|
196
|
+
program.add_workout_session(w2d2)
|
|
197
|
+
|
|
198
|
+
w2d3 = (
|
|
199
|
+
WorkoutSession(id='W2D3')
|
|
200
|
+
.add_component(
|
|
201
|
+
single_exercise_from_prev_session(
|
|
202
|
+
w1d3, squat_hold, duration=datetime.timedelta(seconds=30)
|
|
203
|
+
)
|
|
204
|
+
)
|
|
205
|
+
.add_component(single_exercise_from_prev_session(w1d3, backsquat, percentage=+0.1))
|
|
206
|
+
.add_component(single_exercise_from_prev_session(w1d3, deadlift, percentage=+0.05))
|
|
207
|
+
.add_component(single_exercise_from_prev_session(w1d3, bench_press, percentage=+0.05))
|
|
208
|
+
.add_component(
|
|
209
|
+
exercise_group_from_prev_session(
|
|
210
|
+
w1d3, [hanging_knee_raise, reverse_hyperextension], weight=(+5, None)
|
|
211
|
+
)
|
|
212
|
+
)
|
|
213
|
+
)
|
|
214
|
+
program.add_workout_session(w2d3)
|
|
215
|
+
|
|
216
|
+
return program
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
if __name__ == '__main__':
|
|
220
|
+
program = get_example_program()
|
|
221
|
+
print(program)
|
pr_pro/exercise.py
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
from abc import abstractmethod, ABC
|
|
2
|
+
import datetime
|
|
3
|
+
from typing import TYPE_CHECKING, Any, ClassVar, Literal
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, ConfigDict, ValidationInfo, model_validator
|
|
6
|
+
|
|
7
|
+
from pr_pro.sets import (
|
|
8
|
+
DurationSet,
|
|
9
|
+
PowerExerciseSet,
|
|
10
|
+
RepsAndWeightsSet,
|
|
11
|
+
RepsDistanceSet,
|
|
12
|
+
RepsRPESet,
|
|
13
|
+
RepsSet,
|
|
14
|
+
WorkingSet,
|
|
15
|
+
WorkingSet_t,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Exercise(BaseModel, ABC):
|
|
20
|
+
set_class: ClassVar[type[WorkingSet_t]]
|
|
21
|
+
name: str
|
|
22
|
+
# Necessary for discerning exercises in model validation
|
|
23
|
+
model_type: Literal['Exercise'] = 'Exercise'
|
|
24
|
+
model_config = ConfigDict(frozen=True)
|
|
25
|
+
|
|
26
|
+
@staticmethod
|
|
27
|
+
@abstractmethod
|
|
28
|
+
def create_set(reps: int) -> WorkingSet: ...
|
|
29
|
+
|
|
30
|
+
def __str__(self) -> str:
|
|
31
|
+
return f'{self.name} ({self.__class__.__name__})'
|
|
32
|
+
|
|
33
|
+
@model_validator(mode='before')
|
|
34
|
+
@classmethod
|
|
35
|
+
def _validate_from_key_string_or_dict(cls, data: Any, info: ValidationInfo) -> Any:
|
|
36
|
+
if isinstance(data, str):
|
|
37
|
+
exercise_class = get_exercise_type_by_key_string(data)
|
|
38
|
+
name = data.split('(')[0].strip()
|
|
39
|
+
return exercise_class(name=name).model_dump()
|
|
40
|
+
|
|
41
|
+
return data
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class RepsExercise(Exercise):
|
|
45
|
+
set_class = RepsSet
|
|
46
|
+
model_type: Literal['RepsExercise'] = 'RepsExercise'
|
|
47
|
+
|
|
48
|
+
@staticmethod
|
|
49
|
+
def create_set(reps: int) -> RepsSet:
|
|
50
|
+
return RepsSet(reps=reps)
|
|
51
|
+
|
|
52
|
+
if TYPE_CHECKING:
|
|
53
|
+
|
|
54
|
+
def __hash__(self) -> int: ...
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class RepsRPEExercise(RepsExercise):
|
|
58
|
+
set_class = RepsRPESet
|
|
59
|
+
model_type: Literal['RepsRPEExercise'] = 'RepsRPEExercise'
|
|
60
|
+
|
|
61
|
+
@staticmethod
|
|
62
|
+
def create_set(reps: int, rpe: int) -> RepsSet:
|
|
63
|
+
return RepsRPESet(reps=reps, rpe=rpe)
|
|
64
|
+
|
|
65
|
+
if TYPE_CHECKING:
|
|
66
|
+
|
|
67
|
+
def __hash__(self) -> int: ...
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class RepsAndWeightsExercise(RepsExercise):
|
|
71
|
+
set_class = RepsAndWeightsSet
|
|
72
|
+
model_type: Literal['RepsAndWeightsExercise'] = 'RepsAndWeightsExercise'
|
|
73
|
+
|
|
74
|
+
@staticmethod
|
|
75
|
+
def create_set(
|
|
76
|
+
reps: int,
|
|
77
|
+
weight: float | None = None,
|
|
78
|
+
percentage: float | None = None,
|
|
79
|
+
relative_percentage: float | None = None,
|
|
80
|
+
) -> RepsAndWeightsSet:
|
|
81
|
+
return RepsAndWeightsSet(
|
|
82
|
+
reps=reps,
|
|
83
|
+
weight=weight,
|
|
84
|
+
relative_percentage=relative_percentage,
|
|
85
|
+
percentage=percentage,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
if TYPE_CHECKING:
|
|
89
|
+
|
|
90
|
+
def __hash__(self) -> int: ...
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class PowerExercise(RepsExercise):
|
|
94
|
+
set_class = PowerExerciseSet
|
|
95
|
+
model_type: Literal['PowerExercise'] = 'PowerExercise'
|
|
96
|
+
|
|
97
|
+
@staticmethod
|
|
98
|
+
def create_set(
|
|
99
|
+
reps: int,
|
|
100
|
+
weight: float | None = None,
|
|
101
|
+
percentage: float | None = None,
|
|
102
|
+
) -> PowerExerciseSet:
|
|
103
|
+
return PowerExerciseSet(
|
|
104
|
+
reps=reps,
|
|
105
|
+
weight=weight,
|
|
106
|
+
percentage=percentage,
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
if TYPE_CHECKING:
|
|
110
|
+
|
|
111
|
+
def __hash__(self) -> int: ...
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class RepsDistanceExercise(RepsExercise):
|
|
115
|
+
set_class = RepsDistanceSet
|
|
116
|
+
model_type: Literal['RepsDistanceExercise'] = 'RepsDistanceExercise'
|
|
117
|
+
|
|
118
|
+
@staticmethod
|
|
119
|
+
def create_set(reps: int, distance: float) -> RepsDistanceSet:
|
|
120
|
+
return RepsDistanceSet(reps=reps, distance=distance)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
class DurationExercise(Exercise):
|
|
124
|
+
set_class = DurationSet
|
|
125
|
+
model_type: Literal['DurationExercise'] = 'DurationExercise'
|
|
126
|
+
|
|
127
|
+
@staticmethod
|
|
128
|
+
def create_set(duration: datetime.timedelta) -> DurationSet:
|
|
129
|
+
return DurationSet(duration=duration)
|
|
130
|
+
|
|
131
|
+
if TYPE_CHECKING:
|
|
132
|
+
|
|
133
|
+
def __hash__(self) -> int: ...
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
# The type union is required for correct pydantic model validation
|
|
137
|
+
Exercise_t = (
|
|
138
|
+
RepsExercise | RepsRPEExercise | RepsAndWeightsExercise | PowerExercise | DurationExercise
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def get_exercise_type_by_key_string(key: str) -> type[Exercise]:
|
|
143
|
+
type_name = key.split('(')[-1].split(')')[0]
|
|
144
|
+
type_dict = {
|
|
145
|
+
'RepsExercise': RepsExercise,
|
|
146
|
+
'RepsRPEExercise': RepsRPEExercise,
|
|
147
|
+
'RepsAndWeightsExercise': RepsAndWeightsExercise,
|
|
148
|
+
'PowerExercise': PowerExercise,
|
|
149
|
+
'DurationExercise': DurationExercise,
|
|
150
|
+
}
|
|
151
|
+
if type_name not in type_dict:
|
|
152
|
+
raise ValueError(f'Unknown exercise type: {type_name}')
|
|
153
|
+
return type_dict[type_name]
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
if __name__ == '__main__':
|
|
157
|
+
test = PowerExercise(name='test')
|
|
158
|
+
print(test.model_dump())
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from pr_pro.exercise import PowerExercise, RepsExercise
|
|
2
|
+
from pr_pro.exercise import RepsAndWeightsExercise
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
pullup = RepsExercise(name='Pullup')
|
|
6
|
+
pushup = RepsExercise(name='Pushup')
|
|
7
|
+
|
|
8
|
+
power_clean = PowerExercise(name='Power Clean')
|
|
9
|
+
|
|
10
|
+
backsquat = RepsAndWeightsExercise(name='Backsquat')
|
|
11
|
+
deadlift = RepsAndWeightsExercise(name='Deadlift')
|
|
12
|
+
bench_press = RepsAndWeightsExercise(name='Bench Press')
|
|
13
|
+
split_squat = RepsAndWeightsExercise(name='Split Squat')
|
|
14
|
+
row = RepsAndWeightsExercise(name='Row')
|
|
15
|
+
|
|
16
|
+
pendlay_row = RepsAndWeightsExercise(name='Pendlay Row')
|
|
17
|
+
hip_thrust = RepsAndWeightsExercise(name='Hip Thrust')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
if __name__ == '__main__':
|
|
21
|
+
print(pullup.model_dump())
|
pr_pro/functions.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import math
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from typing import Protocol, runtime_checkable
|
|
4
|
+
|
|
5
|
+
# Source: https://www.vcalc.com/wiki/brzycki, https://www.vcalc.com/wiki/body-building-weight-lifting-calculator
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@runtime_checkable
|
|
9
|
+
@dataclass(frozen=True)
|
|
10
|
+
class OneRMCalculator(Protocol):
|
|
11
|
+
@staticmethod
|
|
12
|
+
def one_rep_max(weight: float, reps: float) -> float: ...
|
|
13
|
+
@staticmethod
|
|
14
|
+
def max_weight_from_reps(one_rm_weight: float, reps: float) -> float: ...
|
|
15
|
+
@staticmethod
|
|
16
|
+
def max_reps_from_weight(one_rm_weight: float, weight: float) -> float: ...
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@dataclass(frozen=True)
|
|
20
|
+
class Epley1RMCalculator(OneRMCalculator):
|
|
21
|
+
@staticmethod
|
|
22
|
+
def one_rep_max(weight: float, reps: float) -> float:
|
|
23
|
+
return weight * (1 + reps / 30)
|
|
24
|
+
|
|
25
|
+
@staticmethod
|
|
26
|
+
def max_weight_from_reps(one_rm_weight: float, reps: float) -> float:
|
|
27
|
+
return one_rm_weight / (1 + reps / 30)
|
|
28
|
+
|
|
29
|
+
@staticmethod
|
|
30
|
+
def max_reps_from_weight(one_rm_weight: float, weight: float) -> float:
|
|
31
|
+
return 30 * (one_rm_weight / weight - 1)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass(frozen=True)
|
|
35
|
+
class Brzycki1RMCalculator(OneRMCalculator):
|
|
36
|
+
@staticmethod
|
|
37
|
+
def one_rep_max(weight: float, reps: float) -> float:
|
|
38
|
+
return weight * 36 / (37 - reps)
|
|
39
|
+
|
|
40
|
+
@staticmethod
|
|
41
|
+
def max_weight_from_reps(one_rm_weight: float, reps: float) -> float:
|
|
42
|
+
return one_rm_weight * (37 - reps) / 36
|
|
43
|
+
|
|
44
|
+
@staticmethod
|
|
45
|
+
def max_reps_from_weight(one_rm_weight: float, weight: float) -> float:
|
|
46
|
+
return 37 - 36 * weight / one_rm_weight
|
|
47
|
+
# return 37 - 36 * (one_rm_weight / weight)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclass(frozen=True)
|
|
51
|
+
class Landers1RMCalculator(OneRMCalculator):
|
|
52
|
+
@staticmethod
|
|
53
|
+
def one_rep_max(weight: float, reps: float) -> float:
|
|
54
|
+
return weight * (100 / (101.3 - 2.67123 * reps))
|
|
55
|
+
|
|
56
|
+
@staticmethod
|
|
57
|
+
def max_weight_from_reps(one_rm_weight: float, reps: float) -> float:
|
|
58
|
+
return one_rm_weight * (101.3 - 2.67123 * reps) / 100
|
|
59
|
+
|
|
60
|
+
@staticmethod
|
|
61
|
+
def max_reps_from_weight(one_rm_weight: float, weight: float) -> float:
|
|
62
|
+
return (101.3 - 100 * weight / one_rm_weight) / 2.67123
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@dataclass(frozen=True)
|
|
66
|
+
class Lombardi1RMCalculator(OneRMCalculator):
|
|
67
|
+
@staticmethod
|
|
68
|
+
def one_rep_max(weight: float, reps: float) -> float:
|
|
69
|
+
return weight * (reps**0.10)
|
|
70
|
+
|
|
71
|
+
@staticmethod
|
|
72
|
+
def max_weight_from_reps(one_rm_weight: float, reps: float) -> float:
|
|
73
|
+
return one_rm_weight / (reps**0.10)
|
|
74
|
+
|
|
75
|
+
@staticmethod
|
|
76
|
+
def max_reps_from_weight(one_rm_weight: float, weight: float) -> float:
|
|
77
|
+
return one_rm_weight / weight**10
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@dataclass(frozen=True)
|
|
81
|
+
class OConner1RMCalculator(OneRMCalculator):
|
|
82
|
+
@staticmethod
|
|
83
|
+
def one_rep_max(weight: float, reps: float) -> float:
|
|
84
|
+
return weight * (1 + reps / 40)
|
|
85
|
+
|
|
86
|
+
@staticmethod
|
|
87
|
+
def max_weight_from_reps(one_rm_weight: float, reps: float) -> float:
|
|
88
|
+
return one_rm_weight / (1 + reps / 40)
|
|
89
|
+
|
|
90
|
+
@staticmethod
|
|
91
|
+
def max_reps_from_weight(one_rm_weight: float, weight: float) -> float:
|
|
92
|
+
return 40 * (one_rm_weight / weight - 1)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
@dataclass(frozen=True)
|
|
96
|
+
class Wathan1RMCalculator(OneRMCalculator):
|
|
97
|
+
@staticmethod
|
|
98
|
+
def one_rep_max(weight: float, reps: float) -> float:
|
|
99
|
+
return weight * (100 / (48.8 + 53.8 * (reps**-0.075)))
|
|
100
|
+
|
|
101
|
+
@staticmethod
|
|
102
|
+
def max_weight_from_reps(one_rm_weight: float, reps: float) -> float:
|
|
103
|
+
return one_rm_weight * (48.8 + 53.8 * (reps**-0.075)) / 100
|
|
104
|
+
|
|
105
|
+
@staticmethod
|
|
106
|
+
def max_reps_from_weight(one_rm_weight: float, weight: float) -> float:
|
|
107
|
+
return -0.075 * (48.8 - 100 * weight / one_rm_weight) ** -1
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@dataclass(frozen=True)
|
|
111
|
+
class Mayhew1RMCalculator(OneRMCalculator):
|
|
112
|
+
@staticmethod
|
|
113
|
+
def one_rep_max(weight: float, reps: float) -> float:
|
|
114
|
+
return weight * (100 / (52.2 + 41.9 * (math.exp(-0.055 * reps))))
|
|
115
|
+
|
|
116
|
+
@staticmethod
|
|
117
|
+
def max_weight_from_reps(one_rm_weight: float, reps: float) -> float:
|
|
118
|
+
return one_rm_weight * (52.2 + 41.9 * (math.exp(-0.055 * reps))) / 100
|
|
119
|
+
|
|
120
|
+
@staticmethod
|
|
121
|
+
def max_reps_from_weight(one_rm_weight: float, weight: float) -> float:
|
|
122
|
+
return -1 / 0.055 * math.log((52.2 - 100 * weight / one_rm_weight) / 41.9)
|
pr_pro/program.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import Self
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel, field_serializer
|
|
6
|
+
|
|
7
|
+
from pr_pro.workout_session import WorkoutSession
|
|
8
|
+
from pr_pro.configs import ComputeConfig
|
|
9
|
+
from pr_pro.exercise import Exercise, Exercise_t
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Program(BaseModel):
|
|
13
|
+
name: str
|
|
14
|
+
best_exercise_values: dict[Exercise_t, float] = {}
|
|
15
|
+
workout_session_dict: dict[str, WorkoutSession] = {}
|
|
16
|
+
program_phases: dict[str, list[str]] = {}
|
|
17
|
+
|
|
18
|
+
def __str__(self) -> str:
|
|
19
|
+
workout_str = f'--- Workout {self.name} ---\n'
|
|
20
|
+
best_exercise_str = (
|
|
21
|
+
'Best exercise values\n '
|
|
22
|
+
+ '\n '.join([f'{e.name}: {value}' for e, value in self.best_exercise_values.items()])
|
|
23
|
+
+ '\n\n'
|
|
24
|
+
)
|
|
25
|
+
workout_sessions_str = (
|
|
26
|
+
'Workout sessions\n'
|
|
27
|
+
+ '\n'.join(ws.__str__() for ws in self.workout_session_dict.values())
|
|
28
|
+
+ '\n'
|
|
29
|
+
)
|
|
30
|
+
return workout_str + best_exercise_str + workout_sessions_str
|
|
31
|
+
|
|
32
|
+
def add_workout_session(self, workout_session: WorkoutSession) -> Self:
|
|
33
|
+
if workout_session.id in self.workout_session_dict:
|
|
34
|
+
raise ValueError(
|
|
35
|
+
f'Workout session with id {workout_session.id} already exists in the program.'
|
|
36
|
+
)
|
|
37
|
+
self.workout_session_dict[workout_session.id] = workout_session
|
|
38
|
+
return self
|
|
39
|
+
|
|
40
|
+
def add_program_phase(self, phase_id: str, session_ids: list[str]) -> Self:
|
|
41
|
+
if phase_id in self.program_phases:
|
|
42
|
+
raise ValueError(f'Program phase with id {phase_id} already exists.')
|
|
43
|
+
if not all(session_id in self.workout_session_dict for session_id in session_ids):
|
|
44
|
+
raise ValueError('One or more session IDs do not exist in the program.')
|
|
45
|
+
self.program_phases[phase_id] = session_ids
|
|
46
|
+
return self
|
|
47
|
+
|
|
48
|
+
def get_workout_session_by_id(self, session_id: str) -> WorkoutSession | None:
|
|
49
|
+
return self.workout_session_dict.get(session_id, None)
|
|
50
|
+
|
|
51
|
+
def add_best_exercise_value(self, exercise: Exercise_t, value: float) -> Self:
|
|
52
|
+
self.best_exercise_values[exercise] = value
|
|
53
|
+
return self
|
|
54
|
+
|
|
55
|
+
def compute_values(self, compute_config: ComputeConfig) -> None:
|
|
56
|
+
for session in self.workout_session_dict.values():
|
|
57
|
+
session.compute_values(self.best_exercise_values, compute_config)
|
|
58
|
+
|
|
59
|
+
@field_serializer('best_exercise_values')
|
|
60
|
+
def serialize_best_exercise_values(self, v: dict[Exercise, float], _info) -> dict[str, float]:
|
|
61
|
+
return {key.__str__(): value for key, value in v.items()}
|
|
62
|
+
|
|
63
|
+
def write_json_file(self, file_path: Path) -> None:
|
|
64
|
+
with open(file_path, 'w') as f:
|
|
65
|
+
f.write(self.model_dump_json(indent=2))
|
|
66
|
+
|
|
67
|
+
@staticmethod
|
|
68
|
+
def from_json_file(file_path: Path) -> Program:
|
|
69
|
+
with open(file_path, 'r') as f:
|
|
70
|
+
return Program.model_validate_json(f.read())
|