-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweight_lifting.py
79 lines (62 loc) · 3.02 KB
/
weight_lifting.py
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
import pandas as pd
import numpy as np
from datetime import datetime
import os
WORKOUT_DATA_PATH = "weight_lifting_data.csv"
WORKOUT_PLAN_PATH = "workout_plan.csv"
NEW_WORKOUT_DATA_PATH = "new_workout_data.csv"
NEW_WORKOUT_PLAN_PATH = "new_workout_plan.csv"
WORKOUT_DATA_COLUMNS = ['Movement Name', 'Set Number', 'Weight', 'Reps', 'Date','Workout Name']
WORKOUT_PLAN_COLUMNS = ['Workout Name', 'Movement Name', 'Sets', 'Reps', 'Date', 'Notes']
class WorkoutData:
def __init__(self):
if not os.path.exists(WORKOUT_DATA_PATH) or not os.path.exists(WORKOUT_PLAN_PATH):
print('Please run __init__.py before creating a WorkoutData instance!')
return None
self.weight_lifting_data = pd.read_csv('weight_lifting_data.csv')
self.workout_plan = pd.read_csv('workout_plan.csv')
def get_weight_lifting_data(self):
return self.weight_lifting_data
def get_workout_plan(self):
return self.workout_plan
def generate_workout_template(self, workout_name):
workout_plan = self.workout_plan[self.workout_plan['Workout Name'] == workout_name]
num_rows = workout_plan['Sets'].sum()
columns = self.weight_lifting_data.columns
output = pd.DataFrame(index=range(num_rows), columns=columns)
ind = 0
for _, row in workout_plan.iterrows():
for s in range(row['Sets']):
output.iloc[ind] = [row['Movement Name'], s, None, None, datetime.now(), workout_name]
ind += 1
output.to_csv('new_workout_data.csv')
os.system("open new_workout_data.csv")
def create_new_workout(self):
output = pd.DataFrame(columns = ['Workout Name', 'Movement Name', 'Sets', 'Reps', 'Date', 'Notes'])
print(output.columns)
output.to_csv('new_workout_plan.csv', index = False)
os.system("open new_workout_plan.csv")
def upload_new_workout_plan(self):
new_plan = pd.read_csv(NEW_WORKOUT_PLAN_PATH)
self.workout_plan = pd.concat([self.workout_plan, new_plan])
self.workout_plan.to_csv(WORKOUT_PLAN_PATH, index=False)
self.reprocess_workout_plan()
print('Workout Uploaded!')
def create_new_workout_data(self):
output = pd.DataFrame(columns = self.weight_lifting_data.columns.tolist()[1:])
output.to_csv('new_workout_data.csv')
os.system("open new_workout_data.csv")
def upload_workout(self):
new_workout = pd.read_csv(NEW_WORKOUT_DATA_PATH)
self.weight_lifting_data = pd.concat([self.weight_lifting_data, new_workout])
self.weight_lifting_data.to_csv(WORKOUT_DATA_PATH)
self.reprocess_workout_data()
print('Workout Uploaded!')
def reprocess_workout_plan(self):
df = pd.read_csv(WORKOUT_PLAN_PATH)
df = df[WORKOUT_PLAN_COLUMNS]
df.to_csv('workout_plan.csv')
def reprocess_workout_data(self):
df = pd.read_csv(WORKOUT_DATA_PATH)
df = df[WORKOUT_DATA_COLUMNS]
df.to_csv('weight_lifting_data.csv')