Switch stats from camel case to snake case
This commit is contained in:
@@ -11,10 +11,10 @@ class Stats:
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
# Extract necessary fields
|
# Extract necessary fields
|
||||||
workout_ids = [t["WorkoutId"] for t in topsets if t["WorkoutId"]]
|
workout_ids = [t["workout_id"] for t in topsets if t["workout_id"]]
|
||||||
person_ids = [t["PersonId"] for t in topsets if t["PersonId"]]
|
person_ids = [t["person_id"] for t in topsets if t["person_id"]]
|
||||||
start_dates = [t["StartDate"] for t in topsets if t["StartDate"]]
|
start_dates = [t["start_date"] for t in topsets if t["start_date"]]
|
||||||
exercise_ids = [t["ExerciseId"] for t in topsets if t["ExerciseId"]]
|
exercise_ids = [t["exercise_id"] for t in topsets if t["exercise_id"]]
|
||||||
|
|
||||||
workout_count = len(set(workout_ids))
|
workout_count = len(set(workout_ids))
|
||||||
people_count = len(set(person_ids))
|
people_count = len(set(person_ids))
|
||||||
@@ -24,8 +24,8 @@ class Stats:
|
|||||||
# Group sets by workout and exercise
|
# Group sets by workout and exercise
|
||||||
sets_per_exercise_per_workout = defaultdict(lambda: defaultdict(int))
|
sets_per_exercise_per_workout = defaultdict(lambda: defaultdict(int))
|
||||||
for t in topsets:
|
for t in topsets:
|
||||||
if t["WorkoutId"] and t["ExerciseId"]:
|
if t["workout_id"] and t["exercise_id"]:
|
||||||
sets_per_exercise_per_workout[t["WorkoutId"]][t["ExerciseId"]] += 1
|
sets_per_exercise_per_workout[t["workout_id"]][t["exercise_id"]] += 1
|
||||||
|
|
||||||
# Calculate the average sets per exercise across all workouts
|
# Calculate the average sets per exercise across all workouts
|
||||||
total_sets_per_exercise = []
|
total_sets_per_exercise = []
|
||||||
@@ -37,8 +37,8 @@ class Stats:
|
|||||||
# Group exercises by workout
|
# Group exercises by workout
|
||||||
exercises_by_workout = defaultdict(set)
|
exercises_by_workout = defaultdict(set)
|
||||||
for t in topsets:
|
for t in topsets:
|
||||||
if t["WorkoutId"] and t["ExerciseId"]:
|
if t["workout_id"] and t["exercise_id"]:
|
||||||
exercises_by_workout[t["WorkoutId"]].add(t["ExerciseId"])
|
exercises_by_workout[t["workout_id"]].add(t["exercise_id"])
|
||||||
|
|
||||||
# Calculate average exercises per workout
|
# Calculate average exercises per workout
|
||||||
average_exercises_per_workout = round(
|
average_exercises_per_workout = round(
|
||||||
@@ -47,40 +47,40 @@ class Stats:
|
|||||||
|
|
||||||
# Stats
|
# Stats
|
||||||
stats = [
|
stats = [
|
||||||
{"Text": "Total Workouts", "Value": workout_count},
|
{"text": "Total Workouts", "value": workout_count},
|
||||||
{"Text": "Total Sets", "Value": total_sets},
|
{"text": "Total Sets", "value": total_sets},
|
||||||
{"Text": "Average Sets Per Exercise", "Value": average_sets_per_exercise}
|
{"text": "Average Sets Per Exercise", "value": average_sets_per_exercise}
|
||||||
]
|
]
|
||||||
|
|
||||||
if exercise_count > 1:
|
if exercise_count > 1:
|
||||||
stats.append({"Text": "Total Exercises", "Value": exercise_count})
|
stats.append({"text": "Total Exercises", "value": exercise_count})
|
||||||
stats.append({"Text": "Average Exercises Per Workout", "Value": average_exercises_per_workout})
|
stats.append({"text": "Average Exercises Per Workout", "value": average_exercises_per_workout})
|
||||||
|
|
||||||
if people_count > 1:
|
if people_count > 1:
|
||||||
stats.append({"Text": "People Tracked", "Value": people_count})
|
stats.append({"text": "People Tracked", "value": people_count})
|
||||||
|
|
||||||
if workout_count > 0:
|
if workout_count > 0:
|
||||||
first_workout_date = min(start_dates)
|
first_workout_date = min(start_dates)
|
||||||
last_workout_date = max(start_dates)
|
last_workout_date = max(start_dates)
|
||||||
current_date = date.today()
|
current_date = date.today()
|
||||||
|
|
||||||
stats.append({"Text": "Days Since First Workout",
|
stats.append({"text": "Days Since First Workout",
|
||||||
"Value": (current_date - first_workout_date).days})
|
"value": (current_date - first_workout_date).days})
|
||||||
|
|
||||||
if workout_count >= 2:
|
if workout_count >= 2:
|
||||||
stats.append({"Text": "Days Since Last Workout",
|
stats.append({"text": "Days Since Last Workout",
|
||||||
"Value": (current_date - last_workout_date).days})
|
"value": (current_date - last_workout_date).days})
|
||||||
|
|
||||||
average_sets_per_workout = round(total_sets / workout_count, 1)
|
average_sets_per_workout = round(total_sets / workout_count, 1)
|
||||||
stats.append({"Text": "Average Sets Per Workout",
|
stats.append({"text": "Average Sets Per Workout",
|
||||||
"Value": average_sets_per_workout})
|
"value": average_sets_per_workout})
|
||||||
|
|
||||||
training_duration = last_workout_date - first_workout_date
|
training_duration = last_workout_date - first_workout_date
|
||||||
if training_duration.days > 0:
|
if training_duration.days > 0:
|
||||||
average_workouts_per_week = round(
|
average_workouts_per_week = round(
|
||||||
workout_count / (training_duration.days / 7), 1)
|
workout_count / (training_duration.days / 7), 1)
|
||||||
stats.append({"Text": "Average Workouts Per Week",
|
stats.append({"text": "Average Workouts Per Week",
|
||||||
"Value": average_workouts_per_week})
|
"value": average_workouts_per_week})
|
||||||
|
|
||||||
return stats
|
return stats
|
||||||
|
|
||||||
@@ -88,10 +88,10 @@ class Stats:
|
|||||||
# Base query
|
# Base query
|
||||||
query = """
|
query = """
|
||||||
SELECT
|
SELECT
|
||||||
t.workout_id AS "WorkoutId",
|
t.workout_id,
|
||||||
w.person_id AS "PersonId",
|
w.person_id,
|
||||||
w.start_date AS "StartDate",
|
w.start_date,
|
||||||
e.exercise_id AS "ExerciseId"
|
e.exercise_id
|
||||||
FROM
|
FROM
|
||||||
topset t
|
topset t
|
||||||
JOIN workout w ON t.workout_id = w.workout_id
|
JOIN workout w ON t.workout_id = w.workout_id
|
||||||
|
|||||||
@@ -5,8 +5,8 @@
|
|||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<div class="flex-shrink-0">
|
<div class="flex-shrink-0">
|
||||||
<span class="text-2xl sm:text-3xl leading-none font-bold text-gray-900">{{
|
<span class="text-2xl sm:text-3xl leading-none font-bold text-gray-900">{{
|
||||||
stat['Value'] }}</span>
|
stat.value }}</span>
|
||||||
<h3 class="text-base font-normal text-gray-500">{{ stat['Text'] }}</h3>
|
<h3 class="text-base font-normal text-gray-500">{{ stat.text }}</h3>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user