If a workout was tracked with a hear rate monitor heart rate graph will be selected by default, and average bpm will be rendered as well
This commit is contained in:
18
app.py
18
app.py
@@ -299,6 +299,7 @@ def get_workouts_for_user(user_id):
|
||||
for workout in workouts:
|
||||
cadence_readings = CadenceReading.query.filter_by(
|
||||
workout_id=workout.id).all()
|
||||
|
||||
if cadence_readings:
|
||||
start_time = min(
|
||||
reading.created_at for reading in cadence_readings)
|
||||
@@ -309,6 +310,18 @@ def get_workouts_for_user(user_id):
|
||||
reading.rpm for reading in cadence_readings) / len(cadence_readings)
|
||||
calories = cadence_readings[-1].calories
|
||||
distance = cadence_readings[-1].distance
|
||||
|
||||
selected_graph_types = ['speed']
|
||||
is_heart_rate_available = False
|
||||
heart_rate_readings = HeartRateReading.query.filter_by(
|
||||
workout_id=workout.id).all()
|
||||
average_bpm = 0
|
||||
if heart_rate_readings:
|
||||
selected_graph_types.append('heart_rate')
|
||||
is_heart_rate_available = True
|
||||
average_bpm = sum(heartrate.bpm for heartrate in heart_rate_readings) / \
|
||||
len(heart_rate_readings)
|
||||
|
||||
workouts_data.append({
|
||||
'id': workout.id,
|
||||
'user_id': user_id,
|
||||
@@ -319,7 +332,10 @@ def get_workouts_for_user(user_id):
|
||||
'average_rpm': int(average_rpm),
|
||||
'calories': int(calories),
|
||||
'distance': int(distance),
|
||||
'bike_display_name': workout.bike.display_name
|
||||
'bike_display_name': workout.bike.display_name,
|
||||
'selected_graph_types': selected_graph_types,
|
||||
'is_heart_rate_available': is_heart_rate_available,
|
||||
'average_bpm': int(average_bpm)
|
||||
})
|
||||
return workouts_data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user