API & Client - fix elevation conversion to imperial units

This commit is contained in:
Sam 2022-12-14 18:15:56 +01:00
parent 47ec18e0a3
commit 3be55ed8e7
3 changed files with 84 additions and 6 deletions

View File

@ -0,0 +1,78 @@
"""update elevation precision
Revision ID: 0f375c44e659
Revises: a8cc0adfe1d3
Create Date: 2022-12-14 18:01:54.662987
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '0f375c44e659'
down_revision = 'a8cc0adfe1d3'
branch_labels = None
depends_on = None
def upgrade():
op.alter_column(
'workouts',
'descent',
existing_type=sa.NUMERIC(precision=7, scale=2),
type_=sa.Numeric(precision=8, scale=3),
existing_nullable=True,
)
op.alter_column(
'workouts',
'ascent',
existing_type=sa.NUMERIC(precision=7, scale=3),
type_=sa.Numeric(precision=8, scale=3),
existing_nullable=True,
)
op.alter_column(
'workout_segments',
'descent',
existing_type=sa.NUMERIC(precision=7, scale=2),
type_=sa.Numeric(precision=8, scale=3),
existing_nullable=True,
)
op.alter_column(
'workout_segments',
'ascent',
existing_type=sa.NUMERIC(precision=7, scale=3),
type_=sa.Numeric(precision=8, scale=3),
existing_nullable=True,
)
def downgrade():
op.alter_column(
'workout_segments',
'ascent',
existing_type=sa.NUMERIC(precision=8, scale=3),
type_=sa.Numeric(precision=7, scale=2),
existing_nullable=True,
)
op.alter_column(
'workout_segments',
'descent',
existing_type=sa.NUMERIC(precision=8, scale=3),
type_=sa.Numeric(precision=7, scale=2),
existing_nullable=True,
)
op.alter_column(
'workouts',
'ascent',
existing_type=sa.NUMERIC(precision=8, scale=3),
type_=sa.Numeric(precision=7, scale=2),
existing_nullable=True,
)
op.alter_column(
'workouts',
'descent',
existing_type=sa.NUMERIC(precision=8, scale=3),
type_=sa.Numeric(precision=7, scale=2),
existing_nullable=True,
)

View File

@ -148,8 +148,8 @@ class Workout(BaseModel):
distance = db.Column(db.Numeric(6, 3), nullable=True) # kilometers distance = db.Column(db.Numeric(6, 3), nullable=True) # kilometers
min_alt = db.Column(db.Numeric(6, 2), nullable=True) # meters min_alt = db.Column(db.Numeric(6, 2), nullable=True) # meters
max_alt = db.Column(db.Numeric(6, 2), nullable=True) # meters max_alt = db.Column(db.Numeric(6, 2), nullable=True) # meters
descent = db.Column(db.Numeric(7, 2), nullable=True) # meters descent = db.Column(db.Numeric(8, 3), nullable=True) # meters
ascent = db.Column(db.Numeric(7, 2), nullable=True) # meters ascent = db.Column(db.Numeric(8, 3), nullable=True) # meters
max_speed = db.Column(db.Numeric(6, 2), nullable=True) # km/h max_speed = db.Column(db.Numeric(6, 2), nullable=True) # km/h
ave_speed = db.Column(db.Numeric(6, 2), nullable=True) # km/h ave_speed = db.Column(db.Numeric(6, 2), nullable=True) # km/h
bounds = db.Column(postgresql.ARRAY(db.Float), nullable=True) bounds = db.Column(postgresql.ARRAY(db.Float), nullable=True)
@ -415,8 +415,8 @@ class WorkoutSegment(BaseModel):
distance = db.Column(db.Numeric(6, 3), nullable=True) # kilometers distance = db.Column(db.Numeric(6, 3), nullable=True) # kilometers
min_alt = db.Column(db.Numeric(6, 2), nullable=True) # meters min_alt = db.Column(db.Numeric(6, 2), nullable=True) # meters
max_alt = db.Column(db.Numeric(6, 2), nullable=True) # meters max_alt = db.Column(db.Numeric(6, 2), nullable=True) # meters
descent = db.Column(db.Numeric(7, 2), nullable=True) # meters descent = db.Column(db.Numeric(8, 3), nullable=True) # meters
ascent = db.Column(db.Numeric(7, 2), nullable=True) # meters ascent = db.Column(db.Numeric(8, 3), nullable=True) # meters
max_speed = db.Column(db.Numeric(6, 2), nullable=True) # km/h max_speed = db.Column(db.Numeric(6, 2), nullable=True) # km/h
ave_speed = db.Column(db.Numeric(6, 2), nullable=True) # km/h ave_speed = db.Column(db.Numeric(6, 2), nullable=True) # km/h

View File

@ -439,13 +439,13 @@
workoutForm.workoutAscent === '' workoutForm.workoutAscent === ''
? null ? null
: authUser.value.imperial_units : authUser.value.imperial_units
? convertDistance(+workoutForm.workoutAscent, 'ft', 'm', 2) ? convertDistance(+workoutForm.workoutAscent, 'ft', 'm', 3)
: +workoutForm.workoutAscent : +workoutForm.workoutAscent
payload.descent = payload.descent =
workoutForm.workoutDescent === '' workoutForm.workoutDescent === ''
? null ? null
: authUser.value.imperial_units : authUser.value.imperial_units
? convertDistance(+workoutForm.workoutDescent, 'ft', 'm', 2) ? convertDistance(+workoutForm.workoutDescent, 'ft', 'm', 3)
: +workoutForm.workoutDescent : +workoutForm.workoutDescent
if ( if (
(payload.ascent !== null && payload.descent === null) || (payload.ascent !== null && payload.descent === null) ||