Merge pull request #251 from SamR1/fix-segment-duration

API - save segment duration w/o microseconds
This commit is contained in:
Sam 2022-10-31 11:11:45 +01:00 committed by GitHub
commit 37e9e88bd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 2 deletions

View File

@ -1,12 +1,16 @@
from datetime import datetime from datetime import datetime, timedelta
from statistics import mean from statistics import mean
from typing import List, Union from typing import List, Union
import pytest import pytest
import pytz import pytz
from flask import Flask
from gpxpy.gpxfield import SimpleTZ from gpxpy.gpxfield import SimpleTZ
from fittrackee.users.models import User
from fittrackee.workouts.models import Sport, Workout
from fittrackee.workouts.utils.workouts import ( from fittrackee.workouts.utils.workouts import (
create_segment,
get_average_speed, get_average_speed,
get_workout_datetime, get_workout_datetime,
) )
@ -113,3 +117,34 @@ class TestWorkoutGetWorkoutDatetime:
) )
assert workout_date_with_tz is None assert workout_date_with_tz is None
class TestCreateSegment:
def test_it_removes_microseconds(
self,
app: Flask,
user_1: User,
sport_1_cycling: Sport,
workout_cycling_user_1: Workout,
) -> None:
duration = timedelta(seconds=3600, microseconds=100)
segment = create_segment(
workout_id=workout_cycling_user_1.id,
workout_uuid=workout_cycling_user_1.uuid,
segment_data={
'idx': 0,
'duration': duration,
'distance': 10,
'stop_time': timedelta(seconds=0),
'moving_time': duration,
'elevation_min': None,
'elevation_max': None,
'downhill': None,
'uphill': None,
'max_speed': 10,
'average_speed': 10,
},
)
assert segment.duration.microseconds == 0

View File

@ -174,7 +174,7 @@ def create_segment(
workout_uuid=workout_uuid, workout_uuid=workout_uuid,
segment_id=segment_data['idx'], segment_id=segment_data['idx'],
) )
new_segment.duration = segment_data['duration'] new_segment.duration = _remove_microseconds(segment_data['duration'])
new_segment.distance = segment_data['distance'] new_segment.distance = segment_data['distance']
update_workout_data(new_segment, segment_data) update_workout_data(new_segment, segment_data)
return new_segment return new_segment