-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram.py
More file actions
1271 lines (1048 loc) · 46.5 KB
/
program.py
File metadata and controls
1271 lines (1048 loc) · 46.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import copy
import random
from reportlab.lib.colors import HexColor
from reportlab.lib.pagesizes import letter
from reportlab.lib.units import inch
from reportlab.pdfgen import canvas
import sys
from PySide6.QtWidgets import (
QApplication, QWidget, QVBoxLayout, QTableWidget,
QTableWidgetItem, QPushButton, QLabel, QHeaderView, QComboBox, QHBoxLayout,
QDialog, QListWidget, QLineEdit, QMessageBox, QInputDialog, QListWidgetItem
)
from PySide6.QtCore import Qt
from openpyxl import Workbook
from openpyxl.styles import Font, Alignment
from openpyxl.utils import get_column_letter
import json
import os
CLIENTS_FILE = "clients.json"
PROGRAMS_DIR = "programs"
UID = 0
class UidManager:
@staticmethod
def set_start(value):
global UID
UID = value
@staticmethod
def get_uid():
global UID
UID += 1
return UID
class Client:
def __init__(self, name, weight, height, age, sex, uid=None):
self.name = name
self.weight = weight
self.height = height
self.age = age
self.sex = sex
self.uid = uid if uid is not None else UidManager.get_uid()
def to_dict(self):
return {"name": self.name, "weight": self.weight, "height": self.height, "age": self.age, "sex": self.sex, "uid": self.uid}
@staticmethod
def from_dict(d):
return Client(d["name"], d["weight"], d["height"], d["age"], d["sex"], uid=d["uid"])
class ClientManager:
def __init__(self, filename=CLIENTS_FILE):
self.filename = filename
self.clients = []
self.load()
def load(self):
try:
with open(self.filename, "r") as f:
data = json.load(f)
self.clients = [Client.from_dict(c) for c in data]
if self.clients:
max_uid = max(c.uid for c in self.clients)
UidManager.set_start(max_uid)
except FileNotFoundError:
self.clients = []
UidManager.set_start(0)
def save(self):
with open(self.filename, "w") as f:
json.dump([c.to_dict() for c in self.clients], f, indent=2)
def add_client(self, name, weight, height, age, sex):
if name:
self.clients.append(Client(name, weight, height, age, sex))
self.save()
def get_by_uid(self, uid):
return next((c for c in self.clients if c.uid == uid), None)
class Exercise:
def __init__(self, name, type, link=""):
self.name = name
self.type = type
self.link = link
self.base_sets = 2
self.sets = 2
if type in (0, 1):
self.base_reps = "4-6"
else:
self.base_reps = "6-8"
self.reps = self.base_reps
#Will add progression to make it scale for larger week ranges
def apply_progression(self, week):
adjusted_week = week % 5
if adjusted_week == 3:
self.sets = min(self.base_sets + 1, 4)
low, high = map(int, self.base_reps.split("-"))
self.reps = f"{low+1}-{high+1}"
elif adjusted_week == 4:
self.sets = min(self.base_sets + 1, 4)
low, high = map(int, self.base_reps.split("-"))
self.reps = f"{low+2}-{high+2}"
def print_exercise(self):
print(f"Exercise: {self.name}, Type: {self.type}, Volume: {self.sets}x{self.reps}, Link: {self.link}")
class ExerciseList:
def __init__(self):
self.exercises = []
def add_exercise(self, exercise):
self.exercises.append(exercise)
def add_exercise_by_con(self, name, type, link=""):
self.exercises.append(Exercise(name, type, link))
def remove_exercise(self, name):
self.exercises = [e for e in self.exercises if e.name != name]
def get_exercises_by_type(self, type) -> list:
return [exercise for exercise in self.exercises if exercise.type == type]
def to_dict(self):
return [
{"name": e.name, "type": e.type, "link": e.link}
for e in self.exercises
]
def load_from_dict(self, data):
self.exercises.clear()
for e in data:
self.add_exercise_by_con(e["name"], e["type"], e.get("link", ""))
# 0 = Regular Press, 1 = Upper Chest Press, 2 = Regular Fly, 3 = Upper Chest Fly
# 0 = Heavy Tricep Lateral, 1 = Heavy Tricep Long, 2 = Tricep Pushdown Variation, 3 = Tricep Overhead Variation
# 0 = Heavy Rowing Movement, 1 = Heavy Pulling Movement, 2 = Close Grip Rowing Movement, 3 = Traps
# 0 = Heavy Curls Long, 1 = Heavy Curls Short, 2 = Light Curls Long, 3 = Light Curls Short
# 0 = Heavy Squat, 1 = Heavy Hinge, 2 = Light Squat/Hinge, 3 = Accessory Lower Body
# 0 = Heavy Shoulder Press, 1 = Raise Variation, 2 = Rear Delt Variation, 3 = Calfs
chest_exercises = ExerciseList()
chest_exercises.add_exercise_by_con("Flat Barbell Bench Press", 0)
chest_exercises.add_exercise_by_con("Flat Dumbbell Bench Press", 0)
chest_exercises.add_exercise_by_con("Incline Barbell Bench Press", 1)
chest_exercises.add_exercise_by_con("Incline Dumbbell Bench Press", 1)
chest_exercises.add_exercise_by_con("Incline Smith Machine Press", 1)
chest_exercises.add_exercise_by_con("Incline Machine Press", 1)
chest_exercises.add_exercise_by_con("Standing Cable Fly", 2)
chest_exercises.add_exercise_by_con("Machine Cable Fly (Pec Deck)", 2)
chest_exercises.add_exercise_by_con("Decline Cable Fly", 2)
chest_exercises.add_exercise_by_con("Low to High Cable Fly", 3)
triceps_exercises = ExerciseList()
triceps_exercises.add_exercise_by_con("Close Grip Bench Press", 0)
triceps_exercises.add_exercise_by_con("Weighted Dips", 0)
triceps_exercises.add_exercise_by_con("Machine Dips", 0)
triceps_exercises.add_exercise_by_con("Skull Crushers", 1)
triceps_exercises.add_exercise_by_con("JM Press", 1)
triceps_exercises.add_exercise_by_con("Rope Tricep Pushdown", 2)
triceps_exercises.add_exercise_by_con("Straight Bar Tricep Pushdown", 2)
triceps_exercises.add_exercise_by_con("V-Bar Tricep Pushdown", 2)
triceps_exercises.add_exercise_by_con("Overhead Dumbbell Tricep Extension", 3)
triceps_exercises.add_exercise_by_con("Overhead Cable Tricep Extension", 3)
triceps_exercises.add_exercise_by_con("Single Arm Overhead Cable Tricep Extension", 3)
triceps_exercises.add_exercise_by_con("Single Arm Overhead Dumbbell Tricep Extension", 3)
back_exercises = ExerciseList()
back_exercises.add_exercise_by_con("Bent Over Barbell Rows", 0)
back_exercises.add_exercise_by_con("Bent Over Dumbbell Rows", 0)
back_exercises.add_exercise_by_con("Chest-Supported T-Bar Rows", 0)
back_exercises.add_exercise_by_con("Weighted Pull-Ups", 1)
back_exercises.add_exercise_by_con("Wide-Grip Lat-Pulldowns", 1)
back_exercises.add_exercise_by_con("Seated Cable Row", 2)
back_exercises.add_exercise_by_con("Seated Cable Row (V-Bar)", 2)
back_exercises.add_exercise_by_con("Face Pulls", 3)
back_exercises.add_exercise_by_con("Shrugs", 3)
bicep_exercises = ExerciseList()
bicep_exercises.add_exercise_by_con("Ez-Bar Curls", 0)
bicep_exercises.add_exercise_by_con("Dumbbell Curls", 0)
bicep_exercises.add_exercise_by_con("Preacher Curls", 1)
bicep_exercises.add_exercise_by_con("Cable Curls", 2)
bicep_exercises.add_exercise_by_con("Reverse Barbell Curls", 2)
bicep_exercises.add_exercise_by_con("Incline Dumbbell Curls", 2)
bicep_exercises.add_exercise_by_con("Hammer Curls", 2)
bicep_exercises.add_exercise_by_con("Spider Curls", 3)
bicep_exercises.add_exercise_by_con("Wide-Grip Ez-Bar Curls", 3)
leg_exercises = ExerciseList()
leg_exercises.add_exercise_by_con("Barbell Back Squat", 0)
leg_exercises.add_exercise_by_con("Front Squat", 0)
leg_exercises.add_exercise_by_con("Goblet Squat", 0)
leg_exercises.add_exercise_by_con("Romanian Deadlift", 1)
leg_exercises.add_exercise_by_con("Conventional Deadlift", 1)
leg_exercises.add_exercise_by_con("Leg Press", 2)
leg_exercises.add_exercise_by_con("Lunges", 2)
leg_exercises.add_exercise_by_con("Leg Extensions", 3)
leg_exercises.add_exercise_by_con("Leg Curls", 3)
shoulder_exercises = ExerciseList()
shoulder_exercises.add_exercise_by_con("Overhead Barbell Press", 0)
shoulder_exercises.add_exercise_by_con("Dumbbell Shoulder Press", 0)
shoulder_exercises.add_exercise_by_con("Lateral Raises", 1)
shoulder_exercises.add_exercise_by_con("Cable Lateral Raises", 1)
shoulder_exercises.add_exercise_by_con("Reverse Pec Deck Fly", 2)
shoulder_exercises.add_exercise_by_con("Bent Over Dumbbell Reverse Fly", 2)
shoulder_exercises.add_exercise_by_con("Face Pulls", 2)
shoulder_exercises.add_exercise_by_con("Calf Raises", 3)
EXERCISE_POOLS = {
"Chest": chest_exercises,
"Triceps": triceps_exercises,
"Back": back_exercises,
"Biceps": bicep_exercises,
"Legs": leg_exercises,
"Shoulders": shoulder_exercises
}
class WorkoutExercises:
def __init__(self, exercise_list):
self.exercise_list = exercise_list
self.program = {}
def generate_exercises(self):
program = []
heavy_exercises = self.exercise_list.get_exercises_by_type(0) + self.exercise_list.get_exercises_by_type(1)
program.append(random.choice(heavy_exercises))
type_chosen = program[0].type
program.append(random.choice(self.exercise_list.get_exercises_by_type(1-type_chosen)))
secondary_exercises = self.exercise_list.get_exercises_by_type(2) + self.exercise_list.get_exercises_by_type(3)
program.append(random.choice(secondary_exercises))
second_light = random.choice(secondary_exercises)
while second_light.type in [exercise.type for exercise in program]:
second_light = random.choice(secondary_exercises)
program.append(second_light)
return program
#Multiple Different Ways to Generate a Program
# Chest/Back Arms Legs 2x a Week (0)
# Push Pull Legs 2x a Week (1)
# Full Body 3x a Week (2)
# Upper Lower 2x a Week (3)
class WorkoutProgram:
def __init__(self, program_type):
self.program_type = program_type
self.workouts = {}
def generate_program(self):
self.workouts = {}
if self.program_type == 0:
self.generate_arnold_split()
elif self.program_type == 1:
self.generate_ppl_program()
elif self.program_type == 2:
self.generate_full_body_program()
def generate_arnold_split(self):
chest_workout = WorkoutExercises(chest_exercises)
program_chest = chest_workout.generate_exercises()
back_workout = WorkoutExercises(back_exercises)
program_back = back_workout.generate_exercises()
program_chest.sort(key=lambda x: x.type)
program_back.sort(key=lambda x: x.type)
self.workouts["Chest & Back"] = program_chest + program_back
bicep_workout = WorkoutExercises(bicep_exercises)
program_bicep = bicep_workout.generate_exercises()
tricep_workout = WorkoutExercises(triceps_exercises)
program_triceps = tricep_workout.generate_exercises()
program_triceps.sort(key=lambda x: x.type)
program_bicep.sort(key=lambda x: x.type)
self.workouts["Arms"] = program_triceps + program_bicep
leg_workout = WorkoutExercises(leg_exercises)
program_legs = leg_workout.generate_exercises()
shoulder_workout = WorkoutExercises(shoulder_exercises)
program_shoulders = shoulder_workout.generate_exercises()
program_legs.sort(key=lambda x: x.type)
program_shoulders.sort(key=lambda x: x.type)
self.workouts["Legs & Shoulders"] = program_legs + program_shoulders
def generate_ppl_program(self):
chest_workout = WorkoutExercises(chest_exercises)
program_chest = chest_workout.generate_exercises()
tricep_workout = WorkoutExercises(triceps_exercises)
program_triceps = tricep_workout.generate_exercises()
program_triceps.sort(key=lambda x: x.type)
program_chest.sort(key=lambda x: x.type)
self.workouts["Push"] = program_chest + program_triceps
back_workout = WorkoutExercises(back_exercises)
program_back = back_workout.generate_exercises()
bicep_workout = WorkoutExercises(bicep_exercises)
program_bicep = bicep_workout.generate_exercises()
program_back.sort(key=lambda x: x.type)
program_bicep.sort(key=lambda x: x.type)
self.workouts["Pull"] = program_back + program_bicep
leg_workout = WorkoutExercises(leg_exercises)
program_legs = leg_workout.generate_exercises()
shoulder_workout = WorkoutExercises(shoulder_exercises)
program_shoulders = shoulder_workout.generate_exercises()
program_legs.sort(key=lambda x: x.type)
program_shoulders.sort(key=lambda x: x.type)
self.workouts["Legs & Shoulders"] = program_legs + program_shoulders
def generate_full_body_program(self):
program_chest = WorkoutExercises(chest_exercises).generate_exercises()
program_back = WorkoutExercises(back_exercises).generate_exercises()
program_legs = WorkoutExercises(leg_exercises).generate_exercises()
program_biceps = WorkoutExercises(bicep_exercises).generate_exercises()
program_triceps = WorkoutExercises(triceps_exercises).generate_exercises()
program_shoulders = WorkoutExercises(shoulder_exercises).generate_exercises()
exercises_a = [program_chest[0], program_back[0], program_legs[0], program_biceps[0], program_triceps[0], program_shoulders[0]]
self.workouts["Full Body A"] = exercises_a
exercises_b = [program_chest[1], program_back[1], program_legs[1], program_biceps[1], program_triceps[1], program_shoulders[1]]
self.workouts["Full Body B"] = exercises_b
exercises_c = [program_chest[0], program_back[0], program_legs[0], program_biceps[2], program_triceps[2], program_shoulders[2]]
self.workouts["Full Body C"] = exercises_c
def print_program(self):
for workout_name, exercises in self.workouts.items():
print(f"{workout_name} Workout:")
for exercise in exercises:
exercise.print_exercise()
print()
class Week:
def __init__(self, program):
self.program = program
self.schedule = {}
def generate_week_schedule(self):
days = list(self.program.workouts.keys())
for day in days:
self.schedule[day] = self.program.workouts[day]
def print_week_schedule(self):
for day, exercises in self.schedule.items():
print(f"{day}:")
for exercise in exercises:
exercise.print_exercise()
print()
class TrainingBlock:
def __init__(self, program, weeks=4):
self.program = program
self.weeks = []
self.num_weeks = weeks
def generate(self):
for week_number in range(1, self.num_weeks + 1):
self.program.generate_program()
week = Week(self.program)
week.generate_week_schedule()
for day, exercises in week.schedule.items():
week.schedule[day] = [copy.deepcopy(ex) for ex in exercises]
for exercises in week.schedule.values():
for ex in exercises:
ex.apply_progression(week_number)
self.weeks.append(week)
def to_dict(self):
return {
"program_type": self.program.program_type,
"num_weeks": self.num_weeks,
"weeks": [
{
"schedule": {
day: [
{
"name": ex.name,
"type": ex.type,
"sets": ex.sets,
"reps": ex.reps,
"link": ex.link
} for ex in exercises
]
for day, exercises in week.schedule.items()
}
}
for week in self.weeks
]
}
@staticmethod
def from_dict(data):
program_type = data.get("program_type", 0)
dummy_program = WorkoutProgram(program_type=program_type)
block = TrainingBlock(dummy_program, weeks=data["num_weeks"])
block.weeks = []
for week_data in data["weeks"]:
week = Week(dummy_program)
week.schedule = {}
for day, exercises in week_data["schedule"].items():
week.schedule[day] = []
for e in exercises:
ex = Exercise(e["name"], e["type"], e.get("link", ""))
ex.sets = e["sets"]
ex.reps = e["reps"]
week.schedule[day].append(ex)
block.weeks.append(week)
return block
os.makedirs(PROGRAMS_DIR, exist_ok=True)
def program_path(client_uid):
return os.path.join(PROGRAMS_DIR, f"{client_uid}.json")
def save_client_program(client_uid, block):
with open(program_path(client_uid), "w") as f:
json.dump(block.to_dict(), f, indent=2)
def load_client_program(client_uid):
path = program_path(client_uid)
if not os.path.exists(path):
return None
with open(path, "r") as f:
return TrainingBlock.from_dict(json.load(f))
def export_block_to_light_pdf(block, filename="Training_Block.pdf"):
c = canvas.Canvas(filename, pagesize=letter)
width, height = letter
bg = HexColor("#FFFFFF")
text = HexColor("#0F172A")
accent = HexColor("#2563EB")
muted = HexColor("#475569")
for week_index, week in enumerate(block.weeks):
c.setFillColor(bg)
c.rect(0, 0, width, height, stroke=0, fill=1)
y = height - 1.2 * inch
c.setFont("Helvetica-Bold", 22)
c.setFillColor(text)
if (week_index + 1) % 5 == 0:
c.drawString(1 * inch, y, f"Week {week_index + 1} (Heavy)")
else:
c.drawString(1 * inch, y, f"Week {week_index + 1}")
y -= 0.4 * inch
for day, exercises in week.schedule.items():
if y < 2 * inch:
c.showPage()
y = height - 1.2 * inch
c.setFont("Helvetica-Bold", 17)
c.setFillColor(accent)
c.drawString(1 * inch, y, day)
y -= 0.25 * inch
c.setStrokeColor(accent)
c.setLineWidth(1.2)
c.line(1 * inch, y, width - 1 * inch, y)
y -= 0.3 * inch
for ex in exercises:
c.setFont("Helvetica-Bold", 13)
c.setFillColor(text)
c.drawString(1.1 * inch, y, ex.name)
c.setFont("Helvetica", 11)
c.setFillColor(muted)
c.drawRightString(
width - 1 * inch,
y,
f"{ex.sets} x {ex.reps}"
)
y -= 0.25 * inch
y -= 0.35 * inch
c.showPage()
c.save()
def export_nutrition_to_light_pdf(
weight_kg,
height_cm,
age,
sex,
activity_label,
activity_factor,
filename="Nutrition_Plan.pdf"
):
maintenance = NutritionCalculator.maintenance_calories(
weight_kg, height_cm, age, sex, activity_factor
)
bulk = NutritionCalculator.bulk_calories(maintenance)
cut = NutritionCalculator.cut_calories(maintenance)
c = canvas.Canvas(filename, pagesize=letter)
width, height = letter
bg = HexColor("#FFFFFF")
text = HexColor("#0F172A")
accent = HexColor("#2563EB")
muted = HexColor("#475569")
c.setFillColor(bg)
c.rect(0, 0, width, height, stroke=0, fill=1)
y = height - 1.2 * inch
# Title
c.setFont("Helvetica-Bold", 24)
c.setFillColor(text)
c.drawString(1 * inch, y, "Nutrition Overview")
y -= 0.5 * inch
c.setStrokeColor(accent)
c.setLineWidth(2)
c.line(1 * inch, y, width - 1 * inch, y)
y -= 0.6 * inch
# Stats
c.setFont("Helvetica-Bold", 16)
c.setFillColor(accent)
c.drawString(1 * inch, y, "Client Stats")
y -= 0.35 * inch
c.setFont("Helvetica", 13)
c.setFillColor(text)
stats = [
f"Weight: {weight_kg} kg",
f"Height: {height_cm} cm",
f"Age: {age}",
f"Sex: {sex}",
f"Activity Level: {activity_label}"
]
for s in stats:
c.drawString(1.1 * inch, y, s)
y -= 0.25 * inch
y -= 0.4 * inch
# Calories
c.setFont("Helvetica-Bold", 16)
c.setFillColor(accent)
c.drawString(1 * inch, y, "Daily Calories")
y -= 0.35 * inch
c.setFont("Helvetica", 14)
c.setFillColor(text)
c.drawString(1.1 * inch, y, f"Maintenance Calories:")
c.drawRightString(width - 1 * inch, y, f"{maintenance} kcal")
y -= 0.3 * inch
c.drawString(1.1 * inch, y, f"Lean Bulk Calories:")
c.drawRightString(width - 1 * inch, y, f"{bulk} kcal")
y -= 0.3 * inch
c.drawString(1.1 * inch, y, f"Fat Loss Calories:")
c.drawRightString(width - 1 * inch, y, f"{cut} kcal")
y -= 0.6 * inch
c.save()
def autosize_worksheet_columns(ws, min_width=10, max_width=50):
for col_cells in ws.columns:
max_length = 0
col_letter = get_column_letter(col_cells[0].column)
for cell in col_cells:
if cell.value:
cell_length = len(str(cell.value))
max_length = max(max_length, cell_length)
adjusted_width = max(min_width, min(max_length + 2, max_width))
ws.column_dimensions[col_letter].width = adjusted_width
def export_training_block_to_excel(block, filename="Training_Block.xlsx"):
wb = Workbook()
wb.remove(wb.active) # remove default sheet
header_font = Font(bold=True)
center_align = Alignment(vertical="center")
for week_index, week in enumerate(block.weeks, start=1):
ws = wb.create_sheet(title=f"Week {week_index}")
ws.append(["Day", "Exercise", "Sets", "Reps", "Weight"])
for col in range(1, 5):
cell = ws.cell(row=1, column=col)
cell.font = header_font
cell.alignment = center_align
ws.column_dimensions[chr(64 + col)].width = 22
row = 2
for day, exercises in week.schedule.items():
for ex in exercises:
ws.cell(row=row, column=1, value=day)
ws.cell(row=row, column=2, value=ex.name)
ws.cell(row=row, column=3, value=ex.sets)
ws.cell(row=row, column=4, value=ex.reps)
row += 1
autosize_worksheet_columns(ws)
wb.save(filename)
class ProgramGUI(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Workout Program Generator & Multi-Week Preview")
self.setGeometry(100, 100, 800, 500)
self.training_block = None
self.week_number = 0
self.layout = QVBoxLayout()
self.setLayout(self.layout)
self.client_manager = ClientManager()
self.current_client = None
client_layout = QHBoxLayout()
self.layout.addLayout(client_layout)
client_layout.addWidget(QLabel("Client:"))
self.client_selector = QComboBox()
self.client_selector.addItem("— No Client —")
for c in self.client_manager.clients:
self.client_selector.addItem(c.name, c.uid)
self.client_selector.currentIndexChanged.connect(self.on_client_selected)
client_layout.addWidget(self.client_selector)
self.manage_clients_btn = QPushButton("Manage Clients")
self.manage_clients_btn.clicked.connect(self.open_client_manager)
client_layout.addWidget(self.manage_clients_btn)
top_layout = QHBoxLayout()
self.layout.addLayout(top_layout)
top_layout.addWidget(QLabel("Program Type:"))
self.program_selector = QComboBox()
self.program_selector.addItems(["PPL", "Arnold Split", "Full Body"])
top_layout.addWidget(self.program_selector)
self.week_selector = QComboBox()
self.week_selector.addItems(["5", "10", "15"])
top_layout.addWidget(self.week_selector)
self.generate_button = QPushButton("Generate Program")
self.generate_button.clicked.connect(self.generate_program)
top_layout.addWidget(self.generate_button)
self.week_label = QLabel("")
self.week_label.setAlignment(Qt.AlignCenter)
self.layout.addWidget(self.week_label)
self.table = QTableWidget()
self.table.setColumnCount(5)
self.table.setHorizontalHeaderLabels(["Day", "Exercise", "Type", "Sets", "Reps"])
self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
self.layout.addWidget(self.table)
nav_layout = QHBoxLayout()
self.layout.addLayout(nav_layout)
self.prev_week_btn = QPushButton("<< Previous Week")
self.prev_week_btn.clicked.connect(self.prev_week)
nav_layout.addWidget(self.prev_week_btn)
self.next_week_btn = QPushButton("Next Week >>")
self.next_week_btn.clicked.connect(self.next_week)
nav_layout.addWidget(self.next_week_btn)
self.save_btn = QPushButton("Save Current Week Edits")
self.save_btn.clicked.connect(self.save_week)
nav_layout.addWidget(self.save_btn)
self.nutrition_dialog = NutritionDialog(self)
self.nutrition_btn = QPushButton("Nutrition Calculator")
self.nutrition_btn.clicked.connect(self.open_nutrition)
nav_layout.addWidget(self.nutrition_btn)
self.manage_btn = QPushButton("Manage Exercises")
self.manage_btn.clicked.connect(self.open_exercise_manager)
nav_layout.addWidget(self.manage_btn)
self.export_ex_btn = QPushButton("Export Exercises")
self.export_ex_btn.clicked.connect(lambda: export_exercises_to_json())
nav_layout.addWidget(self.export_ex_btn)
self.import_ex_btn = QPushButton("Import Exercises")
self.import_ex_btn.clicked.connect(self.import_exercises)
nav_layout.addWidget(self.import_ex_btn)
self.save_pdf_btn = QPushButton("Export Training Block to PDF")
self.save_pdf_btn.clicked.connect(self.save_week)
self.save_pdf_btn.clicked.connect(self.export_current_block_to_pdf)
nav_layout.addWidget(self.save_pdf_btn)
self.export_excel_btn = QPushButton("Export Training Block to Excel")
self.export_excel_btn.clicked.connect(self.save_week)
self.export_excel_btn.clicked.connect(self.export_current_block_to_excel)
nav_layout.addWidget(self.export_excel_btn)
def on_client_selected(self, index):
uid = self.client_selector.itemData(index)
if uid is None:
self.current_client = None
self.training_block = None
self.table.setRowCount(0)
self.week_label.setText("")
self.nutrition_dialog.reset_data()
return
client_obj = self.client_manager.get_by_uid(uid)
if client_obj:
self.current_client = client_obj
self.nutrition_dialog.set_client_data(
client_obj.weight,
client_obj.height,
client_obj.age,
client_obj.sex
)
block = load_client_program(client_obj.uid)
if block:
self.training_block = block
self.week_number = 0
self.show_week()
else:
self.training_block = None
self.table.setRowCount(0)
self.week_label.setText("")
QMessageBox.information(
self,
"No Program Found",
f"{client_obj.name} has no saved program.\nGenerate one and it will be saved automatically."
)
def export_current_block_to_pdf(self):
if self.training_block:
filename, ok = QInputDialog.getText(None, "Input Dialog", "Enter document name:", QLineEdit.Normal, "")
if ok and filename != "":
filename += ".pdf"
export_block_to_light_pdf(self.training_block, filename=filename)
print(f"Exported current training block to {filename}")
elif ok and not filename:
filename = f"Training_Block_Week_{len(self.training_block.weeks)}.pdf"
export_block_to_light_pdf(self.training_block, filename=filename)
print(f"Exported current training block to {filename}")
def export_current_block_to_excel(self):
if self.training_block:
filename, ok = QInputDialog.getText(None, "Input Dialog", "Enter document name:", QLineEdit.Normal, "")
if ok and filename != "":
filename += ".xlsx"
export_training_block_to_excel(self.training_block, filename=filename)
print(f"Exported current training block to {filename}")
elif ok and not filename:
filename = f"Training_Block_Week_{len(self.training_block.weeks)}.xlsx"
export_training_block_to_excel(self.training_block, filename=filename)
print(f"Exported current training block to {filename}")
def open_client_manager(self):
dlg = ClientManagerDialog(self, self.client_manager)
dlg.exec()
self.client_selector.clear()
self.client_selector.addItem("— No Client —")
for c in self.client_manager.clients:
self.client_selector.addItem(c.name, c.uid)
def open_exercise_manager(self):
dlg = ExerciseManager(self)
dlg.exec()
def import_exercises(self):
import_exercises_from_json()
print("Exercise config imported.")
def open_nutrition(self):
#dlg = NutritionDialog(self)
self.nutrition_dialog.exec()
def generate_program(self):
program_type = self.program_selector.currentText()
amt_weeks = int(self.week_selector.currentText())
if program_type == "PPL":
wp = WorkoutProgram(program_type=1)
elif program_type == "Arnold Split":
wp = WorkoutProgram(program_type=0)
else:
wp = WorkoutProgram(program_type=2)
self.training_block = TrainingBlock(wp, weeks=amt_weeks)
self.training_block.generate()
self.week_number = 0
self.show_week()
if self.current_client and load_client_program(self.current_client.uid) is None:
save_client_program(self.current_client.uid, self.training_block)
def show_week(self):
week = self.training_block.weeks[self.week_number]
self.week_label.setText(f"Week {self.week_number + 1}")
# Count total exercises
total_exercises = sum(len(exs) for exs in week.schedule.values())
self.table.setRowCount(total_exercises)
row_index = 0
for day, exercises in week.schedule.items():
for ex in exercises:
self.table.setItem(row_index, 0, QTableWidgetItem(day))
self.table.item(row_index, 0).setFlags(Qt.ItemIsEnabled)
self.table.setItem(row_index, 1, QTableWidgetItem(ex.name))
self.table.item(row_index, 1).setFlags(Qt.ItemIsEnabled)
self.table.setItem(row_index, 2, QTableWidgetItem(str(ex.type)))
self.table.item(row_index, 2).setFlags(Qt.ItemIsEnabled)
self.table.setItem(row_index, 3, QTableWidgetItem(str(ex.sets)))
self.table.setItem(row_index, 4, QTableWidgetItem(str(ex.reps)))
row_index += 1
def save_week(self):
if not self.training_block:
return
week = self.training_block.weeks[self.week_number]
row_index = 0
for day, exercises in week.schedule.items():
for i, ex in enumerate(exercises):
sets = self.table.item(row_index, 3).text()
reps = self.table.item(row_index, 4).text()
ex.sets = int(sets)
ex.reps = reps
row_index += 1
if self.current_client:
save_client_program(self.current_client.uid, self.training_block)
print(f"Week {self.week_number + 1} edits saved.")
def next_week(self):
if self.training_block and self.week_number < len(self.training_block.weeks) - 1:
self.save_week()
self.week_number += 1
self.show_week()
def prev_week(self):
if self.training_block and self.week_number > 0:
self.save_week()
self.week_number -= 1
self.show_week()
class EditClientDialog(QDialog):
def __init__(self, client, parent=None):
super().__init__(parent)
self.setWindowTitle(f"Edit Client: {client.name}")
self.client = client
self.setMinimumWidth(300)
layout = QVBoxLayout(self)
self.weight_input = QLineEdit(str(client.weight))
self.weight_input.setPlaceholderText("Weight (kg)")
layout.addWidget(QLabel("Weight (kg)"))
layout.addWidget(self.weight_input)
self.height_input = QLineEdit(str(client.height))
self.height_input.setPlaceholderText("Height (cm)")
layout.addWidget(QLabel("Height (cm)"))
layout.addWidget(self.height_input)
self.age_input = QLineEdit(str(client.age))
self.age_input.setPlaceholderText("Age")
layout.addWidget(QLabel("Age"))
layout.addWidget(self.age_input)
self.sex_input = QComboBox()
self.sex_input.addItems(["Male", "Female"])
self.sex_input.setCurrentText(client.sex)
layout.addWidget(QLabel("Sex"))
layout.addWidget(self.sex_input)
btn_layout = QHBoxLayout()
save_btn = QPushButton("Save")
cancel_btn = QPushButton("Cancel")
btn_layout.addWidget(save_btn)
btn_layout.addWidget(cancel_btn)
layout.addLayout(btn_layout)
save_btn.clicked.connect(self.save)
cancel_btn.clicked.connect(self.reject)
def save(self):
try:
self.client.weight = float(self.weight_input.text())
self.client.height = float(self.height_input.text())
self.client.age = int(self.age_input.text())
self.client.sex = self.sex_input.currentText()
self.accept()
except ValueError:
QMessageBox.warning(self, "Input Error", "Please enter valid numbers.")
class ClientManagerDialog(QDialog):
def __init__(self, parent, manager):
super().__init__(parent)
self.manager = manager
self.setWindowTitle("Client Manager")
self.setMinimumWidth(300)
layout = QVBoxLayout(self)
self.list = QListWidget()
self.refresh_list()
layout.addWidget(self.list)
self.name_input = QLineEdit()
self.name_input.setPlaceholderText("Client Name")
self.weight = QLineEdit()
self.weight.setPlaceholderText("Weight (kg)")
self.client_height = QLineEdit()
self.client_height.setPlaceholderText("Height (cm)")
self.age = QLineEdit()
self.age.setPlaceholderText("Age")
self.sex = QComboBox()
self.sex.addItems(["Male", "Female"])
for w in [self.name_input, self.weight, self.client_height, self.age, self.sex]:
layout.addWidget(w)
btn_layout = QHBoxLayout()
add_btn = QPushButton("Add Client")
add_btn.clicked.connect(self.add_client)
edit_btn = QPushButton("Edit Client")
edit_btn.clicked.connect(self.edit_client)
remove_btn = QPushButton("Remove Client")
remove_btn.clicked.connect(self.remove_client)
clear_btn = QPushButton("Clear Inputs")
clear_btn.clicked.connect(self.clear_inputs)
btn_layout.addWidget(add_btn)
btn_layout.addWidget(edit_btn)
btn_layout.addWidget(remove_btn)
btn_layout.addWidget(clear_btn)
layout.addLayout(btn_layout)
def refresh_list(self):
self.list.clear()
for c in self.manager.clients:
item = QListWidgetItem(c.name)
item.setData(Qt.UserRole, c.uid)
self.list.addItem(item)
def selected_client(self):
item = self.list.currentItem()
if not item:
return None
uid = item.data(Qt.UserRole)
return self.manager.get_by_uid(uid)
def add_client(self):
name = self.name_input.text().strip()
try:
weight_kg = float(self.weight.text())
height_cm = float(self.client_height.text())
age = int(self.age.text())
except ValueError:
QMessageBox.warning(self, "Input Error", "Please enter valid numbers.")
return
sex = self.sex.currentText()
if not name:
QMessageBox.warning(self, "Input Error", "Client name required.")
return
self.manager.add_client(name, weight_kg, height_cm, age, sex)
self.manager.save()
self.refresh_list()