diff --git a/fittrackee/migrations/versions/32_eff1c16c43eb_add_gpx_speed_preference.py b/fittrackee/migrations/versions/32_eff1c16c43eb_add_gpx_speed_preference.py new file mode 100644 index 00000000..73348290 --- /dev/null +++ b/fittrackee/migrations/versions/32_eff1c16c43eb_add_gpx_speed_preference.py @@ -0,0 +1,34 @@ +"""Add user prefrence for gpx speed calculation + +Revision ID: eff1c16c43eb +Revises: db58d195c5bf +Create Date: 2023-05-14 22:12:56.244291 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'eff1c16c43eb' +down_revision = 'db58d195c5bf' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('users', schema=None) as batch_op: + batch_op.add_column(sa.Column('use_raw_gpx_speed', sa.Boolean(), nullable=True)) + op.execute("UPDATE users SET use_raw_gpx_speed = false") + op.alter_column('users', 'use_raw_gpx_speed', nullable=False) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('users', schema=None) as batch_op: + batch_op.drop_column('use_raw_gpx_speed') + + # ### end Alembic commands ### diff --git a/fittrackee/tests/users/test_auth_api.py b/fittrackee/tests/users/test_auth_api.py index 4b6cf5e7..d88ec55f 100644 --- a/fittrackee/tests/users/test_auth_api.py +++ b/fittrackee/tests/users/test_auth_api.py @@ -1483,6 +1483,7 @@ class TestUserPreferencesUpdate(ApiTestCaseMixin): imperial_units=True, display_ascent=False, start_elevation_at_zero=False, + use_raw_gpx_speed=True, date_format='yyyy-MM-dd', ) ), @@ -1495,6 +1496,7 @@ class TestUserPreferencesUpdate(ApiTestCaseMixin): assert data['message'] == 'user preferences updated' assert data['data']['display_ascent'] is False assert data['data']['start_elevation_at_zero'] is False + assert data['data']['use_raw_gpx_speed'] is True assert data['data']['imperial_units'] is True assert data['data']['language'] == expected_language assert data['data']['timezone'] == 'America/New_York' diff --git a/fittrackee/users/auth.py b/fittrackee/users/auth.py index 00516ffc..2f0ff282 100644 --- a/fittrackee/users/auth.py +++ b/fittrackee/users/auth.py @@ -879,6 +879,7 @@ def edit_user_preferences(auth_user: User) -> Union[Dict, HttpResponse]: "total_ascent": 720.35, "total_distance": 67.895, "total_duration": "6:50:27", + "use_raw_gpx_speed": true, "username": "sam" "weekm": true, }, @@ -892,6 +893,7 @@ def edit_user_preferences(auth_user: User) -> Union[Dict, HttpResponse]: : Union[Dict, HttpResponse]: 'language', 'start_elevation_at_zero', 'timezone', + 'use_raw_gpx_speed', 'weekm', } if not post_data or not post_data.keys() >= user_mandatory_data: @@ -925,6 +928,7 @@ def edit_user_preferences(auth_user: User) -> Union[Dict, HttpResponse]: imperial_units = post_data.get('imperial_units') language = get_language(post_data.get('language')) start_elevation_at_zero = post_data.get('start_elevation_at_zero') + use_raw_gpx_speed = post_data.get('use_raw_gpx_speed') timezone = post_data.get('timezone') weekm = post_data.get('weekm') @@ -935,6 +939,7 @@ def edit_user_preferences(auth_user: User) -> Union[Dict, HttpResponse]: auth_user.language = language auth_user.start_elevation_at_zero = start_elevation_at_zero auth_user.timezone = timezone + auth_user.use_raw_gpx_speed = use_raw_gpx_speed auth_user.weekm = weekm db.session.commit() diff --git a/fittrackee/users/models.py b/fittrackee/users/models.py index 2c598a31..8ab7c91e 100644 --- a/fittrackee/users/models.py +++ b/fittrackee/users/models.py @@ -62,6 +62,9 @@ class User(BaseModel): start_elevation_at_zero = db.Column( db.Boolean, default=True, nullable=False ) + use_raw_gpx_speed = db.Column( + db.Boolean, default=False, nullable=False + ) def __repr__(self) -> str: return f'' @@ -216,6 +219,7 @@ class User(BaseModel): 'language': self.language, 'start_elevation_at_zero': self.start_elevation_at_zero, 'timezone': self.timezone, + 'use_raw_gpx_speed': self.use_raw_gpx_speed, 'weekm': self.weekm, }, } diff --git a/fittrackee/workouts/utils/gpx.py b/fittrackee/workouts/utils/gpx.py index 0116fab8..7e1428ba 100644 --- a/fittrackee/workouts/utils/gpx.py +++ b/fittrackee/workouts/utils/gpx.py @@ -73,6 +73,7 @@ def get_gpx_info( stopped_speed_threshold: float, update_map_data: Optional[bool] = True, update_weather_data: Optional[bool] = True, + use_raw_gpx_speed: Optional[bool] = False ) -> Tuple: """ Parse and return gpx, map and weather data from gpx file @@ -128,7 +129,8 @@ def get_gpx_info( if update_map_data: map_data.append([point.longitude, point.latitude]) moving_data = segment.get_moving_data( - stopped_speed_threshold=stopped_speed_threshold + stopped_speed_threshold=stopped_speed_threshold, + raw=use_raw_gpx_speed ) if moving_data: calculated_max_speed = moving_data.max_speed diff --git a/fittrackee/workouts/utils/workouts.py b/fittrackee/workouts/utils/workouts.py index c687205d..2caed7ce 100644 --- a/fittrackee/workouts/utils/workouts.py +++ b/fittrackee/workouts/utils/workouts.py @@ -299,10 +299,12 @@ def process_one_gpx_file( absolute_gpx_filepath = None absolute_map_filepath = None try: - gpx_data, map_data, weather_data = get_gpx_info( - params['file_path'], stopped_speed_threshold - ) auth_user = params['auth_user'] + gpx_data, map_data, weather_data = get_gpx_info( + gpx_file=params['file_path'], + stopped_speed_threshold=stopped_speed_threshold, + use_raw_gpx_speed=auth_user.use_raw_gpx_speed + ) workout_date, _ = get_workout_datetime( workout_date=gpx_data['start'], date_str_format=None if gpx_data else '%Y-%m-%d %H:%M',