diff --git a/fittrackee/migrations/versions/23_cd0e6cf83207_add_ascent_record.py b/fittrackee/migrations/versions/23_cd0e6cf83207_add_ascent_record.py new file mode 100644 index 00000000..aef966c1 --- /dev/null +++ b/fittrackee/migrations/versions/23_cd0e6cf83207_add_ascent_record.py @@ -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") diff --git a/fittrackee/workouts/models.py b/fittrackee/workouts/models.py index ac5e2273..d9089889 100644 --- a/fittrackee/workouts/models.py +++ b/fittrackee/workouts/models.py @@ -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 diff --git a/fittrackee_client/src/locales/en/workouts.json b/fittrackee_client/src/locales/en/workouts.json index 2685ea39..474fa29c 100644 --- a/fittrackee_client/src/locales/en/workouts.json +++ b/fittrackee_client/src/locales/en/workouts.json @@ -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", diff --git a/fittrackee_client/src/locales/fr/workouts.json b/fittrackee_client/src/locales/fr/workouts.json index 5d5f3858..9ecc2173 100644 --- a/fittrackee_client/src/locales/fr/workouts.json +++ b/fittrackee_client/src/locales/fr/workouts.json @@ -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 ", diff --git a/fittrackee_client/src/utils/records.ts b/fittrackee_client/src/utils/records.ts index abed185b..392e6e85 100644 --- a/fittrackee_client/src/utils/records.ts +++ b/fittrackee_client/src/utils/records.ts @@ -9,30 +9,37 @@ export const formatRecord = ( tz: string, useImperialUnits: boolean ): Record => { - 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 {