Skip to content

Commit d31e149

Browse files
authored
Add files via upload
Upload files due to original forked repo being private.
0 parents  commit d31e149

27 files changed

+2493
-0
lines changed

DDL.sql

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
-- This file corresponds to the necessary CS340 Portfolio Project deliverables.
2+
3+
SET foreign_key_checks = 0;
4+
SET autocommit = 0;
5+
6+
-- Ensures clean import
7+
DROP TABLE IF EXISTS Users;
8+
DROP TABLE IF EXISTS WorkoutSessions;
9+
DROP TABLE IF EXISTS ListExercises;
10+
DROP TABLE IF EXISTS SessionExercises;
11+
DROP TABLE IF EXISTS Metrics;
12+
13+
-- User table that stores platform users
14+
CREATE TABLE Users (
15+
user_id INT PRIMARY KEY AUTO_INCREMENT,
16+
username VARCHAR(255) NOT NULL UNIQUE,
17+
contact VARCHAR(15) NOT NULL UNIQUE
18+
);
19+
20+
-- Log specific workout session
21+
CREATE TABLE WorkoutSessions (
22+
workout_session_id INT PRIMARY KEY AUTO_INCREMENT,
23+
user_id INT NOT NULL,
24+
workout_date DATETIME NOT NULL,
25+
duration_minutes INT NOT NULL,
26+
notes CHAR(255),
27+
-- Foreign key links user_id in WorkoutSessions to the primary key in Users.
28+
-- This ensures that each workout session is associated with a valid user.
29+
FOREIGN KEY (user_id) REFERENCES Users(user_id) ON DELETE CASCADE
30+
);
31+
32+
-- Exercise table to store various exercises that can be added to a workout
33+
CREATE TABLE ListExercises (
34+
exercise_id INT PRIMARY KEY AUTO_INCREMENT,
35+
name CHAR(255) NOT NULL,
36+
description CHAR(255),
37+
category CHAR(255) NOT NULL
38+
);
39+
40+
-- Stores exercises performed in a specific workout
41+
CREATE TABLE SessionExercises (
42+
session_exercise_id INT PRIMARY KEY AUTO_INCREMENT,
43+
workout_session_id INT NOT NULL,
44+
exercise_id INT NULL,
45+
sets INT NOT NULL,
46+
reps INT NOT NULL,
47+
weight INT,
48+
-- Foreign key links workout_session_id to WorkoutSessions, enforcing that each
49+
-- entry in SessionExercises is tied to an existing workout session.
50+
FOREIGN KEY (workout_session_id) REFERENCES WorkoutSessions(workout_session_id) ON DELETE CASCADE,
51+
-- Foreign key links exercise_id to ListExercises, ensuring exercises performed
52+
-- in each session are valid and listed in ListExercises.
53+
FOREIGN KEY (exercise_id) REFERENCES ListExercises(exercise_id) ON DELETE CASCADE
54+
);
55+
56+
-- Store various metrics for a user's progress
57+
CREATE TABLE Metrics (
58+
metric_id INT PRIMARY KEY AUTO_INCREMENT,
59+
user_id INT NOT NULL,
60+
metric_type VARCHAR(255) NOT NULL,
61+
value DECIMAL(10, 2) NOT NULL,
62+
date_recorded TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
63+
-- Foreign key links user_id in Metrics to Users, ensuring each metric is tied
64+
-- to a valid user, so deleted users have their metrics automatically removed.
65+
FOREIGN KEY (user_id) REFERENCES Users(user_id) ON DELETE CASCADE
66+
);
67+
68+
-- Populate Users table with sample data
69+
INSERT INTO Users (username, contact)
70+
VALUES
71+
('kangjoo', 1234567890),
72+
('hinsonj', 1234567891),
73+
('tanalexis', 1234567892);
74+
75+
-- Populate WorkoutSessions table with sample data
76+
INSERT INTO WorkoutSessions (user_id, workout_date, duration_minutes, notes)
77+
VALUES
78+
((SELECT user_id FROM Users WHERE username = 'kangjoo'), '2024-11-01 08:00:00', 60, 'Morning workout, low intensity, form focused'),
79+
((SELECT user_id FROM Users WHERE username = 'hinsonj'), '2024-11-02 09:00:00', 45, NULL),
80+
((SELECT user_id FROM Users WHERE username = 'tanalexis'), '2024-11-03 12:00:00', 30, 'Quick session, high intensity');
81+
82+
-- Populate ListExercises table with sample data
83+
INSERT INTO ListExercises (name, description, category)
84+
VALUES
85+
('Push Up', 'https://www.youtube.com/watch?v=IODxDxX7oi4', 'Strength'),
86+
('Squat', 'https://www.youtube.com/watch?v=byxWus7BwfQ', 'Strength'),
87+
('Running', 'https://www.youtube.com/watch?v=brFHyOtTwH4', 'Cardio');
88+
89+
-- Populate SessionExercises table with sample data
90+
INSERT INTO SessionExercises (workout_session_id, exercise_id, sets, reps, weight)
91+
VALUES
92+
((SELECT workout_session_id FROM WorkoutSessions WHERE notes LIKE '%Morning workout%'),
93+
(SELECT exercise_id FROM ListExercises WHERE name = 'Push Up'), 3, 25, NULL),
94+
((SELECT workout_session_id FROM WorkoutSessions WHERE notes LIKE '%Quick session%'),
95+
(SELECT exercise_id FROM ListExercises WHERE name = 'Running'), 1, 0, NULL),
96+
((SELECT workout_session_id FROM WorkoutSessions WHERE notes IS NULL),
97+
(SELECT exercise_id FROM ListExercises WHERE name = 'Squat'), 4, 10, 250);
98+
99+
-- Populate Metrics table with sample data
100+
INSERT INTO Metrics (user_id, metric_type, value, date_recorded)
101+
VALUES
102+
((SELECT user_id FROM Users WHERE username = 'kangjoo'), 'Body Weight', 180.5, '2024-01-05 08:00:00'),
103+
((SELECT user_id FROM Users WHERE username = 'hinsonj'), 'Personal Best', 200.0, '2024-01-05 08:00:00'),
104+
((SELECT user_id FROM Users WHERE username = 'tanalexis'), 'Body Weight', 150.5, '2024-01-06 08:00:00');
105+
106+
SET foreign_key_checks = 1;
107+
set autocommit = 1;
108+
109+
COMMIT;

