Merge branch 'dev' into oauth2
This commit is contained in:
@ -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'
|
||||
]
|
||||
@ -319,9 +320,14 @@ class Workout(BaseModel):
|
||||
def get_user_workout_records(
|
||||
cls, user_id: int, sport_id: int, as_integer: Optional[bool] = False
|
||||
) -> Dict:
|
||||
"""
|
||||
Note:
|
||||
Values for ascent are null for workouts without gpx
|
||||
"""
|
||||
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'
|
||||
}
|
||||
@ -329,7 +335,11 @@ class Workout(BaseModel):
|
||||
for record_type, column in record_types_columns.items():
|
||||
column_sorted = getattr(getattr(Workout, column), 'desc')()
|
||||
record_workout = (
|
||||
Workout.query.filter_by(user_id=user_id, sport_id=sport_id)
|
||||
Workout.query.filter(
|
||||
Workout.user_id == user_id,
|
||||
Workout.sport_id == sport_id,
|
||||
getattr(Workout, column) != None, # noqa
|
||||
)
|
||||
.order_by(column_sorted, Workout.workout_date)
|
||||
.first()
|
||||
)
|
||||
@ -481,7 +491,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
|
||||
@ -491,7 +501,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
|
||||
|
@ -17,10 +17,11 @@ def get_records(auth_user: User) -> Dict:
|
||||
Get all records for authenticated user.
|
||||
|
||||
Following types of records are available:
|
||||
- average speed (record_type: 'AS')
|
||||
- farest distance (record_type: 'FD')
|
||||
- longest duration (record_type: 'LD')
|
||||
- maximum speed (record_type: 'MS')
|
||||
- average speed (record_type: ``AS``)
|
||||
- farthest distance (record_type: ``FD``)
|
||||
- highest ascent (record_type: ``HA``)
|
||||
- longest duration (record_type: ``LD``)
|
||||
- maximum speed (record_type: ``MS``)
|
||||
|
||||
**Scope**: ``workouts:read``
|
||||
|
||||
@ -61,6 +62,15 @@ def get_records(auth_user: User) -> Dict:
|
||||
"workout_date": "Sun, 07 Jul 2019 08:00:00 GMT",
|
||||
"workout_id": "hvYBqYBRa7wwXpaStWR4V2"
|
||||
},
|
||||
{
|
||||
"id": 13,
|
||||
"record_type": "HA",
|
||||
"sport_id": 1,
|
||||
"user": "Sam",
|
||||
"value": 43.97,
|
||||
"workout_date": "Sun, 07 Jul 2019 08:00:00 GMT",
|
||||
"workout_id": "hvYBqYBRa7wwXpaStWR4V2"
|
||||
},
|
||||
{
|
||||
"id": 11,
|
||||
"record_type": "LD",
|
||||
|
@ -118,6 +118,15 @@ def get_workouts(auth_user: User) -> Union[Dict, HttpResponse]:
|
||||
"workout_date": "Mon, 01 Jan 2018 00:00:00 GMT",
|
||||
"workout_id": "kjxavSTUrJvoAh2wvCeGEF"
|
||||
},
|
||||
{
|
||||
"id": 13,
|
||||
"record_type": "HA",
|
||||
"sport_id": 1,
|
||||
"user": "Sam",
|
||||
"value": 43.97,
|
||||
"workout_date": "Sun, 07 Jul 2019 08:00:00 GMT",
|
||||
"workout_id": "hvYBqYBRa7wwXpaStWR4V2"
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"record_type": "LD",
|
||||
|
Reference in New Issue
Block a user