From 6628d8a40f523a400400c871f9a01ac240c777a8 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Mon, 31 Jul 2023 13:07:17 +1000 Subject: [PATCH] Js date is being sent as a string and therefore when attempting to calculate duration an error is thrown --- app.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index b788213..af5af14 100644 --- a/app.py +++ b/app.py @@ -164,10 +164,10 @@ def workouts(user_id): db.session.add(heart_rate_reading) if cadence_readings: - start_time = min( - c['timestamp'] for c in cadence_readings) - end_time = max( - c['timestamp'] for c in cadence_readings) + timestamps = [datetime_converter( + c['timestamp']) for c in cadence_readings] + start_time = min(timestamps) + end_time = max(timestamps) duration = end_time - start_time duration = duration.total_seconds() average_rpm = sum( @@ -437,6 +437,10 @@ def format_duration(duration): 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__': # Bind to PORT if defined, otherwise default to 5000. port = int(os.environ.get('PORT', 5000))