diff --git a/data query and formatting.ipynb b/data query and formatting.ipynb new file mode 100644 index 0000000..6fa4a0e --- /dev/null +++ b/data query and formatting.ipynb @@ -0,0 +1,2487 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Goal is to display all workouts\n", + "#### * Query database\n", + "#### * Transform models into viewmodels\n", + "#### * Display data to user" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [], + "source": [ + "import sqlite3\n", + "import json\n", + "from datetime import datetime" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "DATABASE = 'workout.db'" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Define function to query database" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "def query_db(query, args=(), one=False):\n", + " conn = sqlite3.connect(DATABASE)\n", + " conn.row_factory = sqlite3.Row\n", + " cur = conn.execute(query, args)\n", + " rv = cur.fetchall()\n", + " conn.commit()\n", + " cur.close()\n", + " return (rv[0] if rv else None) if one else rv" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Query all workouts & topsets completed by Gabe(PersonId=1)" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "WorkoutId: 35, PersonId: 1 Person:Gabe, StartDate: 2022-01-13, TopSetId: 61, ExerciseId: 2, Exercise: Bench, Repetitions: 8, Weight: 50kg\n", + "WorkoutId: 36, PersonId: 1 Person:Gabe, StartDate: 2022-01-18, TopSetId: 62, ExerciseId: 1, Exercise: Squat, Repetitions: 7, Weight: 55kg\n", + "WorkoutId: 36, PersonId: 1 Person:Gabe, StartDate: 2022-01-18, TopSetId: 63, ExerciseId: 4, Exercise: Hotep, Repetitions: 4, Weight: 25kg\n", + "WorkoutId: 37, PersonId: 1 Person:Gabe, StartDate: 2022-02-08, TopSetId: 64, ExerciseId: 2, Exercise: Bench, Repetitions: 5, Weight: 55kg\n", + "WorkoutId: 37, PersonId: 1 Person:Gabe, StartDate: 2022-02-08, TopSetId: 65, ExerciseId: 3, Exercise: Deadlift, Repetitions: 6, Weight: 95kg\n", + "WorkoutId: 38, PersonId: 1 Person:Gabe, StartDate: 2022-02-15, TopSetId: 66, ExerciseId: 1, Exercise: Squat, Repetitions: 3, Weight: 65kg\n", + "WorkoutId: 38, PersonId: 1 Person:Gabe, StartDate: 2022-02-15, TopSetId: 67, ExerciseId: 4, Exercise: Hotep, Repetitions: 6, Weight: 25kg\n", + "WorkoutId: 39, PersonId: 1 Person:Gabe, StartDate: 2022-02-17, TopSetId: 68, ExerciseId: 2, Exercise: Bench, Repetitions: 2, Weight: 60kg\n", + "WorkoutId: 39, PersonId: 1 Person:Gabe, StartDate: 2022-02-17, TopSetId: 69, ExerciseId: 3, Exercise: Deadlift, Repetitions: 8, Weight: 105kg\n", + "WorkoutId: 40, PersonId: 1 Person:Gabe, StartDate: 2022-03-01, TopSetId: 70, ExerciseId: 1, Exercise: Squat, Repetitions: 3, Weight: 75kg\n", + "WorkoutId: 40, PersonId: 1 Person:Gabe, StartDate: 2022-03-01, TopSetId: 71, ExerciseId: 4, Exercise: Hotep, Repetitions: 4, Weight: 30kg\n", + "WorkoutId: 41, PersonId: 1 Person:Gabe, StartDate: 2022-03-10, TopSetId: 72, ExerciseId: 2, Exercise: Bench, Repetitions: 11, Weight: 50kg\n", + "WorkoutId: 42, PersonId: 1 Person:Gabe, StartDate: 2022-03-15, TopSetId: 73, ExerciseId: 1, Exercise: Squat, Repetitions: 5, Weight: 75kg\n", + "WorkoutId: 42, PersonId: 1 Person:Gabe, StartDate: 2022-03-15, TopSetId: 74, ExerciseId: 4, Exercise: Hotep, Repetitions: 5, Weight: 30kg\n", + "WorkoutId: 43, PersonId: 1 Person:Gabe, StartDate: 2022-03-22, TopSetId: 75, ExerciseId: 2, Exercise: Bench, Repetitions: 4, Weight: 60kg\n", + "WorkoutId: 43, PersonId: 1 Person:Gabe, StartDate: 2022-03-22, TopSetId: 76, ExerciseId: 3, Exercise: Deadlift, Repetitions: 4, Weight: 110kg\n", + "WorkoutId: 44, PersonId: 1 Person:Gabe, StartDate: 2022-04-07, TopSetId: 77, ExerciseId: 1, Exercise: Squat, Repetitions: 6, Weight: 75kg\n", + "WorkoutId: 44, PersonId: 1 Person:Gabe, StartDate: 2022-04-07, TopSetId: 78, ExerciseId: 4, Exercise: Hotep, Repetitions: 2, Weight: 35kg\n", + "WorkoutId: 45, PersonId: 1 Person:Gabe, StartDate: 2022-04-21, TopSetId: 79, ExerciseId: 2, Exercise: Bench, Repetitions: 10, Weight: 45kg\n", + "WorkoutId: 45, PersonId: 1 Person:Gabe, StartDate: 2022-04-21, TopSetId: 80, ExerciseId: 3, Exercise: Deadlift, Repetitions: 10, Weight: 100kg\n", + "WorkoutId: 46, PersonId: 1 Person:Gabe, StartDate: 2022-04-26, TopSetId: 81, ExerciseId: 1, Exercise: Squat, Repetitions: 3, Weight: 80kg\n", + "WorkoutId: 47, PersonId: 1 Person:Gabe, StartDate: 2022-04-28, TopSetId: 82, ExerciseId: 2, Exercise: Bench, Repetitions: 2, Weight: 60kg\n", + "WorkoutId: 47, PersonId: 1 Person:Gabe, StartDate: 2022-04-28, TopSetId: 83, ExerciseId: 3, Exercise: Deadlift, Repetitions: 5, Weight: 100kg\n", + "WorkoutId: 48, PersonId: 1 Person:Gabe, StartDate: 2022-05-03, TopSetId: 84, ExerciseId: 2, Exercise: Bench, Repetitions: 4, Weight: 55kg\n", + "WorkoutId: 48, PersonId: 1 Person:Gabe, StartDate: 2022-05-03, TopSetId: 85, ExerciseId: 3, Exercise: Deadlift, Repetitions: 7, Weight: 95kg\n", + "WorkoutId: 49, PersonId: 1 Person:Gabe, StartDate: 2022-05-05, TopSetId: 86, ExerciseId: 2, Exercise: Bench, Repetitions: 4, Weight: 55kg\n", + "WorkoutId: 49, PersonId: 1 Person:Gabe, StartDate: 2022-05-05, TopSetId: 87, ExerciseId: 3, Exercise: Deadlift, Repetitions: 7, Weight: 110kg\n", + "WorkoutId: 50, PersonId: 1 Person:Gabe, StartDate: 2022-05-17, TopSetId: 88, ExerciseId: 1, Exercise: Squat, Repetitions: 3, Weight: 60kg\n", + "WorkoutId: 50, PersonId: 1 Person:Gabe, StartDate: 2022-05-17, TopSetId: 89, ExerciseId: 4, Exercise: Hotep, Repetitions: 4, Weight: 27kg\n", + "WorkoutId: 51, PersonId: 1 Person:Gabe, StartDate: 2022-05-19, TopSetId: 90, ExerciseId: 2, Exercise: Bench, Repetitions: 1, Weight: 65kg\n", + "WorkoutId: 51, PersonId: 1 Person:Gabe, StartDate: 2022-05-19, TopSetId: 91, ExerciseId: 3, Exercise: Deadlift, Repetitions: 4, Weight: 125kg\n", + "WorkoutId: 52, PersonId: 1 Person:Gabe, StartDate: 2022-06-07, TopSetId: 92, ExerciseId: 2, Exercise: Bench, Repetitions: 4, Weight: 55kg\n", + "WorkoutId: 52, PersonId: 1 Person:Gabe, StartDate: 2022-06-07, TopSetId: 93, ExerciseId: 3, Exercise: Deadlift, Repetitions: 5, Weight: 100kg\n", + "WorkoutId: 53, PersonId: 1 Person:Gabe, StartDate: 2022-06-14, TopSetId: 94, ExerciseId: 1, Exercise: Squat, Repetitions: 2, Weight: 75kg\n", + "WorkoutId: 53, PersonId: 1 Person:Gabe, StartDate: 2022-06-14, TopSetId: 95, ExerciseId: 4, Exercise: Hotep, Repetitions: 4, Weight: 31kg\n", + "WorkoutId: 54, PersonId: 1 Person:Gabe, StartDate: 2022-06-29, TopSetId: 96, ExerciseId: 2, Exercise: Bench, Repetitions: 11, Weight: 40kg\n", + "WorkoutId: 55, PersonId: 1 Person:Gabe, StartDate: 2022-07-07, TopSetId: 97, ExerciseId: 1, Exercise: Squat, Repetitions: 5, Weight: 65kg\n", + "WorkoutId: 55, PersonId: 1 Person:Gabe, StartDate: 2022-07-07, TopSetId: 98, ExerciseId: 4, Exercise: Hotep, Repetitions: 6, Weight: 30kg\n", + "WorkoutId: 56, PersonId: 1 Person:Gabe, StartDate: 2022-07-12, TopSetId: 99, ExerciseId: 2, Exercise: Bench, Repetitions: 4, Weight: 60kg\n", + "WorkoutId: 56, PersonId: 1 Person:Gabe, StartDate: 2022-07-12, TopSetId: 100, ExerciseId: 3, Exercise: Deadlift, Repetitions: 9, Weight: 100kg\n", + "WorkoutId: 57, PersonId: 1 Person:Gabe, StartDate: 2022-07-15, TopSetId: 101, ExerciseId: 1, Exercise: Squat, Repetitions: 6, Weight: 75kg\n", + "WorkoutId: 57, PersonId: 1 Person:Gabe, StartDate: 2022-07-15, TopSetId: 102, ExerciseId: 4, Exercise: Hotep, Repetitions: 3, Weight: 35kg\n" + ] + } + ], + "source": [ + "topsets = query_db(\"\"\"\n", + " SELECT \n", + " P.PersonId, \n", + " P.Name AS PersonName, \n", + " W.WorkoutId, \n", + " W.StartDate, \n", + " T.TopSetId, \n", + " E.ExerciseId, \n", + " E.Name AS ExerciseName, \n", + " T.Repetitions, \n", + " T.Weight\n", + " FROM Person P\n", + " LEFT JOIN Workout W ON P.PersonId=W.PersonId\n", + " LEFT JOIN TopSet T ON W.WorkoutId=T.WorkoutId\n", + " LEFT JOIN Exercise E ON T.ExerciseId=E.ExerciseId\n", + " WHERE P.PersonId=?\"\"\", [1])\n", + "\n", + "for topset in topsets:\n", + " print(f'WorkoutId: {topset[\"WorkoutId\"]}, PersonId: {topset[\"PersonId\"]} Person:{topset[\"PersonName\"]}, StartDate: {topset[\"StartDate\"]}, TopSetId: {topset[\"TopSetId\"]}, ExerciseId: {topset[\"ExerciseId\"]}, Exercise: {topset[\"ExerciseName\"]}, Repetitions: {topset[\"Repetitions\"]}, Weight: {topset[\"Weight\"]}kg')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Transform entity to view model with the following schema\n", + "
\n",
+ "{ \"PersonId\": 1,\n",
+ " \"PersonName\": \"Gabe\", \n",
+ " \"Exercises\": [{\"ExerciseIs\": 1, \"ExerciseName\": \"Squat\"}, {\"ExerciseIs\": 2, \"ExerciseName\": \"Bench\"}] \n",
+ " \"Workouts\": [ \n",
+ " { \n",
+ " \"WorkoutId\": 1,\n",
+ " \"StartDate\": \"2022-06-29 00:00:00.000\", \n",
+ " \"TopSets\": [ \n",
+ " { \n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\", \n",
+ " \"Weight\": 80, \n",
+ " \"Repetitions\": 8 \n",
+ " }, \n",
+ " { \n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\", \n",
+ " \"Weight\": 60, \n",
+ " \"Repetitions\": 4 \n",
+ " } \n",
+ " ] \n",
+ " }, \n",
+ " {\n",
+ " \"WorkoutId\": 2,\n",
+ " \"StartDate\": \"2022-07-01 00:00:00.000\", \n",
+ " \"TopSets\": [ \n",
+ " { \n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\", \n",
+ " \"Weight\": 85, \n",
+ " \"Repetitions\": 4 \n",
+ " }, \n",
+ " { \n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\", \n",
+ " \"Weight\": 65, \n",
+ " \"Repetitions\": 5 \n",
+ " } \n",
+ " ] \n",
+ " } \n",
+ " ] \n",
+ "} \n",
+ ""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#### 1. Extract name from rows"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 37,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "'Gabe'"
+ ]
+ },
+ "execution_count": 37,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "def get_name(topsets):\n",
+ " return topsets[0]['PersonName']\n",
+ "\n",
+ "get_name(topsets)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "#### 2. Group rows into workouts using WorkoutId column"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def get_workouts(topsets):\n",
+ " # Get all unique workout_ids (No duplicates)\n",
+ " workout_ids = set([t['WorkoutId'] for t in topsets])\n",
+ "\n",
+ " # Group topsets into workouts\n",
+ " workouts = []\n",
+ " for workout_id in workout_ids:\n",
+ " topsets_in_workout = [t for t in topsets if t['WorkoutId'] == workout_id]\n",
+ " workouts.append({\n",
+ " 'WorkoutId': workout_id,\n",
+ " 'StartDate': topsets_in_workout[0]['StartDate'],\n",
+ " 'TopSets': [{\"TopSetId\": t['TopSetId'], \"ExerciseId\": t['ExerciseId'], \"ExerciseName\": t['ExerciseName'], \"Weight\": t['Weight'], \"Repetitions\": t['Repetitions'] } for t in topsets_in_workout]\n",
+ " })\n",
+ " return workouts"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "[\n",
+ " {\n",
+ " \"WorkoutId\": 35,\n",
+ " \"StartDate\": \"2022-01-13\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 61,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 50,\n",
+ " \"Repetitions\": 8\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 36,\n",
+ " \"StartDate\": \"2022-01-18\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 62,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 7\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 63,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 25,\n",
+ " \"Repetitions\": 4\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 37,\n",
+ " \"StartDate\": \"2022-02-08\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 64,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 5\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 65,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 95,\n",
+ " \"Repetitions\": 6\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 38,\n",
+ " \"StartDate\": \"2022-02-15\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 66,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 65,\n",
+ " \"Repetitions\": 3\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 67,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 25,\n",
+ " \"Repetitions\": 6\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 39,\n",
+ " \"StartDate\": \"2022-02-17\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 68,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 60,\n",
+ " \"Repetitions\": 2\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 69,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 105,\n",
+ " \"Repetitions\": 8\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 40,\n",
+ " \"StartDate\": \"2022-03-01\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 70,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 75,\n",
+ " \"Repetitions\": 3\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 71,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 30,\n",
+ " \"Repetitions\": 4\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 41,\n",
+ " \"StartDate\": \"2022-03-10\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 72,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 50,\n",
+ " \"Repetitions\": 11\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 42,\n",
+ " \"StartDate\": \"2022-03-15\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 73,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 75,\n",
+ " \"Repetitions\": 5\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 74,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 30,\n",
+ " \"Repetitions\": 5\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 43,\n",
+ " \"StartDate\": \"2022-03-22\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 75,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 60,\n",
+ " \"Repetitions\": 4\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 76,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 110,\n",
+ " \"Repetitions\": 4\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 44,\n",
+ " \"StartDate\": \"2022-04-07\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 77,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 75,\n",
+ " \"Repetitions\": 6\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 78,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 35,\n",
+ " \"Repetitions\": 2\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 45,\n",
+ " \"StartDate\": \"2022-04-21\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 79,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 45,\n",
+ " \"Repetitions\": 10\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 80,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 100,\n",
+ " \"Repetitions\": 10\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 46,\n",
+ " \"StartDate\": \"2022-04-26\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 81,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 80,\n",
+ " \"Repetitions\": 3\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 47,\n",
+ " \"StartDate\": \"2022-04-28\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 82,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 60,\n",
+ " \"Repetitions\": 2\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 83,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 100,\n",
+ " \"Repetitions\": 5\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 48,\n",
+ " \"StartDate\": \"2022-05-03\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 84,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 4\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 85,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 95,\n",
+ " \"Repetitions\": 7\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 49,\n",
+ " \"StartDate\": \"2022-05-05\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 86,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 4\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 87,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 110,\n",
+ " \"Repetitions\": 7\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 50,\n",
+ " \"StartDate\": \"2022-05-17\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 88,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 60,\n",
+ " \"Repetitions\": 3\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 89,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 27,\n",
+ " \"Repetitions\": 4\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 51,\n",
+ " \"StartDate\": \"2022-05-19\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 90,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 65,\n",
+ " \"Repetitions\": 1\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 91,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 125,\n",
+ " \"Repetitions\": 4\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 52,\n",
+ " \"StartDate\": \"2022-06-07\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 92,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 4\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 93,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 100,\n",
+ " \"Repetitions\": 5\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 53,\n",
+ " \"StartDate\": \"2022-06-14\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 94,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 75,\n",
+ " \"Repetitions\": 2\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 95,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 31,\n",
+ " \"Repetitions\": 4\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 54,\n",
+ " \"StartDate\": \"2022-06-29\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 96,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 40,\n",
+ " \"Repetitions\": 11\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 55,\n",
+ " \"StartDate\": \"2022-07-07\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 97,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 65,\n",
+ " \"Repetitions\": 5\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 98,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 30,\n",
+ " \"Repetitions\": 6\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 56,\n",
+ " \"StartDate\": \"2022-07-12\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 99,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 60,\n",
+ " \"Repetitions\": 4\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 100,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 100,\n",
+ " \"Repetitions\": 9\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 57,\n",
+ " \"StartDate\": \"2022-07-15\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 101,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 75,\n",
+ " \"Repetitions\": 6\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 102,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 35,\n",
+ " \"Repetitions\": 3\n",
+ " }\n",
+ " ]\n",
+ " }\n",
+ "]\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(json.dumps(get_workouts(topsets), indent=2))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[{'ExerciseId': 1, 'ExerciseName': 'Squat'},\n",
+ " {'ExerciseId': 2, 'ExerciseName': 'Bench'},\n",
+ " {'ExerciseId': 3, 'ExerciseName': 'Deadlift'},\n",
+ " {'ExerciseId': 4, 'ExerciseName': 'Hotep'}]"
+ ]
+ },
+ "execution_count": 17,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "def get_all_exercises_from_topsets(topsets):\n",
+ " exercise_ids = set([t['ExerciseId'] for t in topsets])\n",
+ " exercises = []\n",
+ " for exercise_id in exercise_ids:\n",
+ " exercises.append({\n",
+ " 'ExerciseId': exercise_id,\n",
+ " 'ExerciseName': next((t['ExerciseName'] for t in topsets if t['ExerciseId'] == exercise_id), 'Unknown')\n",
+ " })\n",
+ " return exercises\n",
+ "\n",
+ "get_all_exercises_from_topsets(topsets)\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### 3. Compose functions together to acheive final model"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def convert_to_view_model(topsets):\n",
+ " return {\n",
+ " 'PersonId': next((t['PersonId'] for t in topsets), -1),\n",
+ " 'PersonName': next((t['PersonName'] for t in topsets), -1),\n",
+ " 'Exercises': get_all_exercises_from_topsets(topsets),\n",
+ " 'Workouts': get_workouts(topsets)\n",
+ " }"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "{\n",
+ " \"PersonId\": 1,\n",
+ " \"PersonName\": \"Gabe\",\n",
+ " \"Exercises\": [\n",
+ " {\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\"\n",
+ " },\n",
+ " {\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\"\n",
+ " },\n",
+ " {\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\"\n",
+ " },\n",
+ " {\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\"\n",
+ " }\n",
+ " ],\n",
+ " \"Workouts\": [\n",
+ " {\n",
+ " \"WorkoutId\": 35,\n",
+ " \"StartDate\": \"2022-01-13\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 61,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 50,\n",
+ " \"Repetitions\": 8\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 36,\n",
+ " \"StartDate\": \"2022-01-18\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 62,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 7\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 63,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 25,\n",
+ " \"Repetitions\": 4\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 37,\n",
+ " \"StartDate\": \"2022-02-08\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 64,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 5\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 65,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 95,\n",
+ " \"Repetitions\": 6\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 38,\n",
+ " \"StartDate\": \"2022-02-15\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 66,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 65,\n",
+ " \"Repetitions\": 3\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 67,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 25,\n",
+ " \"Repetitions\": 6\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 39,\n",
+ " \"StartDate\": \"2022-02-17\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 68,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 60,\n",
+ " \"Repetitions\": 2\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 69,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 105,\n",
+ " \"Repetitions\": 8\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 40,\n",
+ " \"StartDate\": \"2022-03-01\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 70,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 75,\n",
+ " \"Repetitions\": 3\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 71,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 30,\n",
+ " \"Repetitions\": 4\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 41,\n",
+ " \"StartDate\": \"2022-03-10\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 72,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 50,\n",
+ " \"Repetitions\": 11\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 42,\n",
+ " \"StartDate\": \"2022-03-15\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 73,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 75,\n",
+ " \"Repetitions\": 5\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 74,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 30,\n",
+ " \"Repetitions\": 5\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 43,\n",
+ " \"StartDate\": \"2022-03-22\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 75,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 60,\n",
+ " \"Repetitions\": 4\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 76,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 110,\n",
+ " \"Repetitions\": 4\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 44,\n",
+ " \"StartDate\": \"2022-04-07\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 77,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 75,\n",
+ " \"Repetitions\": 6\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 78,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 35,\n",
+ " \"Repetitions\": 2\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 45,\n",
+ " \"StartDate\": \"2022-04-21\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 79,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 45,\n",
+ " \"Repetitions\": 10\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 80,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 100,\n",
+ " \"Repetitions\": 10\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 46,\n",
+ " \"StartDate\": \"2022-04-26\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 81,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 80,\n",
+ " \"Repetitions\": 3\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 47,\n",
+ " \"StartDate\": \"2022-04-28\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 82,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 60,\n",
+ " \"Repetitions\": 2\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 83,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 100,\n",
+ " \"Repetitions\": 5\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 48,\n",
+ " \"StartDate\": \"2022-05-03\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 84,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 4\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 85,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 95,\n",
+ " \"Repetitions\": 7\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 49,\n",
+ " \"StartDate\": \"2022-05-05\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 86,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 4\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 87,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 110,\n",
+ " \"Repetitions\": 7\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 50,\n",
+ " \"StartDate\": \"2022-05-17\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 88,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 60,\n",
+ " \"Repetitions\": 3\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 89,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 27,\n",
+ " \"Repetitions\": 4\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 51,\n",
+ " \"StartDate\": \"2022-05-19\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 90,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 65,\n",
+ " \"Repetitions\": 1\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 91,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 125,\n",
+ " \"Repetitions\": 4\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 52,\n",
+ " \"StartDate\": \"2022-06-07\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 92,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 4\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 93,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 100,\n",
+ " \"Repetitions\": 5\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 53,\n",
+ " \"StartDate\": \"2022-06-14\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 94,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 75,\n",
+ " \"Repetitions\": 2\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 95,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 31,\n",
+ " \"Repetitions\": 4\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 54,\n",
+ " \"StartDate\": \"2022-06-29\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 96,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 40,\n",
+ " \"Repetitions\": 11\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 55,\n",
+ " \"StartDate\": \"2022-07-07\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 97,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 65,\n",
+ " \"Repetitions\": 5\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 98,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 30,\n",
+ " \"Repetitions\": 6\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 56,\n",
+ " \"StartDate\": \"2022-07-12\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 99,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 60,\n",
+ " \"Repetitions\": 4\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 100,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 100,\n",
+ " \"Repetitions\": 9\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 57,\n",
+ " \"StartDate\": \"2022-07-15\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 101,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 75,\n",
+ " \"Repetitions\": 6\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 102,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 35,\n",
+ " \"Repetitions\": 3\n",
+ " }\n",
+ " ]\n",
+ " }\n",
+ " ]\n",
+ "}\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(json.dumps(convert_to_view_model(topsets), indent=2))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Dashboard page"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "all_topsets =query_db(\"\"\"\n",
+ " SELECT \n",
+ " P.PersonId, \n",
+ " P.Name AS PersonName, \n",
+ " W.WorkoutId, \n",
+ " W.StartDate, \n",
+ " T.TopSetId, \n",
+ " E.ExerciseId, \n",
+ " E.Name AS ExerciseName, \n",
+ " T.Repetitions, \n",
+ " T.Weight\n",
+ " FROM Person P\n",
+ " LEFT JOIN Workout W ON P.PersonId=W.PersonId\n",
+ " LEFT JOIN TopSet T ON W.WorkoutId=T.WorkoutId\n",
+ " LEFT JOIN Exercise E ON T.ExerciseId=E.ExerciseId\"\"\")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def get_people(topsets):\n",
+ " # Get all unique workout_ids (No duplicates)\n",
+ " people_ids = set([t['PersonId'] for t in topsets])\n",
+ "\n",
+ " # Group topsets into workouts\n",
+ " people = []\n",
+ " for person_id in people_ids:\n",
+ " workouts_for_person = [t for t in topsets if t['PersonId'] == person_id]\n",
+ " people.append({\n",
+ " 'PersonId': person_id,\n",
+ " 'PersonName': workouts_for_person[0]['PersonName'],\n",
+ " 'Workouts': get_workouts(workouts_for_person)\n",
+ " })\n",
+ " return people"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 24,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "[\n",
+ " {\n",
+ " \"PersonId\": 1,\n",
+ " \"PersonName\": \"Gabe\",\n",
+ " \"Workouts\": [\n",
+ " {\n",
+ " \"WorkoutId\": 35,\n",
+ " \"StartDate\": \"2022-01-13\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 61,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 50,\n",
+ " \"Repetitions\": 8\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 36,\n",
+ " \"StartDate\": \"2022-01-18\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 62,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 7\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 63,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 25,\n",
+ " \"Repetitions\": 4\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 37,\n",
+ " \"StartDate\": \"2022-02-08\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 64,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 5\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 65,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 95,\n",
+ " \"Repetitions\": 6\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 38,\n",
+ " \"StartDate\": \"2022-02-15\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 66,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 65,\n",
+ " \"Repetitions\": 3\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 67,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 25,\n",
+ " \"Repetitions\": 6\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 39,\n",
+ " \"StartDate\": \"2022-02-17\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 68,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 60,\n",
+ " \"Repetitions\": 2\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 69,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 105,\n",
+ " \"Repetitions\": 8\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 40,\n",
+ " \"StartDate\": \"2022-03-01\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 70,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 75,\n",
+ " \"Repetitions\": 3\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 71,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 30,\n",
+ " \"Repetitions\": 4\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 41,\n",
+ " \"StartDate\": \"2022-03-10\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 72,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 50,\n",
+ " \"Repetitions\": 11\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 42,\n",
+ " \"StartDate\": \"2022-03-15\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 73,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 75,\n",
+ " \"Repetitions\": 5\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 74,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 30,\n",
+ " \"Repetitions\": 5\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 43,\n",
+ " \"StartDate\": \"2022-03-22\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 75,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 60,\n",
+ " \"Repetitions\": 4\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 76,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 110,\n",
+ " \"Repetitions\": 4\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 44,\n",
+ " \"StartDate\": \"2022-04-07\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 77,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 75,\n",
+ " \"Repetitions\": 6\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 78,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 35,\n",
+ " \"Repetitions\": 2\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 45,\n",
+ " \"StartDate\": \"2022-04-21\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 79,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 45,\n",
+ " \"Repetitions\": 10\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 80,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 100,\n",
+ " \"Repetitions\": 10\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 46,\n",
+ " \"StartDate\": \"2022-04-26\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 81,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 80,\n",
+ " \"Repetitions\": 3\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 47,\n",
+ " \"StartDate\": \"2022-04-28\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 82,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 60,\n",
+ " \"Repetitions\": 2\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 83,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 100,\n",
+ " \"Repetitions\": 5\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 48,\n",
+ " \"StartDate\": \"2022-05-03\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 84,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 4\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 85,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 95,\n",
+ " \"Repetitions\": 7\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 49,\n",
+ " \"StartDate\": \"2022-05-05\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 86,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 4\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 87,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 110,\n",
+ " \"Repetitions\": 7\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 50,\n",
+ " \"StartDate\": \"2022-05-17\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 88,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 60,\n",
+ " \"Repetitions\": 3\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 89,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 27,\n",
+ " \"Repetitions\": 4\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 51,\n",
+ " \"StartDate\": \"2022-05-19\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 90,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 65,\n",
+ " \"Repetitions\": 1\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 91,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 125,\n",
+ " \"Repetitions\": 4\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 52,\n",
+ " \"StartDate\": \"2022-06-07\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 92,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 4\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 93,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 100,\n",
+ " \"Repetitions\": 5\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 53,\n",
+ " \"StartDate\": \"2022-06-14\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 94,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 75,\n",
+ " \"Repetitions\": 2\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 95,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 31,\n",
+ " \"Repetitions\": 4\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 54,\n",
+ " \"StartDate\": \"2022-06-29\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 96,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 40,\n",
+ " \"Repetitions\": 11\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 55,\n",
+ " \"StartDate\": \"2022-07-07\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 97,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 65,\n",
+ " \"Repetitions\": 5\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 98,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 30,\n",
+ " \"Repetitions\": 6\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 56,\n",
+ " \"StartDate\": \"2022-07-12\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 99,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 60,\n",
+ " \"Repetitions\": 4\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 100,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 100,\n",
+ " \"Repetitions\": 9\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 57,\n",
+ " \"StartDate\": \"2022-07-15\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 101,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 75,\n",
+ " \"Repetitions\": 6\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 102,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 35,\n",
+ " \"Repetitions\": 3\n",
+ " }\n",
+ " ]\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"PersonId\": 2,\n",
+ " \"PersonName\": \"Michael\",\n",
+ " \"Workouts\": [\n",
+ " {\n",
+ " \"WorkoutId\": 10,\n",
+ " \"StartDate\": \"2022-01-13\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 13,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 45,\n",
+ " \"Repetitions\": 7\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 14,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 115,\n",
+ " \"Repetitions\": 5\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 11,\n",
+ " \"StartDate\": \"2022-01-18\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 15,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 10\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 16,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 30,\n",
+ " \"Repetitions\": 10\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 12,\n",
+ " \"StartDate\": \"2022-01-20\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 17,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 50,\n",
+ " \"Repetitions\": 3\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 18,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 115,\n",
+ " \"Repetitions\": 10\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 13,\n",
+ " \"StartDate\": \"2022-01-25\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 19,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 6,\n",
+ " \"Repetitions\": 65\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 20,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 35,\n",
+ " \"Repetitions\": 7\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 15,\n",
+ " \"StartDate\": \"2022-01-27\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 21,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 1\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 22,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 125,\n",
+ " \"Repetitions\": 5\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 16,\n",
+ " \"StartDate\": \"2022-02-01\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 23,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 75,\n",
+ " \"Repetitions\": 5\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 24,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 40,\n",
+ " \"Repetitions\": 5\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 17,\n",
+ " \"StartDate\": \"2022-02-03\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 25,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 2\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 26,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 135,\n",
+ " \"Repetitions\": 3\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 18,\n",
+ " \"StartDate\": \"2022-02-08\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 27,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 80,\n",
+ " \"Repetitions\": 2\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 28,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 50,\n",
+ " \"Repetitions\": 3\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 19,\n",
+ " \"StartDate\": \"2022-02-15\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 29,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 80,\n",
+ " \"Repetitions\": 5\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 30,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 45,\n",
+ " \"Repetitions\": 3\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 20,\n",
+ " \"StartDate\": \"2022-02-17\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 31,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 60,\n",
+ " \"Repetitions\": 1\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 32,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 150,\n",
+ " \"Repetitions\": 2\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 21,\n",
+ " \"StartDate\": \"2022-03-01\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 33,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 75,\n",
+ " \"Repetitions\": 7\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 34,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 45,\n",
+ " \"Repetitions\": 4\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 22,\n",
+ " \"StartDate\": \"2022-03-10\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 35,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 45,\n",
+ " \"Repetitions\": 10\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 36,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 100,\n",
+ " \"Repetitions\": 10\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 23,\n",
+ " \"StartDate\": \"2022-03-15\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 37,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 2\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 38,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 120,\n",
+ " \"Repetitions\": 2\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 24,\n",
+ " \"StartDate\": \"2022-03-22\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 39,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 60,\n",
+ " \"Repetitions\": 5\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 40,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 40,\n",
+ " \"Repetitions\": 5\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 25,\n",
+ " \"StartDate\": \"2022-04-12\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 41,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 1\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 42,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 130,\n",
+ " \"Repetitions\": 1\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 26,\n",
+ " \"StartDate\": \"2022-04-21\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 43,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 60,\n",
+ " \"Repetitions\": 4\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 44,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 50,\n",
+ " \"Repetitions\": 3\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 27,\n",
+ " \"StartDate\": \"2022-04-26\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 45,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 2\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 46,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 125,\n",
+ " \"Repetitions\": 1\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 28,\n",
+ " \"StartDate\": \"2022-04-28\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 47,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 80,\n",
+ " \"Repetitions\": 2\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 48,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 42,\n",
+ " \"Repetitions\": 2\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 29,\n",
+ " \"StartDate\": \"2022-05-03\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 49,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 47,\n",
+ " \"Repetitions\": 3\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 50,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 130,\n",
+ " \"Repetitions\": 2\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 30,\n",
+ " \"StartDate\": \"2022-05-05\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 51,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 80,\n",
+ " \"Repetitions\": 5\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 52,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 44,\n",
+ " \"Repetitions\": 4\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 31,\n",
+ " \"StartDate\": \"2022-05-17\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 53,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 3\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 54,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 140,\n",
+ " \"Repetitions\": 2\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 32,\n",
+ " \"StartDate\": \"2022-05-19\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 55,\n",
+ " \"ExerciseId\": 2,\n",
+ " \"ExerciseName\": \"Bench\",\n",
+ " \"Weight\": 55,\n",
+ " \"Repetitions\": 2\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 56,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 100,\n",
+ " \"Repetitions\": 5\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 33,\n",
+ " \"StartDate\": \"2022-06-07\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 57,\n",
+ " \"ExerciseId\": 1,\n",
+ " \"ExerciseName\": \"Squat\",\n",
+ " \"Weight\": 85,\n",
+ " \"Repetitions\": 3\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 58,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 45,\n",
+ " \"Repetitions\": 5\n",
+ " }\n",
+ " ]\n",
+ " },\n",
+ " {\n",
+ " \"WorkoutId\": 34,\n",
+ " \"StartDate\": \"2022-06-14\",\n",
+ " \"TopSets\": [\n",
+ " {\n",
+ " \"TopSetId\": 59,\n",
+ " \"ExerciseId\": 3,\n",
+ " \"ExerciseName\": \"Deadlift\",\n",
+ " \"Weight\": 120,\n",
+ " \"Repetitions\": 6\n",
+ " },\n",
+ " {\n",
+ " \"TopSetId\": 60,\n",
+ " \"ExerciseId\": 4,\n",
+ " \"ExerciseName\": \"Hotep\",\n",
+ " \"Weight\": 45,\n",
+ " \"Repetitions\": 5\n",
+ " }\n",
+ " ]\n",
+ " }\n",
+ " ]\n",
+ " }\n",
+ "]\n"
+ ]
+ }
+ ],
+ "source": [
+ "print(json.dumps(get_people(all_topsets), indent=2))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "gabe_topsts = [t for t in topsets if t['PersonId'] == 1]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 63,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "gabe_exercises = get_all_exercises_from_topsets(gabe_topsts)\n",
+ "gabe_rep_maxes = []\n",
+ "for e in gabe_exercises:\n",
+ " exercise_topsets = [t for t in gabe_topsts if t['ExerciseId'] == e['ExerciseId']]\n",
+ " set_reps = set([t['Repetitions'] for t in exercise_topsets])\n",
+ "\n",
+ " topsets_for_exercise = []\n",
+ " for rep in set_reps:\n",
+ " reps = [t for t in exercise_topsets if t['Repetitions'] == rep]\n",
+ " max_weight = max([t['Weight'] for t in reps])\n",
+ " max_topset_for_rep = [t for t in reps if t['Weight'] == max_weight]\n",
+ " topsets_for_exercise.append({\n",
+ " 'StartDate': max_topset_for_rep[0]['StartDate'],\n",
+ " 'Repetitions': rep,\n",
+ " 'Weight': max_weight\n",
+ " })\n",
+ " \n",
+ " topsets_for_exercise.sort(key=lambda x: datetime.strptime(x['StartDate'],\"%Y-%m-%d\"))\n",
+ " \n",
+ " gabe_rep_maxes.append({\n",
+ " 'ExerciseId': e['ExerciseId'],\n",
+ " 'ExerciseName': e['ExerciseName'],\n",
+ " 'RepMaxes': topsets_for_exercise,\n",
+ " })"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 65,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def get_rep_maxes_for_person(person_topsets):\n",
+ " person_exercises = get_all_exercises_from_topsets(person_topsets)\n",
+ "\n",
+ " rep_maxes_in_exercises = []\n",
+ " for e in person_exercises:\n",
+ " exercise_topsets = [\n",
+ " t for t in person_topsets if t['ExerciseId'] == e['ExerciseId']]\n",
+ " set_reps = set([t['Repetitions'] for t in exercise_topsets])\n",
+ "\n",
+ " topsets_for_exercise = []\n",
+ " for rep in set_reps:\n",
+ " reps = [t for t in exercise_topsets if t['Repetitions'] == rep]\n",
+ " max_weight = max([t['Weight'] for t in reps])\n",
+ " max_topset_for_rep = [t for t in reps if t['Weight'] == max_weight]\n",
+ " topsets_for_exercise.append({\n",
+ " 'StartDate': max_topset_for_rep[0]['StartDate'],\n",
+ " 'Repetitions': rep,\n",
+ " 'Weight': max_weight\n",
+ " })\n",
+ "\n",
+ " topsets_for_exercise.sort(\n",
+ " key=lambda x: datetime.strptime(x['StartDate'], \"%Y-%m-%d\"))\n",
+ "\n",
+ " rep_maxes_in_exercises.append({\n",
+ " 'ExerciseId': e['ExerciseId'],\n",
+ " 'ExerciseName': e['ExerciseName'],\n",
+ " 'RepMaxes': topsets_for_exercise,\n",
+ " })\n",
+ " return rep_maxes_in_exercises\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 66,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[{'ExerciseId': 1,\n",
+ " 'ExerciseName': 'Squat',\n",
+ " 'RepMaxes': [{'StartDate': '2022-01-18', 'Repetitions': 7, 'Weight': 55},\n",
+ " {'StartDate': '2022-03-15', 'Repetitions': 5, 'Weight': 75},\n",
+ " {'StartDate': '2022-04-07', 'Repetitions': 6, 'Weight': 75},\n",
+ " {'StartDate': '2022-04-26', 'Repetitions': 3, 'Weight': 80},\n",
+ " {'StartDate': '2022-06-14', 'Repetitions': 2, 'Weight': 75}]},\n",
+ " {'ExerciseId': 2,\n",
+ " 'ExerciseName': 'Bench',\n",
+ " 'RepMaxes': [{'StartDate': '2022-01-13', 'Repetitions': 8, 'Weight': 50},\n",
+ " {'StartDate': '2022-02-08', 'Repetitions': 5, 'Weight': 55},\n",
+ " {'StartDate': '2022-02-17', 'Repetitions': 2, 'Weight': 60},\n",
+ " {'StartDate': '2022-03-10', 'Repetitions': 11, 'Weight': 50},\n",
+ " {'StartDate': '2022-03-22', 'Repetitions': 4, 'Weight': 60},\n",
+ " {'StartDate': '2022-04-21', 'Repetitions': 10, 'Weight': 45},\n",
+ " {'StartDate': '2022-05-19', 'Repetitions': 1, 'Weight': 65}]},\n",
+ " {'ExerciseId': 3,\n",
+ " 'ExerciseName': 'Deadlift',\n",
+ " 'RepMaxes': [{'StartDate': '2022-02-08', 'Repetitions': 6, 'Weight': 95},\n",
+ " {'StartDate': '2022-02-17', 'Repetitions': 8, 'Weight': 105},\n",
+ " {'StartDate': '2022-04-21', 'Repetitions': 10, 'Weight': 100},\n",
+ " {'StartDate': '2022-04-28', 'Repetitions': 5, 'Weight': 100},\n",
+ " {'StartDate': '2022-05-05', 'Repetitions': 7, 'Weight': 110},\n",
+ " {'StartDate': '2022-05-19', 'Repetitions': 4, 'Weight': 125},\n",
+ " {'StartDate': '2022-07-12', 'Repetitions': 9, 'Weight': 100}]},\n",
+ " {'ExerciseId': 4,\n",
+ " 'ExerciseName': 'Hotep',\n",
+ " 'RepMaxes': [{'StartDate': '2022-03-15', 'Repetitions': 5, 'Weight': 30},\n",
+ " {'StartDate': '2022-04-07', 'Repetitions': 2, 'Weight': 35},\n",
+ " {'StartDate': '2022-06-14', 'Repetitions': 4, 'Weight': 31},\n",
+ " {'StartDate': '2022-07-07', 'Repetitions': 6, 'Weight': 30},\n",
+ " {'StartDate': '2022-07-15', 'Repetitions': 3, 'Weight': 35}]}]"
+ ]
+ },
+ "execution_count": 66,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "get_rep_maxes_for_person(gabe_topsts)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 67,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "def get_people_and_exercise_rep_maxes(topsets):\n",
+ " # Get all unique workout_ids (No duplicates)\n",
+ " people_ids = set([t['PersonId'] for t in topsets])\n",
+ "\n",
+ " # Group topsets into workouts\n",
+ " people = []\n",
+ " for person_id in people_ids:\n",
+ " workouts_for_person = [t for t in topsets if t['PersonId'] == person_id]\n",
+ " people.append({\n",
+ " 'PersonId': person_id,\n",
+ " 'PersonName': workouts_for_person[0]['PersonName'],\n",
+ " 'Exercises': get_rep_maxes_for_person(workouts_for_person)\n",
+ " })\n",
+ " return people"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 69,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "[{'PersonId': 1,\n",
+ " 'PersonName': 'Gabe',\n",
+ " 'Exercises': [{'ExerciseId': 1,\n",
+ " 'ExerciseName': 'Squat',\n",
+ " 'RepMaxes': [{'StartDate': '2022-01-18', 'Repetitions': 7, 'Weight': 55},\n",
+ " {'StartDate': '2022-03-15', 'Repetitions': 5, 'Weight': 75},\n",
+ " {'StartDate': '2022-04-07', 'Repetitions': 6, 'Weight': 75},\n",
+ " {'StartDate': '2022-04-26', 'Repetitions': 3, 'Weight': 80},\n",
+ " {'StartDate': '2022-06-14', 'Repetitions': 2, 'Weight': 75}]},\n",
+ " {'ExerciseId': 2,\n",
+ " 'ExerciseName': 'Bench',\n",
+ " 'RepMaxes': [{'StartDate': '2022-01-13', 'Repetitions': 8, 'Weight': 50},\n",
+ " {'StartDate': '2022-02-08', 'Repetitions': 5, 'Weight': 55},\n",
+ " {'StartDate': '2022-02-17', 'Repetitions': 2, 'Weight': 60},\n",
+ " {'StartDate': '2022-03-10', 'Repetitions': 11, 'Weight': 50},\n",
+ " {'StartDate': '2022-03-22', 'Repetitions': 4, 'Weight': 60},\n",
+ " {'StartDate': '2022-04-21', 'Repetitions': 10, 'Weight': 45},\n",
+ " {'StartDate': '2022-05-19', 'Repetitions': 1, 'Weight': 65}]},\n",
+ " {'ExerciseId': 3,\n",
+ " 'ExerciseName': 'Deadlift',\n",
+ " 'RepMaxes': [{'StartDate': '2022-02-08', 'Repetitions': 6, 'Weight': 95},\n",
+ " {'StartDate': '2022-02-17', 'Repetitions': 8, 'Weight': 105},\n",
+ " {'StartDate': '2022-04-21', 'Repetitions': 10, 'Weight': 100},\n",
+ " {'StartDate': '2022-04-28', 'Repetitions': 5, 'Weight': 100},\n",
+ " {'StartDate': '2022-05-05', 'Repetitions': 7, 'Weight': 110},\n",
+ " {'StartDate': '2022-05-19', 'Repetitions': 4, 'Weight': 125},\n",
+ " {'StartDate': '2022-07-12', 'Repetitions': 9, 'Weight': 100}]},\n",
+ " {'ExerciseId': 4,\n",
+ " 'ExerciseName': 'Hotep',\n",
+ " 'RepMaxes': [{'StartDate': '2022-03-15', 'Repetitions': 5, 'Weight': 30},\n",
+ " {'StartDate': '2022-04-07', 'Repetitions': 2, 'Weight': 35},\n",
+ " {'StartDate': '2022-06-14', 'Repetitions': 4, 'Weight': 31},\n",
+ " {'StartDate': '2022-07-07', 'Repetitions': 6, 'Weight': 30},\n",
+ " {'StartDate': '2022-07-15', 'Repetitions': 3, 'Weight': 35}]}]},\n",
+ " {'PersonId': 2,\n",
+ " 'PersonName': 'Michael',\n",
+ " 'Exercises': [{'ExerciseId': 1,\n",
+ " 'ExerciseName': 'Squat',\n",
+ " 'RepMaxes': [{'StartDate': '2022-01-18', 'Repetitions': 10, 'Weight': 55},\n",
+ " {'StartDate': '2022-01-25', 'Repetitions': 65, 'Weight': 6},\n",
+ " {'StartDate': '2022-02-08', 'Repetitions': 2, 'Weight': 80},\n",
+ " {'StartDate': '2022-02-15', 'Repetitions': 5, 'Weight': 80},\n",
+ " {'StartDate': '2022-03-01', 'Repetitions': 7, 'Weight': 75},\n",
+ " {'StartDate': '2022-04-21', 'Repetitions': 4, 'Weight': 60},\n",
+ " {'StartDate': '2022-06-07', 'Repetitions': 3, 'Weight': 85}]},\n",
+ " {'ExerciseId': 2,\n",
+ " 'ExerciseName': 'Bench',\n",
+ " 'RepMaxes': [{'StartDate': '2022-01-13', 'Repetitions': 7, 'Weight': 45},\n",
+ " {'StartDate': '2022-02-03', 'Repetitions': 2, 'Weight': 55},\n",
+ " {'StartDate': '2022-02-17', 'Repetitions': 1, 'Weight': 60},\n",
+ " {'StartDate': '2022-03-10', 'Repetitions': 10, 'Weight': 45},\n",
+ " {'StartDate': '2022-03-22', 'Repetitions': 5, 'Weight': 40},\n",
+ " {'StartDate': '2022-05-17', 'Repetitions': 3, 'Weight': 55}]},\n",
+ " {'ExerciseId': 3,\n",
+ " 'ExerciseName': 'Deadlift',\n",
+ " 'RepMaxes': [{'StartDate': '2022-01-20', 'Repetitions': 10, 'Weight': 115},\n",
+ " {'StartDate': '2022-01-27', 'Repetitions': 5, 'Weight': 125},\n",
+ " {'StartDate': '2022-02-03', 'Repetitions': 3, 'Weight': 135},\n",
+ " {'StartDate': '2022-02-17', 'Repetitions': 2, 'Weight': 150},\n",
+ " {'StartDate': '2022-04-12', 'Repetitions': 1, 'Weight': 130},\n",
+ " {'StartDate': '2022-06-14', 'Repetitions': 6, 'Weight': 120}]},\n",
+ " {'ExerciseId': 4,\n",
+ " 'ExerciseName': 'Hotep',\n",
+ " 'RepMaxes': [{'StartDate': '2022-01-18', 'Repetitions': 10, 'Weight': 30},\n",
+ " {'StartDate': '2022-01-25', 'Repetitions': 7, 'Weight': 35},\n",
+ " {'StartDate': '2022-02-15', 'Repetitions': 3, 'Weight': 45},\n",
+ " {'StartDate': '2022-03-01', 'Repetitions': 4, 'Weight': 45},\n",
+ " {'StartDate': '2022-04-28', 'Repetitions': 2, 'Weight': 42},\n",
+ " {'StartDate': '2022-06-07', 'Repetitions': 5, 'Weight': 45}]}]}]"
+ ]
+ },
+ "execution_count": 69,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "get_people_and_exercise_rep_maxes(all_topsets)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3.9.6 64-bit",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.9.6"
+ },
+ "orig_nbformat": 4,
+ "vscode": {
+ "interpreter": {
+ "hash": "63076e477759601ac1c90dd52b6ecb6aedfcfea91f89ed7c8d6b0b077f7912d7"
+ }
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}