-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_progress.py
70 lines (53 loc) · 1.84 KB
/
view_progress.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
# view_progress.py
import sqlite3
import matplotlib.pyplot as plt
from datetime import datetime
def fetch_progress(db_name='progress.db', exercise='Knee Exercise'):
"""
Fetch all progress records for a specific exercise from the database.
Parameters:
- db_name (str): Name of the SQLite database file.
- exercise (str): Name of the exercise to filter by.
Returns:
- list of tuples: Each tuple contains (date, exercise, repetitions, points).
"""
conn = sqlite3.connect(db_name)
c = conn.cursor()
c.execute("SELECT * FROM progress WHERE exercise = ?", (exercise,))
data = c.fetchall()
conn.close()
return data
def plot_progress(data, exercise='Knee Exercise'):
"""
Plot repetitions and points over time.
Parameters:
- data (list of tuples): Each tuple contains (date, exercise, repetitions, points).
- exercise (str): Name of the exercise for labeling.
"""
if not data:
print("No progress data available.")
return
dates = [datetime.strptime(record[0], "%Y-%m-%d %H:%M:%S") for record in data]
reps = [record[2] for record in data]
points = [record[3] for record in data]
plt.figure(figsize=(12, 6))
plt.subplot(1, 2, 1)
plt.plot(dates, reps, marker='o', linestyle='-')
plt.title(f'{exercise} Repetitions Over Time')
plt.xlabel('Date')
plt.ylabel('Repetitions')
plt.xticks(rotation=45)
plt.subplot(1, 2, 2)
plt.plot(dates, points, marker='o', color='orange', linestyle='-')
plt.title(f'{exercise} Points Over Time')
plt.xlabel('Date')
plt.ylabel('Points')
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
def main():
exercise = 'Knee Exercise' # Change as needed
data = fetch_progress(exercise=exercise)
plot_progress(data, exercise=exercise)
if __name__ == "__main__":
main()