strava working
This commit is contained in:
@@ -741,6 +741,7 @@ def fetchcp(rower,theworkouts,table='cpdata'):
|
|||||||
def create_row_df(r,distance,duration,startdatetime,workouttype='rower',
|
def create_row_df(r,distance,duration,startdatetime,workouttype='rower',
|
||||||
avghr=None,avgpwr=None,avgspm=None,
|
avghr=None,avgpwr=None,avgspm=None,
|
||||||
rankingpiece = False,
|
rankingpiece = False,
|
||||||
|
duplicate=False,
|
||||||
title='Manual entry',notes='',weightcategory='hwt'):
|
title='Manual entry',notes='',weightcategory='hwt'):
|
||||||
|
|
||||||
|
|
||||||
@@ -813,6 +814,7 @@ def create_row_df(r,distance,duration,startdatetime,workouttype='rower',
|
|||||||
title=title,
|
title=title,
|
||||||
notes=notes,
|
notes=notes,
|
||||||
rankingpiece=rankingpiece,
|
rankingpiece=rankingpiece,
|
||||||
|
duplicate=duplicate,
|
||||||
dosmooth=False,
|
dosmooth=False,
|
||||||
workouttype=workouttype,
|
workouttype=workouttype,
|
||||||
consistencychecks=False,
|
consistencychecks=False,
|
||||||
@@ -829,6 +831,7 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
|
|||||||
workoutsource='unknown',
|
workoutsource='unknown',
|
||||||
notes='', totaldist=0, totaltime=0,
|
notes='', totaldist=0, totaltime=0,
|
||||||
rankingpiece=False,
|
rankingpiece=False,
|
||||||
|
duplicate=False,
|
||||||
summary='',
|
summary='',
|
||||||
makeprivate=False,
|
makeprivate=False,
|
||||||
oarlength=2.89, inboard=0.88,
|
oarlength=2.89, inboard=0.88,
|
||||||
@@ -999,7 +1002,6 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
|
|||||||
maxhr = np.nan_to_num(maxhr)
|
maxhr = np.nan_to_num(maxhr)
|
||||||
averagehr = np.nan_to_num(averagehr)
|
averagehr = np.nan_to_num(averagehr)
|
||||||
|
|
||||||
duplicate = False
|
|
||||||
|
|
||||||
t = datetime.datetime.strptime(duration,"%H:%M:%S.%f")
|
t = datetime.datetime.strptime(duration,"%H:%M:%S.%f")
|
||||||
delta = datetime.timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)
|
delta = datetime.timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)
|
||||||
|
|||||||
@@ -41,6 +41,50 @@ workouttypes = (
|
|||||||
('other','Other'),
|
('other','Other'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
stravamapping = {
|
||||||
|
'water':'Rowing',
|
||||||
|
'rower':'Rowing',
|
||||||
|
'skierg':'NordicSki',
|
||||||
|
'bike':'Ride',
|
||||||
|
'dynamic':'Rowing',
|
||||||
|
'slides':'Rowing',
|
||||||
|
'paddle':'StandUpPaddling',
|
||||||
|
'snow':'NordicSki',
|
||||||
|
'coastal':'Rowing',
|
||||||
|
'c-boat':'Rowing',
|
||||||
|
'churchboat':'Rowing',
|
||||||
|
'Ride':'Ride',
|
||||||
|
'Kitesurf':'Kitesurf',
|
||||||
|
'Run':'Run',
|
||||||
|
'NordicSki':'NordicSki',
|
||||||
|
'Swim':'Swim',
|
||||||
|
'RockClimbing':'RockClimbing',
|
||||||
|
'Hike':'Hike',
|
||||||
|
'RollerSki':'RollerSki',
|
||||||
|
'Walk':'Walk',
|
||||||
|
'AlpineSki':'AlpineSki',
|
||||||
|
'Snowboard':'Snowboard',
|
||||||
|
'BackcountrySki':'BackcountrySki',
|
||||||
|
'Snowshoe':'Snowshoe',
|
||||||
|
'Canoeing':'Canoeing',
|
||||||
|
'StairStepper':'StairStepper',
|
||||||
|
'Crossfit':'Crossfit',
|
||||||
|
'StandUpPaddling':'StandUpPaddling',
|
||||||
|
'EBikeRide':'EBikeRide',
|
||||||
|
'Surfing':'Surfing',
|
||||||
|
'Elliptical':'Elliptical',
|
||||||
|
'VirtualRide':'VirtualRide',
|
||||||
|
'IceSkate':'IceSkate',
|
||||||
|
'WeightTraining':'WeightTraining',
|
||||||
|
'InlineSkate':'InlineSkate',
|
||||||
|
'Windsurf':'Windsurf',
|
||||||
|
'Kayaking':'Kayaking',
|
||||||
|
'Workout':'Workout',
|
||||||
|
'Yoga':'Yoga',
|
||||||
|
'other':'Workout',
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
c2mapping = {
|
c2mapping = {
|
||||||
'water':'water',
|
'water':'water',
|
||||||
'rower':'rower',
|
'rower':'rower',
|
||||||
@@ -87,6 +131,8 @@ c2mapping = {
|
|||||||
|
|
||||||
c2mappinginv = {value:key for key,value in c2mapping.iteritems() if value is not None}
|
c2mappinginv = {value:key for key,value in c2mapping.iteritems() if value is not None}
|
||||||
|
|
||||||
|
stravamappinginv = {value:key for key,value in stravamapping.iteritems() if value is not None}
|
||||||
|
|
||||||
otwtypes = (
|
otwtypes = (
|
||||||
'water',
|
'water',
|
||||||
'coastal',
|
'coastal',
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from stravalib.exc import ActivityUploadFailed,TimeoutExceeded
|
|||||||
from iso8601 import ParseError
|
from iso8601 import ParseError
|
||||||
from utils import myqueue
|
from utils import myqueue
|
||||||
|
|
||||||
|
import mytypes
|
||||||
import gzip
|
import gzip
|
||||||
|
|
||||||
from rowsandall_app.settings import (
|
from rowsandall_app.settings import (
|
||||||
@@ -163,7 +163,7 @@ def create_async_workout(alldata,user,stravaid,debug=False):
|
|||||||
distance = data['distance']
|
distance = data['distance']
|
||||||
stravaid = data['id']
|
stravaid = data['id']
|
||||||
try:
|
try:
|
||||||
workouttype = data['type']
|
workouttype = mytypes.stravamappinginv[data['type']]
|
||||||
except:
|
except:
|
||||||
workouttype = 'rower'
|
workouttype = 'rower'
|
||||||
|
|
||||||
@@ -444,14 +444,15 @@ def add_workout_from_data(user,importid,data,strokedata,
|
|||||||
source='strava',splitdata=None,
|
source='strava',splitdata=None,
|
||||||
workoutsource='strava'):
|
workoutsource='strava'):
|
||||||
try:
|
try:
|
||||||
workouttype = data['type']
|
workouttype = mytypes.stravamappinginv[data['type']]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
workouttype = 'rower'
|
workouttype = 'rower'
|
||||||
|
|
||||||
if workouttype.lower() == 'rowing':
|
if workouttype.lower() == 'rowing':
|
||||||
workouttype = 'rower'
|
workouttype = 'rower'
|
||||||
if 'summary_polyline' in data['map']:
|
|
||||||
workouttype = 'water'
|
if 'summary_polyline' in data['map'] and workouttype=='rower':
|
||||||
|
workouttype = 'water'
|
||||||
|
|
||||||
if workouttype not in [x[0] for x in Workout.workouttypes]:
|
if workouttype not in [x[0] for x in Workout.workouttypes]:
|
||||||
workouttype = 'other'
|
workouttype = 'other'
|
||||||
|
|||||||
@@ -1733,6 +1733,12 @@ def workout_strava_upload_view(request,id=0):
|
|||||||
message = ""
|
message = ""
|
||||||
r = getrower(request.user)
|
r = getrower(request.user)
|
||||||
res = -1
|
res = -1
|
||||||
|
|
||||||
|
try:
|
||||||
|
thetoken = strava_open(request.user)
|
||||||
|
except NoTokenError:
|
||||||
|
return HttpResponseRedirect("/rowers/me/stravaauthorize")
|
||||||
|
|
||||||
if (r.stravatoken == '') or (r.stravatoken is None):
|
if (r.stravatoken == '') or (r.stravatoken is None):
|
||||||
s = "Token doesn't exist. Need to authorize"
|
s = "Token doesn't exist. Need to authorize"
|
||||||
return HttpResponseRedirect("/rowers/me/stravaauthorize/")
|
return HttpResponseRedirect("/rowers/me/stravaauthorize/")
|
||||||
@@ -1749,11 +1755,16 @@ def workout_strava_upload_view(request,id=0):
|
|||||||
newnotes = w.notes+'\n from '+w.workoutsource+' via rowsandall.com'
|
newnotes = w.notes+'\n from '+w.workoutsource+' via rowsandall.com'
|
||||||
except TypeError:
|
except TypeError:
|
||||||
newnotes = 'from '+w.workoutsource+' via rowsandall.com'
|
newnotes = 'from '+w.workoutsource+' via rowsandall.com'
|
||||||
activity_type = r.stravaexportas
|
if w.workouttype in mytypes.rowtypes:
|
||||||
res,mes = stravastuff.handle_stravaexport(f,w.name,
|
activity_type = r.stravaexportas
|
||||||
r.stravatoken,
|
else:
|
||||||
description=newnotes,
|
activity_type = mytypes.stravamapping[w.workouttype]
|
||||||
activity_type=activity_type)
|
|
||||||
|
res,mes = stravastuff.handle_stravaexport(
|
||||||
|
f,w.name,
|
||||||
|
r.stravatoken,
|
||||||
|
description=newnotes,
|
||||||
|
activity_type=activity_type)
|
||||||
if res==0:
|
if res==0:
|
||||||
messages.error(request,mes)
|
messages.error(request,mes)
|
||||||
w.uploadedtostrava = -1
|
w.uploadedtostrava = -1
|
||||||
@@ -10871,7 +10882,7 @@ def workout_getimportview(request,externalid,source = 'c2'):
|
|||||||
|
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
# strokdata not empty - continue
|
# strokedata not empty - continue
|
||||||
id,message = importsources[source].add_workout_from_data(
|
id,message = importsources[source].add_workout_from_data(
|
||||||
request.user,
|
request.user,
|
||||||
externalid,data,
|
externalid,data,
|
||||||
|
|||||||
Reference in New Issue
Block a user