Added ascent record to Dashboard

This commit is contained in:
Fmstrat 2022-03-24 12:17:44 -04:00
parent 3040ae48e9
commit 462a193d2e
5 changed files with 57 additions and 11 deletions

View File

@ -0,0 +1,35 @@
"""add ascent record
Revision ID: cd0e6cf83207
Revises: e30007d681cb
Create Date: 2022-03-22 20:21:13.661883
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'cd0e6cf83207'
down_revision = 'e30007d681cb'
branch_labels = None
depends_on = None
def upgrade():
op.execute(
"""
ALTER TYPE record_types ADD VALUE 'HA';
"""
)
def downgrade():
op.execute("ALTER TYPE record_types RENAME TO record_types_old")
op.execute("CREATE TYPE record_types AS ENUM('AS', 'FD', 'LD', 'MS')")
op.execute(
"""
ALTER TABLE records ALTER COLUMN record_type TYPE record_types
USING record_type::text::record_types
"""
)
op.execute("DROP TYPE record_types_old")

View File

@ -22,6 +22,7 @@ BaseModel: DeclarativeMeta = db.Model
record_types = [
'AS', # 'Best Average Speed'
'FD', # 'Farthest Distance'
'HA', # 'Highest Ascent'
'LD', # 'Longest Duration'
'MS', # 'Max speed'
]
@ -322,6 +323,7 @@ class Workout(BaseModel):
record_types_columns = {
'AS': 'ave_speed', # 'Average speed'
'FD': 'distance', # 'Farthest Distance'
'HA': 'ascent', # 'Highest Ascent'
'LD': 'moving', # 'Longest Duration'
'MS': 'max_speed', # 'Max speed'
}
@ -475,7 +477,7 @@ class Record(BaseModel):
return datetime.timedelta(seconds=self._value)
elif self.record_type in ['AS', 'MS']:
return float(self._value / 100)
else: # 'FD'
else: # 'FD' or 'HA'
return float(self._value / 1000)
@value.setter # type: ignore
@ -485,7 +487,7 @@ class Record(BaseModel):
def serialize(self) -> Dict:
if self.value is None:
value = None
elif self.record_type in ['AS', 'FD', 'MS']:
elif self.record_type in ['AS', 'FD', 'HA', 'MS']:
value = float(self.value) # type: ignore
else: # 'LD'
value = str(self.value) # type: ignore

View File

@ -43,6 +43,7 @@
"RECORD": "record | records",
"RECORD_AS": "Ave. speed",
"RECORD_FD": "Farest distance",
"RECORD_HA": "Highest ascent",
"RECORD_LD": "Longest duration",
"RECORD_MS": "Max. speed",
"REMAINING_CHARS": "remaining characters",

View File

@ -43,6 +43,7 @@
"RECORD": "record | records",
"RECORD_AS": "Vitesse moy.",
"RECORD_FD": "Distance la + longue",
"RECORD_HA": "dénivelé le plus positif",
"RECORD_LD": "Durée la + longue",
"RECORD_MS": "Vitesse max.",
"REMAINING_CHARS": "nombre de caractères restants ",

View File

@ -9,30 +9,37 @@ export const formatRecord = (
tz: string,
useImperialUnits: boolean
): Record<string, string | number> => {
const unitFrom: TUnit = 'km'
const unitTo: TUnit = useImperialUnits
? units[unitFrom].defaultTarget
: unitFrom
const distanceUnitFrom: TUnit = 'km'
const distanceUnitTo: TUnit = useImperialUnits
? units[distanceUnitFrom].defaultTarget
: distanceUnitFrom
const ascentUnitFrom: TUnit = 'm'
const ascentUnitTo: TUnit = useImperialUnits
? units[ascentUnitFrom].defaultTarget
: ascentUnitFrom
let value
switch (record.record_type) {
case 'AS':
case 'MS':
value = `${convertDistance(
+record.value,
unitFrom,
unitTo,
distanceUnitFrom,
distanceUnitTo,
2
)} ${unitTo}/h`
)} ${distanceUnitTo}/h`
break
case 'FD':
value = `${convertDistance(+record.value, unitFrom, unitTo, 3)} ${unitTo}`
value = `${convertDistance(+record.value, distanceUnitFrom, distanceUnitTo, 3)} ${distanceUnitTo}`
break
case 'HA':
value = `${convertDistance(+record.value, ascentUnitFrom, ascentUnitTo, 2)} ${ascentUnitTo}`
break
case 'LD':
value = record.value
break
default:
throw new Error(
`Invalid record type, expected: "AS", "FD", "LD", "MD", got: "${record.record_type}"`
`Invalid record type, expected: "AS", "FD", "HA", "LD", "MD", got: "${record.record_type}"`
)
}
return {