Merge branch 'dev' into elevation
This commit is contained in:
Vendored
+1
-1
@@ -1 +1 @@
|
||||
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><!--[if IE]><link rel="icon" href="/favicon.ico"><![endif]--><link rel="stylesheet" href="/static/css/fork-awesome.min.css"/><link rel="stylesheet" href="/static/css/leaflet.css"/><title>FitTrackee</title><script defer="defer" src="/static/js/chunk-vendors.7132edc6.js"></script><script defer="defer" src="/static/js/app.bf1d4e1c.js"></script><link href="/static/css/app.32d0ced1.css" rel="stylesheet"><link rel="icon" type="image/png" sizes="32x32" href="/img/icons/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/img/icons/favicon-16x16.png"><link rel="manifest" href="/manifest.json"><meta name="theme-color" content="#4DBA87"><meta name="apple-mobile-web-app-capable" content="no"><meta name="apple-mobile-web-app-status-bar-style" content="default"><meta name="apple-mobile-web-app-title" content="fittrackee_client"><link rel="apple-touch-icon" href="/img/icons/apple-touch-icon-152x152.png"><link rel="mask-icon" href="/img/icons/safari-pinned-tab.svg" color="#4DBA87"><meta name="msapplication-TileImage" content="/img/icons/msapplication-icon-144x144.png"><meta name="msapplication-TileColor" content="#000000"></head><body><noscript><strong>We're sorry but FitTrackee doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
|
||||
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><!--[if IE]><link rel="icon" href="/favicon.ico"><![endif]--><link rel="stylesheet" href="/static/css/fork-awesome.min.css"/><link rel="stylesheet" href="/static/css/leaflet.css"/><title>FitTrackee</title><script defer="defer" src="/static/js/chunk-vendors.7132edc6.js"></script><script defer="defer" src="/static/js/app.ac1e5052.js"></script><link href="/static/css/app.f768a44b.css" rel="stylesheet"><link rel="icon" type="image/png" sizes="32x32" href="/img/icons/favicon-32x32.png"><link rel="icon" type="image/png" sizes="16x16" href="/img/icons/favicon-16x16.png"><link rel="manifest" href="/manifest.json"><meta name="theme-color" content="#4DBA87"><meta name="apple-mobile-web-app-capable" content="no"><meta name="apple-mobile-web-app-status-bar-style" content="default"><meta name="apple-mobile-web-app-title" content="fittrackee_client"><link rel="apple-touch-icon" href="/img/icons/apple-touch-icon-152x152.png"><link rel="mask-icon" href="/img/icons/safari-pinned-tab.svg" color="#4DBA87"><meta name="msapplication-TileImage" content="/img/icons/msapplication-icon-144x144.png"><meta name="msapplication-TileColor" content="#000000"></head><body><noscript><strong>We're sorry but FitTrackee doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
-1
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
+2
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
-2
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
@@ -1,2 +1,2 @@
|
||||
"use strict";(self["webpackChunkfittrackee_client"]=self["webpackChunkfittrackee_client"]||[]).push([[193],{9161:function(e,s,t){t.r(s),t.d(s,{default:function(){return A}});t(6699);var a=t(6252),r=t(2262),l=t(3577),o=t(3324),n=t(9996);const c={class:"chart-menu"},i={class:"chart-arrow"},u={class:"time-frames custom-checkboxes-group"},d={class:"time-frames-checkboxes custom-checkboxes"},p=["id","name","checked","onInput"],m={class:"chart-arrow"};var v=(0,a.aZ)({__name:"StatsMenu",emits:["arrowClick","timeFrameUpdate"],setup(e,{emit:s}){const t=(0,r.iH)("month"),o=["week","month","year"];function n(e){t.value=e,s("timeFrameUpdate",e)}return(e,r)=>((0,a.wg)(),(0,a.iD)("div",c,[(0,a._)("div",i,[(0,a._)("i",{class:"fa fa-chevron-left","aria-hidden":"true",onClick:r[0]||(r[0]=e=>s("arrowClick",!0))})]),(0,a._)("div",u,[(0,a._)("div",d,[((0,a.wg)(),(0,a.iD)(a.HY,null,(0,a.Ko)(o,(s=>(0,a._)("div",{class:"time-frame custom-checkbox",key:s},[(0,a._)("label",null,[(0,a._)("input",{type:"radio",id:s,name:s,checked:t.value===s,onInput:e=>n(s)},null,40,p),(0,a._)("span",null,(0,l.zw)(e.$t(`statistics.TIME_FRAMES.${s}`)),1)])]))),64))])]),(0,a._)("div",m,[(0,a._)("i",{class:"fa fa-chevron-right","aria-hidden":"true",onClick:r[1]||(r[1]=e=>s("arrowClick",!1))})])]))}}),k=t(3744);const _=(0,k.Z)(v,[["__scopeId","data-v-22d55de2"]]);var S=_,w=t(631);const f={class:"sports-menu"},h=["id","name","checked","onInput"],U={class:"sport-label"};var b=(0,a.aZ)({__name:"StatsSportsMenu",props:{userSports:null,selectedSportIds:{default:()=>[]}},emits:["selectedSportIdsUpdate"],setup(e,{emit:s}){const t=e,{t:n}=(0,o.QT)(),c=(0,a.f3)("sportColors"),{selectedSportIds:i}=(0,r.BK)(t),u=(0,a.Fl)((()=>(0,w.xH)(t.userSports,n)));function d(e){s("selectedSportIdsUpdate",e)}return(e,s)=>{const t=(0,a.up)("SportImage");return(0,a.wg)(),(0,a.iD)("div",f,[((0,a.wg)(!0),(0,a.iD)(a.HY,null,(0,a.Ko)((0,r.SU)(u),(e=>((0,a.wg)(),(0,a.iD)("label",{type:"checkbox",key:e.id,style:(0,l.j5)({color:e.color?e.color:(0,r.SU)(c)[e.label]})},[(0,a._)("input",{type:"checkbox",id:e.id,name:e.label,checked:(0,r.SU)(i).includes(e.id),onInput:s=>d(e.id)},null,40,h),(0,a.Wm)(t,{"sport-label":e.label,color:e.color},null,8,["sport-label","color"]),(0,a._)("span",U,(0,l.zw)(e.translatedLabel),1)],4)))),128))])}}});const I=b;var g=I,T=t(9318);const y={key:0,id:"user-statistics"};var C=(0,a.aZ)({__name:"index",props:{sports:null,user:null},setup(e){const s=e,{t:t}=(0,o.QT)(),{sports:l,user:c}=(0,r.BK)(s),i=(0,r.iH)("month"),u=(0,r.iH)(v(i.value)),d=(0,a.Fl)((()=>(0,w.xH)(s.sports,t))),p=(0,r.iH)(_(s.sports));function m(e){i.value=e,u.value=v(i.value)}function v(e){return(0,T.aZ)(new Date,e,s.user.weekm)}function k(e){u.value=(0,T.FN)(u.value,e,s.user.weekm)}function _(e){return e.map((e=>e.id))}function f(e){p.value.includes(e)?p.value=p.value.filter((s=>s!==e)):p.value.push(e)}return(0,a.YP)((()=>s.sports),(e=>{p.value=_(e)})),(e,s)=>(0,r.SU)(d)?((0,a.wg)(),(0,a.iD)("div",y,[(0,a.Wm)(S,{onTimeFrameUpdate:m,onArrowClick:k}),(0,a.Wm)(n.Z,{sports:(0,r.SU)(l),user:(0,r.SU)(c),chartParams:u.value,"displayed-sport-ids":p.value,fullStats:!0},null,8,["sports","user","chartParams","displayed-sport-ids"]),(0,a.Wm)(g,{"selected-sport-ids":p.value,"user-sports":(0,r.SU)(l),onSelectedSportIdsUpdate:f},null,8,["selected-sport-ids","user-sports"])])):(0,a.kq)("",!0)}});const F=(0,k.Z)(C,[["__scopeId","data-v-d693c7da"]]);var Z=F,x=t(5630),D=t(8602),H=t(9917);const E={id:"statistics",class:"view"},R={key:0,class:"container"};var W=(0,a.aZ)({__name:"StatisticsView",setup(e){const s=(0,H.o)(),t=(0,a.Fl)((()=>s.getters[D.YN.GETTERS.AUTH_USER_PROFILE])),o=(0,a.Fl)((()=>s.getters[D.O8.GETTERS.SPORTS].filter((e=>t.value.sports_list.includes(e.id)))));return(e,s)=>{const n=(0,a.up)("Card");return(0,a.wg)(),(0,a.iD)("div",E,[(0,r.SU)(t).username?((0,a.wg)(),(0,a.iD)("div",R,[(0,a.Wm)(n,null,{title:(0,a.w5)((()=>[(0,a.Uk)((0,l.zw)(e.$t("statistics.STATISTICS")),1)])),content:(0,a.w5)((()=>[(0,a.Wm)(Z,{class:(0,l.C_)({"stats-disabled":0===(0,r.SU)(t).nb_workouts}),user:(0,r.SU)(t),sports:(0,r.SU)(o)},null,8,["class","user","sports"])])),_:1}),0===(0,r.SU)(t).nb_workouts?((0,a.wg)(),(0,a.j4)(x.Z,{key:0})):(0,a.kq)("",!0)])):(0,a.kq)("",!0)])}}});const P=(0,k.Z)(W,[["__scopeId","data-v-2e341d4e"]]);var A=P}}]);
|
||||
//# sourceMappingURL=statistics.1ad194e3.js.map
|
||||
//# sourceMappingURL=statistics.440cd8b2.js.map
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
@@ -0,0 +1,45 @@
|
||||
"""add ascent record
|
||||
|
||||
Revision ID: cd0e6cf83207
|
||||
Revises: 5e3a3a31c432
|
||||
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 = '5e3a3a31c432'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
op.execute(
|
||||
"""
|
||||
ALTER TYPE record_types ADD VALUE 'HA';
|
||||
"""
|
||||
)
|
||||
|
||||
op.add_column(
|
||||
'users', sa.Column('display_ascent', sa.Boolean(), nullable=True)
|
||||
)
|
||||
op.execute("UPDATE users SET display_ascent = true")
|
||||
op.alter_column('users', 'display_ascent', nullable=False)
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_column('users', 'display_ascent')
|
||||
|
||||
op.execute("DELETE FROM records WHERE record_type = 'HA';")
|
||||
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")
|
||||
@@ -1272,6 +1272,7 @@ class TestUserPreferencesUpdate(ApiTestCaseMixin):
|
||||
weekm=True,
|
||||
language=input_language,
|
||||
imperial_units=True,
|
||||
display_ascent=False,
|
||||
)
|
||||
),
|
||||
headers=dict(Authorization=f'Bearer {auth_token}'),
|
||||
@@ -1281,8 +1282,11 @@ class TestUserPreferencesUpdate(ApiTestCaseMixin):
|
||||
data = json.loads(response.data.decode())
|
||||
assert data['status'] == 'success'
|
||||
assert data['message'] == 'user preferences updated'
|
||||
assert data['data']['display_ascent'] is False
|
||||
assert data['data']['imperial_units'] is True
|
||||
assert data['data']['language'] == expected_language
|
||||
assert data['data'] == jsonify_dict(user_1.serialize(user_1))
|
||||
assert data['data']['timezone'] == 'America/New_York'
|
||||
assert data['data']['weekm'] is True
|
||||
|
||||
|
||||
class TestUserSportPreferencesUpdate(ApiTestCaseMixin):
|
||||
|
||||
@@ -67,6 +67,7 @@ class TestUserSerializeAsAuthUser(UserModelAssertMixin):
|
||||
assert serialized_user['language'] == user_1.language
|
||||
assert serialized_user['timezone'] == user_1.timezone
|
||||
assert serialized_user['weekm'] == user_1.weekm
|
||||
assert serialized_user['display_ascent'] == user_1.display_ascent
|
||||
|
||||
def test_it_returns_workouts_infos(self, app: Flask, user_1: User) -> None:
|
||||
serialized_user = user_1.serialize(user_1)
|
||||
|
||||
@@ -56,7 +56,7 @@ def assert_workout_data_with_gpx(data: Dict) -> None:
|
||||
assert segment['pauses'] is None
|
||||
|
||||
records = data['data']['workouts'][0]['records']
|
||||
assert len(records) == 4
|
||||
assert len(records) == 5
|
||||
assert records[0]['sport_id'] == 1
|
||||
assert records[0]['workout_id'] == data['data']['workouts'][0]['id']
|
||||
assert records[0]['record_type'] == 'MS'
|
||||
@@ -69,14 +69,19 @@ def assert_workout_data_with_gpx(data: Dict) -> None:
|
||||
assert records[1]['value'] == '0:04:10'
|
||||
assert records[2]['sport_id'] == 1
|
||||
assert records[2]['workout_id'] == data['data']['workouts'][0]['id']
|
||||
assert records[2]['record_type'] == 'FD'
|
||||
assert records[2]['record_type'] == 'HA'
|
||||
assert records[2]['value'] == 0.4
|
||||
assert records[2]['workout_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[2]['value'] == 0.32
|
||||
assert records[3]['sport_id'] == 1
|
||||
assert records[3]['workout_id'] == data['data']['workouts'][0]['id']
|
||||
assert records[3]['record_type'] == 'AS'
|
||||
assert records[3]['record_type'] == 'FD'
|
||||
assert records[3]['workout_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[3]['value'] == 4.61
|
||||
assert records[3]['value'] == 0.32
|
||||
assert records[4]['sport_id'] == 1
|
||||
assert records[4]['workout_id'] == data['data']['workouts'][0]['id']
|
||||
assert records[4]['record_type'] == 'AS'
|
||||
assert records[4]['workout_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[4]['value'] == 4.61
|
||||
|
||||
|
||||
def assert_workout_data_with_gpx_segments(data: Dict) -> None:
|
||||
@@ -133,7 +138,7 @@ def assert_workout_data_with_gpx_segments(data: Dict) -> None:
|
||||
assert segment['pauses'] is None
|
||||
|
||||
records = data['data']['workouts'][0]['records']
|
||||
assert len(records) == 4
|
||||
assert len(records) == 5
|
||||
assert records[0]['sport_id'] == 1
|
||||
assert records[0]['workout_id'] == data['data']['workouts'][0]['id']
|
||||
assert records[0]['record_type'] == 'MS'
|
||||
@@ -146,14 +151,18 @@ def assert_workout_data_with_gpx_segments(data: Dict) -> None:
|
||||
assert records[1]['value'] == '0:03:55'
|
||||
assert records[2]['sport_id'] == 1
|
||||
assert records[2]['workout_id'] == data['data']['workouts'][0]['id']
|
||||
assert records[2]['record_type'] == 'FD'
|
||||
assert records[2]['record_type'] == 'HA'
|
||||
assert records[2]['workout_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[2]['value'] == 0.3
|
||||
assert records[3]['sport_id'] == 1
|
||||
assert records[3]['workout_id'] == data['data']['workouts'][0]['id']
|
||||
assert records[3]['record_type'] == 'AS'
|
||||
assert records[3]['record_type'] == 'FD'
|
||||
assert records[3]['workout_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[3]['value'] == 4.59
|
||||
assert records[3]['value'] == 0.3
|
||||
assert records[4]['sport_id'] == 1
|
||||
assert records[4]['workout_id'] == data['data']['workouts'][0]['id']
|
||||
assert records[4]['record_type'] == 'AS'
|
||||
assert records[4]['workout_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[4]['value'] == 4.59
|
||||
|
||||
|
||||
def assert_workout_data_wo_gpx(data: Dict) -> None:
|
||||
@@ -252,6 +261,39 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
|
||||
assert 'just a workout' == data['data']['workouts'][0]['title']
|
||||
assert_workout_data_with_gpx(data)
|
||||
|
||||
def test_it_returns_ha_record_when_a_workout_without_gpx_exists(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
gpx_file: str,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
app, user_1.email
|
||||
)
|
||||
|
||||
response = client.post(
|
||||
'/api/workouts',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
data='{"sport_id": 1}',
|
||||
),
|
||||
headers=dict(
|
||||
content_type='multipart/form-data',
|
||||
Authorization=f'Bearer {auth_token}',
|
||||
),
|
||||
)
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
records = data['data']['workouts'][0]['records']
|
||||
assert len(records) == 1
|
||||
assert records[0]['sport_id'] == 1
|
||||
assert records[0]['workout_id'] == data['data']['workouts'][0]['id']
|
||||
assert records[0]['record_type'] == 'HA'
|
||||
assert records[0]['value'] == 0.4
|
||||
assert records[0]['workout_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
|
||||
def test_it_creates_workout_with_expecting_gpx_path(
|
||||
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
|
||||
) -> None:
|
||||
|
||||
@@ -32,7 +32,7 @@ def assert_workout_data_with_gpx(data: Dict, sport_id: int) -> None:
|
||||
assert data['data']['workouts'][0]['with_gpx'] is True
|
||||
|
||||
records = data['data']['workouts'][0]['records']
|
||||
assert len(records) == 4
|
||||
assert len(records) == 5
|
||||
assert records[0]['sport_id'] == sport_id
|
||||
assert records[0]['workout_id'] == data['data']['workouts'][0]['id']
|
||||
assert records[0]['record_type'] == 'MS'
|
||||
@@ -45,14 +45,18 @@ def assert_workout_data_with_gpx(data: Dict, sport_id: int) -> None:
|
||||
assert records[1]['value'] == '0:04:10'
|
||||
assert records[2]['sport_id'] == sport_id
|
||||
assert records[2]['workout_id'] == data['data']['workouts'][0]['id']
|
||||
assert records[2]['record_type'] == 'FD'
|
||||
assert records[2]['record_type'] == 'HA'
|
||||
assert records[2]['workout_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[2]['value'] == 0.32
|
||||
assert records[3]['sport_id'] == sport_id
|
||||
assert records[3]['workout_id'] == data['data']['workouts'][0]['id']
|
||||
assert records[3]['record_type'] == 'AS'
|
||||
assert records[3]['record_type'] == 'FD'
|
||||
assert records[3]['workout_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[3]['value'] == 4.61
|
||||
assert records[3]['value'] == 0.32
|
||||
assert records[4]['sport_id'] == sport_id
|
||||
assert records[4]['workout_id'] == data['data']['workouts'][0]['id']
|
||||
assert records[4]['record_type'] == 'AS'
|
||||
assert records[4]['workout_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[4]['value'] == 4.61
|
||||
|
||||
|
||||
class TestEditWorkoutWithGpx(ApiTestCaseMixin):
|
||||
|
||||
@@ -290,6 +290,7 @@ def get_authenticated_user_profile(
|
||||
"bio": null,
|
||||
"birth_date": null,
|
||||
"created_at": "Sun, 14 Jul 2019 14:09:58 GMT",
|
||||
"display_ascent": true,
|
||||
"email": "sam@example.com",
|
||||
"first_name": null,
|
||||
"imperial_units": false,
|
||||
@@ -319,6 +320,15 @@ def get_authenticated_user_profile(
|
||||
"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",
|
||||
@@ -390,6 +400,7 @@ def edit_user(auth_user: User) -> Union[Dict, HttpResponse]:
|
||||
"bio": null,
|
||||
"birth_date": null,
|
||||
"created_at": "Sun, 14 Jul 2019 14:09:58 GMT",
|
||||
"display_ascent": true,
|
||||
"email": "sam@example.com",
|
||||
"first_name": null,
|
||||
"imperial_units": false,
|
||||
@@ -419,6 +430,15 @@ def edit_user(auth_user: User) -> Union[Dict, HttpResponse]:
|
||||
"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",
|
||||
@@ -546,6 +566,7 @@ def update_user_account(auth_user: User) -> Union[Dict, HttpResponse]:
|
||||
"bio": null,
|
||||
"birth_date": null,
|
||||
"created_at": "Sun, 14 Jul 2019 14:09:58 GMT",
|
||||
"display_ascent": true,
|
||||
"email": "sam@example.com",
|
||||
"first_name": null,
|
||||
"imperial_units": false,
|
||||
@@ -575,6 +596,15 @@ def update_user_account(auth_user: User) -> Union[Dict, HttpResponse]:
|
||||
"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",
|
||||
@@ -746,6 +776,7 @@ def edit_user_preferences(auth_user: User) -> Union[Dict, HttpResponse]:
|
||||
"bio": null,
|
||||
"birth_date": null,
|
||||
"created_at": "Sun, 14 Jul 2019 14:09:58 GMT",
|
||||
"display_ascent": true,
|
||||
"email": "sam@example.com",
|
||||
"first_name": null,
|
||||
"imperial_units": false,
|
||||
@@ -775,6 +806,15 @@ def edit_user_preferences(auth_user: User) -> Union[Dict, HttpResponse]:
|
||||
"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",
|
||||
@@ -809,10 +849,11 @@ def edit_user_preferences(auth_user: User) -> Union[Dict, HttpResponse]:
|
||||
"status": "success"
|
||||
}
|
||||
|
||||
:<json boolean display_ascent: display highest ascent records
|
||||
:<json boolean imperial_units: display distance in imperial units
|
||||
:<json string language: language preferences
|
||||
:<json string timezone: user time zone
|
||||
:<json boolean weekm: does week start on Monday?
|
||||
:<json string language: language preferences
|
||||
:<json boolean imperial_units: display distance in imperial units
|
||||
|
||||
:reqheader Authorization: OAuth 2.0 Bearer Token
|
||||
|
||||
@@ -830,6 +871,7 @@ def edit_user_preferences(auth_user: User) -> Union[Dict, HttpResponse]:
|
||||
# get post data
|
||||
post_data = request.get_json()
|
||||
user_mandatory_data = {
|
||||
'display_ascent',
|
||||
'imperial_units',
|
||||
'language',
|
||||
'timezone',
|
||||
@@ -838,12 +880,14 @@ def edit_user_preferences(auth_user: User) -> Union[Dict, HttpResponse]:
|
||||
if not post_data or not post_data.keys() >= user_mandatory_data:
|
||||
return InvalidPayloadErrorResponse()
|
||||
|
||||
display_ascent = post_data.get('display_ascent')
|
||||
imperial_units = post_data.get('imperial_units')
|
||||
language = get_language(post_data.get('language'))
|
||||
timezone = post_data.get('timezone')
|
||||
weekm = post_data.get('weekm')
|
||||
|
||||
try:
|
||||
auth_user.display_ascent = display_ascent
|
||||
auth_user.imperial_units = imperial_units
|
||||
auth_user.language = language
|
||||
auth_user.timezone = timezone
|
||||
|
||||
@@ -50,6 +50,7 @@ class User(BaseModel):
|
||||
is_active = db.Column(db.Boolean, default=False, nullable=False)
|
||||
email_to_confirm = db.Column(db.String(255), nullable=True)
|
||||
confirmation_token = db.Column(db.String(255), nullable=True)
|
||||
display_ascent = db.Column(db.Boolean, default=True, nullable=False)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f'<User {self.username!r}>'
|
||||
@@ -173,6 +174,7 @@ class User(BaseModel):
|
||||
serialized_user = {
|
||||
**serialized_user,
|
||||
**{
|
||||
'display_ascent': self.display_ascent,
|
||||
'imperial_units': self.imperial_units,
|
||||
'language': self.language,
|
||||
'timezone': self.timezone,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user