Add pref for use_raw_gpx_speed; still need to do tests and client UI bits

This commit is contained in:
Joshua Taillon 2023-05-14 22:40:03 -06:00
parent 518251d442
commit a98057c936
6 changed files with 53 additions and 4 deletions

View File

@ -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 ###

View File

@ -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'

View File

@ -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]:
:<json string language: language preferences
:<json boolean start_elevation_at_zero: do elevation plots start at zero?
:<json string timezone: user time zone
:<json boolean use_raw_gpx_speed: Use raw (unfiltered) gpx data to calculate speeds
:<json boolean weekm: does week start on Monday?
:reqheader Authorization: OAuth 2.0 Bearer Token
@ -915,6 +917,7 @@ def edit_user_preferences(auth_user: User) -> 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()

View File

@ -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'<User {self.username!r}>'
@ -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,
},
}

View File

@ -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

View File

@ -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',