Js date is being sent as a string and therefore when attempting to calculate duration an error is thrown

This commit is contained in:
Peter Stockings
2023-07-31 13:07:17 +10:00
parent c826b9180a
commit 6628d8a40f

12
app.py
View File

@@ -164,10 +164,10 @@ def workouts(user_id):
db.session.add(heart_rate_reading) db.session.add(heart_rate_reading)
if cadence_readings: if cadence_readings:
start_time = min( timestamps = [datetime_converter(
c['timestamp'] for c in cadence_readings) c['timestamp']) for c in cadence_readings]
end_time = max( start_time = min(timestamps)
c['timestamp'] for c in cadence_readings) end_time = max(timestamps)
duration = end_time - start_time duration = end_time - start_time
duration = duration.total_seconds() duration = duration.total_seconds()
average_rpm = sum( average_rpm = sum(
@@ -437,6 +437,10 @@ def format_duration(duration):
return f"{minutes}m" return f"{minutes}m"
def datetime_converter(datetime_str: str) -> datetime:
return datetime.strptime(datetime_str, "%Y-%m-%dT%H:%M:%S%z")
if __name__ == '__main__': if __name__ == '__main__':
# Bind to PORT if defined, otherwise default to 5000. # Bind to PORT if defined, otherwise default to 5000.
port = int(os.environ.get('PORT', 5000)) port = int(os.environ.get('PORT', 5000))