Refactor dashboard
This commit is contained in:
35
db.py
35
db.py
@@ -13,7 +13,8 @@ from features.person_overview import PersonOverview
|
||||
from features.stats import Stats
|
||||
from features.workout import Workout
|
||||
from features.sql_explorer import SQLExplorer
|
||||
from utils import get_all_exercises_from_topsets, get_exercise_graph_model, get_topsets_for_person, get_workouts
|
||||
from features.dashboard import Dashboard
|
||||
from utils import get_exercise_graph_model
|
||||
|
||||
|
||||
class DataBase():
|
||||
@@ -25,6 +26,8 @@ class DataBase():
|
||||
self.sql_explorer = SQLExplorer(self.execute)
|
||||
self.person_overview = PersonOverview(self.execute)
|
||||
self.people_graphs = PeopleGraphs(self.execute)
|
||||
self.dashboard = Dashboard(self.execute)
|
||||
|
||||
db_url = urlparse(os.environ['DATABASE_URL'])
|
||||
# if db_url is null then throw error
|
||||
if not db_url:
|
||||
@@ -188,33 +191,11 @@ class DataBase():
|
||||
def update_workout_start_date(self, workout_id, start_date):
|
||||
self.execute('UPDATE workout SET start_date=%s WHERE workout_id=%s', [
|
||||
start_date, workout_id], commit=True)
|
||||
|
||||
def get_person_name(self, person_id):
|
||||
result = self.execute("""SELECT name from Person WHERE person_id=%s""", [person_id], one=True)
|
||||
return result["name"]
|
||||
|
||||
def get_person(self, person_id):
|
||||
topsets = self.execute("""
|
||||
SELECT
|
||||
P.person_id AS "PersonId",
|
||||
P.name AS "PersonName",
|
||||
W.workout_id AS "WorkoutId",
|
||||
W.start_date AS "StartDate",
|
||||
T.topset_id AS "TopSetId",
|
||||
E.exercise_id AS "ExerciseId",
|
||||
E.name AS "ExerciseName",
|
||||
T.repetitions AS "Repetitions",
|
||||
T.weight AS "Weight",
|
||||
round((100 * T.Weight::numeric::integer)/(101.3-2.67123 * T.Repetitions),0)::numeric::integer AS "Estimated1RM"
|
||||
FROM Person P
|
||||
LEFT JOIN Workout W ON P.person_id=W.person_id
|
||||
LEFT JOIN TopSet T ON W.workout_id=T.workout_id
|
||||
LEFT JOIN Exercise E ON T.exercise_id=E.exercise_id
|
||||
WHERE P.person_id=%s""", [person_id])
|
||||
|
||||
return {
|
||||
'PersonId': next((t['PersonId'] for t in topsets), -1),
|
||||
'PersonName': next((t['PersonName'] for t in topsets), 'Unknown'),
|
||||
'Exercises': get_all_exercises_from_topsets(topsets),
|
||||
'Workouts': get_workouts(topsets),
|
||||
'ExerciseProgressGraphs': get_topsets_for_person(topsets)
|
||||
}
|
||||
|
||||
def get_workout(self, person_id, workout_id):
|
||||
topsets = self.execute("""
|
||||
|
||||
Reference in New Issue
Block a user