DML.sql

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
-- This file corresponds to the necessary CS340 Portfolio Project deliverables.
2+
3+
SET FOREIGN_KEY_CHECKS=0;
4+
SET AUTOCOMMIT = 0;
5+
6+
-- CREATE --------------------------------------------------------------------------------------------------------------
7+
8+
-- Insert a new user
9+
-- Ex: ('john_doe', 1234567890)
10+
INSERT INTO Users (username, contact)
11+
VALUES (:username, :contact);
12+
13+
-- Add a new workout session for a specific user
14+
-- Ex: ('kangjoo', '2025-01-01', 60, 'Chest day')
15+
INSERT INTO WorkoutSessions (user_id, workout_date, duration_minutes, notes)
16+
VALUES (
17+
(SELECT user_id FROM Users WHERE username = :username),
18+
:workout_date, :duration_minutes, :notes
19+
);
20+
21+
-- Add a new exercise to the list of exercises
22+
-- Ex: ('Bench Press', 'Lift barbell off chest', 'Strength')
23+
INSERT INTO ListExercises (name, description, category)
24+
VALUES (:exercise_name, :exercise_description, :exercise_category);
25+
26+
-- Record an exercise in a specific workout session
27+
-- Ex: ('kangjoo', 'Bench Press', 3, 10, 135)
28+
INSERT INTO SessionExercises (workout_session_id, exercise_id, sets, reps, weight)
29+
VALUES (
30+
(SELECT workout_session_id FROM WorkoutSessions WHERE workout_session_id = :workout_session_id),
31+
COALESCE ((SELECT exercise_id FROM ListExercises WHERE name = :exercise_name) NULL),
32+
:sets, :reps, :weight
33+
);
34+
35+
-- Log a new metric for a user
36+
-- Ex: ('kangjoo', 'Weight', 180, '2025-01-01')
37+
INSERT INTO Metrics (user_id, metric_type, value, date_recorded)
38+
VALUES (
39+
(SELECT user_id FROM Users WHERE username = :username),
40+
:metric_type, :metric_value, :metric_date_recorded
41+
);
42+
43+
44+
-- READ ---------------------------------------------------------------------------------------------------------------
45+
46+
-- Fetch all user details
47+
-- Ex: ('john_doe')
48+
SELECT user_id, username, contact
49+
FROM Users
50+
WHERE username = :username;
51+
52+
-- Get all workout sessions for a specific user
53+
-- Ex: ('kangjoo')
54+
SELECT
55+
WorkoutSessions.workout_session_id, WorkoutSessions.workout_date, WorkoutSessions.duration_minutes, WorkoutSessions.notes
56+
FROM
57+
WorkoutSessions
58+
JOIN
59+
Users ON WorkoutSessions.user_id = Users.user_id
60+
WHERE
61+
Users.username = :username
62+
ORDER BY
63+
WorkoutSessions.workout_date DESC;
64+
65+
-- Fetch all exercises in a given workout session
66+
-- Ex: (12)
67+
SELECT
68+
SessionExercises.session_exercise_id, ListExercises.name AS exercise_name, SessionExercises.sets, SessionExercises.reps, SessionExercises.weight
69+
FROM
70+
SessionExercises
71+
JOIN
72+
ListExercises ON SessionExercises.exercise_id = ListExercises.exercise_id
73+
WHERE
74+
SessionExercises.workout_session_id = :workout_session_id;
75+
76+
-- Get all exercises from the exercise list
77+
SELECT exercise_id, name, description, category
78+
FROM ListExercises
79+
ORDER BY name;
80+
81+
-- Get all metrics for a specific user
82+
-- Ex: ('kangjoo')
83+
SELECT
84+
Metrics.metric_id, Metrics.metric_type, Metrics.value, Metrics.date_recorded
85+
FROM
86+
Metrics
87+
WHERE
88+
Metrics.user_id = (SELECT user_id FROM Users WHERE username = :username)
89+
ORDER BY
90+
Metrics.date_recorded DESC;
91+
92+
93+
-- UPDATE --------------------------------------------------------------------------------------------------------------
94+
95+
-- Update user's contact information
96+
-- Ex: ('john_doe', 912012020)
97+
UPDATE Users
98+
SET contact = %s
99+
WHERE username = %s;
100+
101+
-- Update workout session details
102+
-- Ex: ('2025-01-01', 90, 'Updated notes', 11)
103+
UPDATE WorkoutSessions
104+
SET workout_date = %s, duration_minutes = %s, notes = %s
105+
WHERE workout_session_id = %s;
106+
107+
-- Update exercise details in the exercise list
108+
-- Ex: ('Bench Press', 'Updated description', 'Strength', 5)
109+
UPDATE ListExercises
110+
SET name = %s, description = %s, category = %s
111+
WHERE exercise_id = %s;
112+
113+
-- Update session exercise details for a specific workout session
114+
-- Ex: (3, 12, 145, 25)
115+
UPDATE SessionExercises
116+
SET sets = %s, reps = %s, weight = %s
117+
WHERE session_exercise_id = %s AND exercise_id = %s;
118+
119+
-- Update a specific metric for a user
120+
-- Ex: ('Weight', 185, '2025-02-01', 9)
121+
UPDATE Metrics
122+
SET metric_type = %s, value = %s, date_recorded = %s
123+
WHERE metric_id = %s;
124+
125+
126+
-- DELETE --------------------------------------------------------------------------------------------------------------
127+
128+
-- Delete a user by username
129+
-- Ex: ('john_doe')
130+
DELETE FROM Users
131+
WHERE username = :username;
132+
133+
-- Delete a specific workout session by session ID
134+
-- Ex: (11)
135+
DELETE FROM WorkoutSessions
136+
WHERE workout_session_id = :workout_session_id;
137+
138+
-- Delete an exercise from the exercise list by exercise ID
139+
-- Ex: (5)
140+
DELETE FROM ListExercises
141+
WHERE exercise_id = :exercise_id;
142+
143+
-- Delete a specific exercise from a workout session by session exercise ID
144+
-- Ex: (15)
145+
DELETE FROM SessionExercises
146+
WHERE session_exercise_id = :session_exercise_id AND exercise_id = :exercise_id;
147+
148+
-- Delete a specific metric by metric ID
149+
-- Ex: (9)
150+
DELETE FROM Metrics
151+
WHERE metric_id = :metric_id;
152+
153+
154+
SET FOREIGN_KEY_CHECKS=1;
155+
COMMIT;

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Workout Tracking System Project
2+
3+
Name(s): James Hinson and Joon Kang - Group 135
4+
5+
6+
7+
Course: CS340 - Introduction to Databases
8+
9+
Assignment: Project Step 6
10+
11+
Due Date: 12/9/2024
12+
13+
Description: Flask app for managing users, workout sessions, and exercises,
14+
with CRUD operations and MySQL database integration. Routes include
15+
user and session management, along with exercise tracking.
16+
17+
Citations: No citations, all code was original

__pycache__/app.cpython-39.pyc

14.4 KB
Binary file not shown.

__pycache__/config.cpython-39.pyc

630 Bytes
Binary file not shown.

__pycache__/wsgi.cpython-39.pyc

221 Bytes
Binary file not shown.

access.log

Whitespace-only changes.

0 commit comments

Comments
 (0)