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',
|
||||
avghr=None,avgpwr=None,avgspm=None,
|
||||
rankingpiece = False,
|
||||
duplicate=False,
|
||||
title='Manual entry',notes='',weightcategory='hwt'):
|
||||
|
||||
|
||||
@@ -813,6 +814,7 @@ def create_row_df(r,distance,duration,startdatetime,workouttype='rower',
|
||||
title=title,
|
||||
notes=notes,
|
||||
rankingpiece=rankingpiece,
|
||||
duplicate=duplicate,
|
||||
dosmooth=False,
|
||||
workouttype=workouttype,
|
||||
consistencychecks=False,
|
||||
@@ -829,6 +831,7 @@ def save_workout_database(f2, r, dosmooth=True, workouttype='rower',
|
||||
workoutsource='unknown',
|
||||
notes='', totaldist=0, totaltime=0,
|
||||
rankingpiece=False,
|
||||
duplicate=False,
|
||||
summary='',
|
||||
makeprivate=False,
|
||||
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)
|
||||
averagehr = np.nan_to_num(averagehr)
|
||||
|
||||
duplicate = False
|
||||
|
||||
t = datetime.datetime.strptime(duration,"%H:%M:%S.%f")
|
||||
delta = datetime.timedelta(hours=t.hour, minutes=t.minute, seconds=t.second)
|
||||
|
||||
@@ -41,6 +41,50 @@ workouttypes = (
|
||||
('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 = {
|
||||
'water':'water',
|
||||
'rower':'rower',
|
||||
@@ -87,6 +131,8 @@ c2mapping = {
|
||||
|
||||
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 = (
|
||||
'water',
|
||||
'coastal',
|
||||
|
||||
@@ -18,7 +18,7 @@ from stravalib.exc import ActivityUploadFailed,TimeoutExceeded
|
||||
from iso8601 import ParseError
|
||||
from utils import myqueue
|
||||
|
||||
|
||||
import mytypes
|
||||
import gzip
|
||||
|
||||
from rowsandall_app.settings import (
|
||||
@@ -163,7 +163,7 @@ def create_async_workout(alldata,user,stravaid,debug=False):
|
||||
distance = data['distance']
|
||||
stravaid = data['id']
|
||||
try:
|
||||
workouttype = data['type']
|
||||
workouttype = mytypes.stravamappinginv[data['type']]
|
||||
except:
|
||||
workouttype = 'rower'
|
||||
|
||||
@@ -444,14 +444,15 @@ def add_workout_from_data(user,importid,data,strokedata,
|
||||
source='strava',splitdata=None,
|
||||
workoutsource='strava'):
|
||||
try:
|
||||
workouttype = data['type']
|
||||
workouttype = mytypes.stravamappinginv[data['type']]
|
||||
except KeyError:
|
||||
workouttype = 'rower'
|
||||
|
||||
if workouttype.lower() == 'rowing':
|
||||
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]:
|
||||
workouttype = 'other'
|
||||
|
||||
@@ -1733,6 +1733,12 @@ def workout_strava_upload_view(request,id=0):
|
||||
message = ""
|
||||
r = getrower(request.user)
|
||||
res = -1
|
||||
|
||||
try:
|
||||
thetoken = strava_open(request.user)
|
||||
except NoTokenError:
|
||||
return HttpResponseRedirect("/rowers/me/stravaauthorize")
|
||||
|
||||
if (r.stravatoken == '') or (r.stravatoken is None):
|
||||
s = "Token doesn't exist. Need to authorize"
|
||||
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'
|
||||
except TypeError:
|
||||
newnotes = 'from '+w.workoutsource+' via rowsandall.com'
|
||||
activity_type = r.stravaexportas
|
||||
res,mes = stravastuff.handle_stravaexport(f,w.name,
|
||||
r.stravatoken,
|
||||
description=newnotes,
|
||||
activity_type=activity_type)
|
||||
if w.workouttype in mytypes.rowtypes:
|
||||
activity_type = r.stravaexportas
|
||||
else:
|
||||
activity_type = mytypes.stravamapping[w.workouttype]
|
||||
|
||||
res,mes = stravastuff.handle_stravaexport(
|
||||
f,w.name,
|
||||
r.stravatoken,
|
||||
description=newnotes,
|
||||
activity_type=activity_type)
|
||||
if res==0:
|
||||
messages.error(request,mes)
|
||||
w.uploadedtostrava = -1
|
||||
@@ -10871,7 +10882,7 @@ def workout_getimportview(request,externalid,source = 'c2'):
|
||||
|
||||
return HttpResponseRedirect(url)
|
||||
|
||||
# strokdata not empty - continue
|
||||
# strokedata not empty - continue
|
||||
id,message = importsources[source].add_workout_from_data(
|
||||
request.user,
|
||||
externalid,data,
|
||||
|
||||
Reference in New Issue
Block a user