Added ascent record to Dashboard
This commit is contained in:
parent
3040ae48e9
commit
462a193d2e
@ -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")
|
@ -22,6 +22,7 @@ BaseModel: DeclarativeMeta = db.Model
|
|||||||
record_types = [
|
record_types = [
|
||||||
'AS', # 'Best Average Speed'
|
'AS', # 'Best Average Speed'
|
||||||
'FD', # 'Farthest Distance'
|
'FD', # 'Farthest Distance'
|
||||||
|
'HA', # 'Highest Ascent'
|
||||||
'LD', # 'Longest Duration'
|
'LD', # 'Longest Duration'
|
||||||
'MS', # 'Max speed'
|
'MS', # 'Max speed'
|
||||||
]
|
]
|
||||||
@ -322,6 +323,7 @@ class Workout(BaseModel):
|
|||||||
record_types_columns = {
|
record_types_columns = {
|
||||||
'AS': 'ave_speed', # 'Average speed'
|
'AS': 'ave_speed', # 'Average speed'
|
||||||
'FD': 'distance', # 'Farthest Distance'
|
'FD': 'distance', # 'Farthest Distance'
|
||||||
|
'HA': 'ascent', # 'Highest Ascent'
|
||||||
'LD': 'moving', # 'Longest Duration'
|
'LD': 'moving', # 'Longest Duration'
|
||||||
'MS': 'max_speed', # 'Max speed'
|
'MS': 'max_speed', # 'Max speed'
|
||||||
}
|
}
|
||||||
@ -475,7 +477,7 @@ class Record(BaseModel):
|
|||||||
return datetime.timedelta(seconds=self._value)
|
return datetime.timedelta(seconds=self._value)
|
||||||
elif self.record_type in ['AS', 'MS']:
|
elif self.record_type in ['AS', 'MS']:
|
||||||
return float(self._value / 100)
|
return float(self._value / 100)
|
||||||
else: # 'FD'
|
else: # 'FD' or 'HA'
|
||||||
return float(self._value / 1000)
|
return float(self._value / 1000)
|
||||||
|
|
||||||
@value.setter # type: ignore
|
@value.setter # type: ignore
|
||||||
@ -485,7 +487,7 @@ class Record(BaseModel):
|
|||||||
def serialize(self) -> Dict:
|
def serialize(self) -> Dict:
|
||||||
if self.value is None:
|
if self.value is None:
|
||||||
value = 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
|
value = float(self.value) # type: ignore
|
||||||
else: # 'LD'
|
else: # 'LD'
|
||||||
value = str(self.value) # type: ignore
|
value = str(self.value) # type: ignore
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
"RECORD": "record | records",
|
"RECORD": "record | records",
|
||||||
"RECORD_AS": "Ave. speed",
|
"RECORD_AS": "Ave. speed",
|
||||||
"RECORD_FD": "Farest distance",
|
"RECORD_FD": "Farest distance",
|
||||||
|
"RECORD_HA": "Highest ascent",
|
||||||
"RECORD_LD": "Longest duration",
|
"RECORD_LD": "Longest duration",
|
||||||
"RECORD_MS": "Max. speed",
|
"RECORD_MS": "Max. speed",
|
||||||
"REMAINING_CHARS": "remaining characters",
|
"REMAINING_CHARS": "remaining characters",
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
"RECORD": "record | records",
|
"RECORD": "record | records",
|
||||||
"RECORD_AS": "Vitesse moy.",
|
"RECORD_AS": "Vitesse moy.",
|
||||||
"RECORD_FD": "Distance la + longue",
|
"RECORD_FD": "Distance la + longue",
|
||||||
|
"RECORD_HA": "dénivelé le plus positif",
|
||||||
"RECORD_LD": "Durée la + longue",
|
"RECORD_LD": "Durée la + longue",
|
||||||
"RECORD_MS": "Vitesse max.",
|
"RECORD_MS": "Vitesse max.",
|
||||||
"REMAINING_CHARS": "nombre de caractères restants ",
|
"REMAINING_CHARS": "nombre de caractères restants ",
|
||||||
|
@ -9,30 +9,37 @@ export const formatRecord = (
|
|||||||
tz: string,
|
tz: string,
|
||||||
useImperialUnits: boolean
|
useImperialUnits: boolean
|
||||||
): Record<string, string | number> => {
|
): Record<string, string | number> => {
|
||||||
const unitFrom: TUnit = 'km'
|
const distanceUnitFrom: TUnit = 'km'
|
||||||
const unitTo: TUnit = useImperialUnits
|
const distanceUnitTo: TUnit = useImperialUnits
|
||||||
? units[unitFrom].defaultTarget
|
? units[distanceUnitFrom].defaultTarget
|
||||||
: unitFrom
|
: distanceUnitFrom
|
||||||
|
const ascentUnitFrom: TUnit = 'm'
|
||||||
|
const ascentUnitTo: TUnit = useImperialUnits
|
||||||
|
? units[ascentUnitFrom].defaultTarget
|
||||||
|
: ascentUnitFrom
|
||||||
let value
|
let value
|
||||||
switch (record.record_type) {
|
switch (record.record_type) {
|
||||||
case 'AS':
|
case 'AS':
|
||||||
case 'MS':
|
case 'MS':
|
||||||
value = `${convertDistance(
|
value = `${convertDistance(
|
||||||
+record.value,
|
+record.value,
|
||||||
unitFrom,
|
distanceUnitFrom,
|
||||||
unitTo,
|
distanceUnitTo,
|
||||||
2
|
2
|
||||||
)} ${unitTo}/h`
|
)} ${distanceUnitTo}/h`
|
||||||
break
|
break
|
||||||
case 'FD':
|
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
|
break
|
||||||
case 'LD':
|
case 'LD':
|
||||||
value = record.value
|
value = record.value
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
throw new Error(
|
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 {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user