Merge branch 'feature/errors' into develop
This commit is contained in:
@@ -106,7 +106,7 @@ class TemplateListField(models.TextField):
|
|||||||
|
|
||||||
return value.split(self.token)
|
return value.split(self.token)
|
||||||
|
|
||||||
def from_db_value(self,value, expression, connection, context):
|
def from_db_value(self,value, expression, connection):
|
||||||
if value is None:
|
if value is None:
|
||||||
return value
|
return value
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
@@ -149,7 +149,7 @@ class PowerZonesField(models.TextField):
|
|||||||
|
|
||||||
return value.split(self.token)
|
return value.split(self.token)
|
||||||
|
|
||||||
def from_db_value(self,value, expression, connection, context):
|
def from_db_value(self,value, expression, connection):
|
||||||
if value is None:
|
if value is None:
|
||||||
return value
|
return value
|
||||||
if isinstance(value, list):
|
if isinstance(value, list):
|
||||||
@@ -3030,7 +3030,6 @@ strokedatafields = {
|
|||||||
'hr_an':models.IntegerField(null=True),
|
'hr_an':models.IntegerField(null=True),
|
||||||
'hr_max':models.IntegerField(null=True),
|
'hr_max':models.IntegerField(null=True),
|
||||||
'hr_bottom':models.IntegerField(null=True),
|
'hr_bottom':models.IntegerField(null=True),
|
||||||
'x_right':models.FloatField(null=True),
|
|
||||||
'ergpace':models.FloatField(null=True),
|
'ergpace':models.FloatField(null=True),
|
||||||
'nowindpace':models.FloatField(null=True),
|
'nowindpace':models.FloatField(null=True),
|
||||||
'equivergpower':models.FloatField(null=True),
|
'equivergpower':models.FloatField(null=True),
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from __future__ import division
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
from __future__ import unicode_literals, absolute_import
|
from __future__ import unicode_literals, absolute_import
|
||||||
# Interactions with Rowsandall.com API. Not fully complete.
|
# Interactions with Rowsandall.com API. Not fully complete.
|
||||||
|
|
||||||
# Python
|
# Python
|
||||||
import oauth2 as oauth
|
import oauth2 as oauth
|
||||||
@@ -72,7 +72,7 @@ def do_refresh_token(refreshtoken):
|
|||||||
'Content-Type': 'application/json'}
|
'Content-Type': 'application/json'}
|
||||||
|
|
||||||
url = "http://localhost:8000/rowers/o/token"
|
url = "http://localhost:8000/rowers/o/token"
|
||||||
|
|
||||||
response = requests.post(url,
|
response = requests.post(url,
|
||||||
data=json.dumps(post_data),
|
data=json.dumps(post_data),
|
||||||
headers=headers)
|
headers=headers)
|
||||||
@@ -94,14 +94,14 @@ def get_token(code):
|
|||||||
"code": code,
|
"code": code,
|
||||||
"redirect_uri": "http://localhost:8000/rowers/test_callback",
|
"redirect_uri": "http://localhost:8000/rowers/test_callback",
|
||||||
"client_secret": "aapnootmies",
|
"client_secret": "aapnootmies",
|
||||||
"client_id":1,
|
"client_id":1,
|
||||||
}
|
}
|
||||||
headers = {'Accept': 'application/json',
|
headers = {'Accept': 'application/json',
|
||||||
'Content-Type': 'application/json'}
|
'Content-Type': 'application/json'}
|
||||||
|
|
||||||
url = "http://localhost:8000/rowers/o/token/"
|
url = "http://localhost:8000/rowers/o/token/"
|
||||||
|
|
||||||
|
|
||||||
response = requests.post(url,
|
response = requests.post(url,
|
||||||
data=json.dumps(post_data),
|
data=json.dumps(post_data),
|
||||||
headers=headers)
|
headers=headers)
|
||||||
@@ -111,7 +111,7 @@ def get_token(code):
|
|||||||
expires_in = token_json['expires_in']
|
expires_in = token_json['expires_in']
|
||||||
refresh_token = token_json['refresh_token']
|
refresh_token = token_json['refresh_token']
|
||||||
|
|
||||||
|
|
||||||
return [thetoken,expires_in,refresh_token]
|
return [thetoken,expires_in,refresh_token]
|
||||||
|
|
||||||
def make_authorization_url(request):
|
def make_authorization_url(request):
|
||||||
@@ -190,7 +190,7 @@ def get_ownapi_workout(user,ownapiid):
|
|||||||
|
|
||||||
def createownapiworkoutdata(w):
|
def createownapiworkoutdata(w):
|
||||||
filename = w.csvfilename
|
filename = w.csvfilename
|
||||||
row = rowingdata(filename)
|
row = rowingdata(csvfile=filename)
|
||||||
averagehr = int(row.df[' HRCur (bpm)'].mean())
|
averagehr = int(row.df[' HRCur (bpm)'].mean())
|
||||||
maxhr = int(row.df[' HRCur (bpm)'].max())
|
maxhr = int(row.df[' HRCur (bpm)'].max())
|
||||||
|
|
||||||
@@ -206,7 +206,7 @@ def createownapiworkoutdata(w):
|
|||||||
hr = row.df[' HRCur (bpm)'].astype(int)
|
hr = row.df[' HRCur (bpm)'].astype(int)
|
||||||
|
|
||||||
haslatlon=1
|
haslatlon=1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
lat = row.df[' latitude'].values
|
lat = row.df[' latitude'].values
|
||||||
lon = row.df[' longitude'].values
|
lon = row.df[' longitude'].values
|
||||||
@@ -281,7 +281,5 @@ def getidfromresponse(response):
|
|||||||
t = json.loads(response.text)
|
t = json.loads(response.text)
|
||||||
uri = t['uris'][0]
|
uri = t['uris'][0]
|
||||||
id = uri[len(uri)-13:len(uri)-5]
|
id = uri[len(uri)-13:len(uri)-5]
|
||||||
|
|
||||||
return int(id)
|
|
||||||
|
|
||||||
|
return int(id)
|
||||||
|
|||||||
@@ -104,17 +104,17 @@ def get_workout(user,runkeeperid):
|
|||||||
strokedata = pd.DataFrame.from_dict({
|
strokedata = pd.DataFrame.from_dict({
|
||||||
key: pd.Series(value) for key, value in data.items()
|
key: pd.Series(value) for key, value in data.items()
|
||||||
})
|
})
|
||||||
|
|
||||||
return data,strokedata
|
return data,strokedata
|
||||||
|
|
||||||
# Create Workout Data for upload to SportTracks
|
# Create Workout Data for upload to SportTracks
|
||||||
def createrunkeeperworkoutdata(w):
|
def createrunkeeperworkoutdata(w):
|
||||||
filename = w.csvfilename
|
filename = w.csvfilename
|
||||||
try:
|
try:
|
||||||
row = rowingdata(filename)
|
row = rowingdata(csvfile=filename)
|
||||||
except:
|
except:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
averagehr = int(row.df[' HRCur (bpm)'].mean())
|
averagehr = int(row.df[' HRCur (bpm)'].mean())
|
||||||
maxhr = int(row.df[' HRCur (bpm)'].max())
|
maxhr = int(row.df[' HRCur (bpm)'].max())
|
||||||
duration = w.duration.hour*3600
|
duration = w.duration.hour*3600
|
||||||
@@ -134,9 +134,9 @@ def createrunkeeperworkoutdata(w):
|
|||||||
spm = row.df[' Cadence (stokes/min)'].astype(int)
|
spm = row.df[' Cadence (stokes/min)'].astype(int)
|
||||||
spm[0] = spm[1]
|
spm[0] = spm[1]
|
||||||
hr = row.df[' HRCur (bpm)'].astype(int)
|
hr = row.df[' HRCur (bpm)'].astype(int)
|
||||||
|
|
||||||
haslatlon=1
|
haslatlon=1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
lat = row.df[' latitude'].values
|
lat = row.df[' latitude'].values
|
||||||
lon = row.df[' longitude'].values
|
lon = row.df[' longitude'].values
|
||||||
@@ -148,12 +148,12 @@ def createrunkeeperworkoutdata(w):
|
|||||||
t = t.tolist()
|
t = t.tolist()
|
||||||
hr = hr.tolist()
|
hr = hr.tolist()
|
||||||
d = d.tolist()
|
d = d.tolist()
|
||||||
|
|
||||||
# path data
|
# path data
|
||||||
if haslatlon:
|
if haslatlon:
|
||||||
lat = lat.tolist()
|
lat = lat.tolist()
|
||||||
lon = lon.tolist()
|
lon = lon.tolist()
|
||||||
locdata = []
|
locdata = []
|
||||||
for e in zip(t,lat,lon):
|
for e in zip(t,lat,lon):
|
||||||
point = {'timestamp':e[0],
|
point = {'timestamp':e[0],
|
||||||
'latitude':e[1],
|
'latitude':e[1],
|
||||||
@@ -183,7 +183,7 @@ def createrunkeeperworkoutdata(w):
|
|||||||
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'
|
||||||
|
|
||||||
if haslatlon:
|
if haslatlon:
|
||||||
data = {
|
data = {
|
||||||
"type": "Rowing",
|
"type": "Rowing",
|
||||||
@@ -222,7 +222,7 @@ def getidfromresponse(response):
|
|||||||
|
|
||||||
tester = re.compile('^\/fitnessActivities\/(\d+)$')
|
tester = re.compile('^\/fitnessActivities\/(\d+)$')
|
||||||
id = int(tester.match(uri).group(1))
|
id = int(tester.match(uri).group(1))
|
||||||
|
|
||||||
return int(id)
|
return int(id)
|
||||||
|
|
||||||
def geturifromid(access_token,id):
|
def geturifromid(access_token,id):
|
||||||
@@ -245,7 +245,7 @@ def geturifromid(access_token,id):
|
|||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
# Get user id, having access token
|
# Get user id, having access token
|
||||||
# Handy for checking if the API access is working
|
# Handy for checking if the API access is working
|
||||||
def get_userid(access_token):
|
def get_userid(access_token):
|
||||||
@@ -256,7 +256,7 @@ def get_userid(access_token):
|
|||||||
import urllib
|
import urllib
|
||||||
url = "https://api.runkeeper.com/user"
|
url = "https://api.runkeeper.com/user"
|
||||||
response = requests.get(url,headers=headers)
|
response = requests.get(url,headers=headers)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
me_json = response.json()
|
me_json = response.json()
|
||||||
@@ -271,7 +271,7 @@ def get_userid(access_token):
|
|||||||
return str(res)
|
return str(res)
|
||||||
|
|
||||||
def default(o):
|
def default(o):
|
||||||
if isinstance(o, numpy.int64): return int(o)
|
if isinstance(o, numpy.int64): return int(o)
|
||||||
raise TypeError
|
raise TypeError
|
||||||
|
|
||||||
def workout_runkeeper_upload(user,w):
|
def workout_runkeeper_upload(user,w):
|
||||||
@@ -280,7 +280,7 @@ def workout_runkeeper_upload(user,w):
|
|||||||
|
|
||||||
r = w.user
|
r = w.user
|
||||||
|
|
||||||
|
|
||||||
thetoken = runkeeper_open(r.user)
|
thetoken = runkeeper_open(r.user)
|
||||||
|
|
||||||
# ready to upload. Hurray
|
# ready to upload. Hurray
|
||||||
@@ -291,7 +291,7 @@ def workout_runkeeper_upload(user,w):
|
|||||||
message = "Data error in Runkeeper Upload"
|
message = "Data error in Runkeeper Upload"
|
||||||
rkid = 0
|
rkid = 0
|
||||||
return message, rkid
|
return message, rkid
|
||||||
|
|
||||||
authorizationstring = str('Bearer ' + thetoken)
|
authorizationstring = str('Bearer ' + thetoken)
|
||||||
headers = {'Authorization': authorizationstring,
|
headers = {'Authorization': authorizationstring,
|
||||||
'user-agent': 'sanderroosendaal',
|
'user-agent': 'sanderroosendaal',
|
||||||
@@ -319,7 +319,7 @@ def workout_runkeeper_upload(user,w):
|
|||||||
message = "Something went wrong in workout_runkeeper_upload_view: %s - %s" % (s.reason,s.text)
|
message = "Something went wrong in workout_runkeeper_upload_view: %s - %s" % (s.reason,s.text)
|
||||||
rkid = 0
|
rkid = 0
|
||||||
return message, rkid
|
return message, rkid
|
||||||
|
|
||||||
else:
|
else:
|
||||||
message = "You are not authorized to upload this workout"
|
message = "You are not authorized to upload this workout"
|
||||||
rkid = 0
|
rkid = 0
|
||||||
@@ -338,7 +338,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
|
|||||||
comments = data['notes']
|
comments = data['notes']
|
||||||
except:
|
except:
|
||||||
comments = ''
|
comments = ''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
utcoffset = tz(data['utcoffset'])
|
utcoffset = tz(data['utcoffset'])
|
||||||
except:
|
except:
|
||||||
@@ -362,8 +362,8 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
|
|||||||
starttimeunix = arrow.get(rowdatetime).timestamp
|
starttimeunix = arrow.get(rowdatetime).timestamp
|
||||||
#starttimeunix = mktime(rowdatetime.utctimetuple())
|
#starttimeunix = mktime(rowdatetime.utctimetuple())
|
||||||
starttimeunix += utcoffset*3600
|
starttimeunix += utcoffset*3600
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
title = data['name']
|
title = data['name']
|
||||||
except:
|
except:
|
||||||
@@ -378,7 +378,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
l = data['path']
|
l = data['path']
|
||||||
|
|
||||||
res = splitrunkeeperlatlongdata(l,'timestamp','latitude','longitude')
|
res = splitrunkeeperlatlongdata(l,'timestamp','latitude','longitude')
|
||||||
times_location = res[0]
|
times_location = res[0]
|
||||||
latcoord = res[1]
|
latcoord = res[1]
|
||||||
@@ -390,7 +390,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
|
|||||||
loncoord = np.zeros(len(times_distance))
|
loncoord = np.zeros(len(times_distance))
|
||||||
if workouttype in types.otwtypes:
|
if workouttype in types.otwtypes:
|
||||||
workouttype = 'rower'
|
workouttype = 'rower'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = splitrunkeeperdata(data['cadence'],'timestamp','cadence')
|
res = splitrunkeeperdata(data['cadence'],'timestamp','cadence')
|
||||||
times_spm = res[0]
|
times_spm = res[0]
|
||||||
@@ -398,7 +398,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
times_spm = times_distance
|
times_spm = times_distance
|
||||||
spm = 0*times_distance
|
spm = 0*times_distance
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = splitrunkeeperdata(data['heart_rate'],'timestamp','heart_rate')
|
res = splitrunkeeperdata(data['heart_rate'],'timestamp','heart_rate')
|
||||||
hr = res[1]
|
hr = res[1]
|
||||||
@@ -416,13 +416,13 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
|
|||||||
latseries = latseries.groupby(latseries.index).first()
|
latseries = latseries.groupby(latseries.index).first()
|
||||||
except TypeError:
|
except TypeError:
|
||||||
latseries = 0.0*distseries
|
latseries = 0.0*distseries
|
||||||
|
|
||||||
lonseries = pd.Series(loncoord,index=times_location)
|
lonseries = pd.Series(loncoord,index=times_location)
|
||||||
try:
|
try:
|
||||||
lonseries = lonseries.groupby(lonseries.index).first()
|
lonseries = lonseries.groupby(lonseries.index).first()
|
||||||
except TypeError:
|
except TypeError:
|
||||||
lonseries = 0.0*distseries
|
lonseries = 0.0*distseries
|
||||||
|
|
||||||
spmseries = pd.Series(spm,index=times_spm)
|
spmseries = pd.Series(spm,index=times_spm)
|
||||||
spmseries = spmseries.groupby(spmseries.index).first()
|
spmseries = spmseries.groupby(spmseries.index).first()
|
||||||
hrseries = pd.Series(hr,index=times_hr)
|
hrseries = pd.Series(hr,index=times_hr)
|
||||||
@@ -441,7 +441,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
|
|||||||
' HRCur (bpm)' : hrseries,
|
' HRCur (bpm)' : hrseries,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
df = pd.DataFrame(d)
|
df = pd.DataFrame(d)
|
||||||
|
|
||||||
@@ -451,7 +451,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
|
|||||||
df[' ElapsedTime (sec)'] = cum_time
|
df[' ElapsedTime (sec)'] = cum_time
|
||||||
|
|
||||||
velo = df[' Horizontal (meters)'].diff()/df[' ElapsedTime (sec)'].diff()
|
velo = df[' Horizontal (meters)'].diff()/df[' ElapsedTime (sec)'].diff()
|
||||||
|
|
||||||
df[' Power (watts)'] = 0.0*velo
|
df[' Power (watts)'] = 0.0*velo
|
||||||
|
|
||||||
nr_rows = len(velo.values)
|
nr_rows = len(velo.values)
|
||||||
@@ -471,10 +471,10 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
|
|||||||
unixtime[0] = starttimeunix
|
unixtime[0] = starttimeunix
|
||||||
except IndexError:
|
except IndexError:
|
||||||
return (0,'No data to import')
|
return (0,'No data to import')
|
||||||
|
|
||||||
df['TimeStamp (sec)'] = unixtime
|
df['TimeStamp (sec)'] = unixtime
|
||||||
|
|
||||||
|
|
||||||
dt = np.diff(cum_time).mean()
|
dt = np.diff(cum_time).mean()
|
||||||
wsize = round(5./dt)
|
wsize = round(5./dt)
|
||||||
|
|
||||||
@@ -486,7 +486,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
|
|||||||
df = df.fillna(0)
|
df = df.fillna(0)
|
||||||
|
|
||||||
df.sort_values(by='TimeStamp (sec)',ascending=True)
|
df.sort_values(by='TimeStamp (sec)',ascending=True)
|
||||||
|
|
||||||
timestr = strftime("%Y%m%d-%H%M%S")
|
timestr = strftime("%Y%m%d-%H%M%S")
|
||||||
|
|
||||||
# csvfilename ='media/Import_'+str(importid)+'.csv'
|
# csvfilename ='media/Import_'+str(importid)+'.csv'
|
||||||
@@ -505,4 +505,3 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
|
|||||||
notes=comments)
|
notes=comments)
|
||||||
|
|
||||||
return (id,message)
|
return (id,message)
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ def rower_sporttracks_token_refresh(user):
|
|||||||
r.sporttracksrefreshtoken = refresh_token
|
r.sporttracksrefreshtoken = refresh_token
|
||||||
|
|
||||||
r.save()
|
r.save()
|
||||||
|
|
||||||
return r.sporttrackstoken
|
return r.sporttrackstoken
|
||||||
|
|
||||||
# Get list of workouts available on SportTracks
|
# Get list of workouts available on SportTracks
|
||||||
@@ -117,10 +117,10 @@ def get_workout(user,sporttracksid):
|
|||||||
# Create Workout Data for upload to SportTracks
|
# Create Workout Data for upload to SportTracks
|
||||||
def createsporttracksworkoutdata(w):
|
def createsporttracksworkoutdata(w):
|
||||||
timezone = pytz.timezone(w.timezone)
|
timezone = pytz.timezone(w.timezone)
|
||||||
|
|
||||||
filename = w.csvfilename
|
filename = w.csvfilename
|
||||||
try:
|
try:
|
||||||
row = rowingdata(filename)
|
row = rowingdata(csvfile=filename)
|
||||||
except:
|
except:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@@ -130,7 +130,7 @@ def createsporttracksworkoutdata(w):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
averagehr = 0
|
averagehr = 0
|
||||||
maxhr = 0
|
maxhr = 0
|
||||||
|
|
||||||
duration = w.duration.hour*3600
|
duration = w.duration.hour*3600
|
||||||
duration += w.duration.minute*60
|
duration += w.duration.minute*60
|
||||||
duration += w.duration.second
|
duration += w.duration.second
|
||||||
@@ -148,9 +148,9 @@ def createsporttracksworkoutdata(w):
|
|||||||
spm = row.df[' Cadence (stokes/min)'].astype(int).values
|
spm = row.df[' Cadence (stokes/min)'].astype(int).values
|
||||||
spm[0] = spm[1]
|
spm[0] = spm[1]
|
||||||
hr = row.df[' HRCur (bpm)'].astype(int).values
|
hr = row.df[' HRCur (bpm)'].astype(int).values
|
||||||
|
|
||||||
haslatlon=1
|
haslatlon=1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
lat = row.df[' latitude'].values
|
lat = row.df[' latitude'].values
|
||||||
lon = row.df[' longitude'].values
|
lon = row.df[' longitude'].values
|
||||||
@@ -159,7 +159,7 @@ def createsporttracksworkoutdata(w):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
haslatlon = 0
|
haslatlon = 0
|
||||||
|
|
||||||
|
|
||||||
haspower = 1
|
haspower = 1
|
||||||
try:
|
try:
|
||||||
power = row.df[' Power (watts)'].astype(int).values
|
power = row.df[' Power (watts)'].astype(int).values
|
||||||
@@ -200,7 +200,7 @@ def createsporttracksworkoutdata(w):
|
|||||||
w.notes = w.notes+'\n from '+w.workoutsource+' via rowsandall.com'
|
w.notes = w.notes+'\n from '+w.workoutsource+' via rowsandall.com'
|
||||||
except TypeError:
|
except TypeError:
|
||||||
w.notes = 'from '+w.workoutsource+' via rowsandall.com'
|
w.notes = 'from '+w.workoutsource+' via rowsandall.com'
|
||||||
|
|
||||||
st = w.startdatetime.astimezone(timezone)
|
st = w.startdatetime.astimezone(timezone)
|
||||||
st = st.replace(microsecond=0)
|
st = st.replace(microsecond=0)
|
||||||
|
|
||||||
@@ -246,17 +246,17 @@ def getidfromresponse(response):
|
|||||||
uri = t['uris'][0]
|
uri = t['uris'][0]
|
||||||
regex = '.*?sporttracks\.mobi\/api\/v2\/fitnessActivities/(\d+)\.json$'
|
regex = '.*?sporttracks\.mobi\/api\/v2\/fitnessActivities/(\d+)\.json$'
|
||||||
m = re.compile(regex).match(uri).group(1)
|
m = re.compile(regex).match(uri).group(1)
|
||||||
|
|
||||||
id = int(m)
|
id = int(m)
|
||||||
|
|
||||||
return int(id)
|
return int(id)
|
||||||
|
|
||||||
def default(o):
|
def default(o):
|
||||||
if isinstance(o, numpy.int64): return int(o)
|
if isinstance(o, numpy.int64): return int(o)
|
||||||
raise TypeError
|
raise TypeError
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def workout_sporttracks_upload(user,w):
|
def workout_sporttracks_upload(user,w):
|
||||||
message = "Uploading to SportTracks"
|
message = "Uploading to SportTracks"
|
||||||
stid = 0
|
stid = 0
|
||||||
@@ -298,7 +298,7 @@ def workout_sporttracks_upload(user,w):
|
|||||||
message = "Something went wrong in workout_sporttracks_upload_view: %s" % s.reason
|
message = "Something went wrong in workout_sporttracks_upload_view: %s" % s.reason
|
||||||
stid = 0
|
stid = 0
|
||||||
return message,stid
|
return message,stid
|
||||||
|
|
||||||
else:
|
else:
|
||||||
message = "You are not authorized to upload this workout"
|
message = "You are not authorized to upload this workout"
|
||||||
stid = 0
|
stid = 0
|
||||||
@@ -314,7 +314,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='sporttracks',
|
|||||||
workouttype = data['type']
|
workouttype = data['type']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
workouttype = 'other'
|
workouttype = 'other'
|
||||||
|
|
||||||
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'
|
||||||
try:
|
try:
|
||||||
@@ -322,7 +322,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='sporttracks',
|
|||||||
except:
|
except:
|
||||||
comments = ''
|
comments = ''
|
||||||
|
|
||||||
|
|
||||||
r = Rower.objects.get(user=user)
|
r = Rower.objects.get(user=user)
|
||||||
try:
|
try:
|
||||||
rowdatetime = iso8601.parse_date(data['start_time'])
|
rowdatetime = iso8601.parse_date(data['start_time'])
|
||||||
@@ -359,7 +359,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='sporttracks',
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
l = data['location']
|
l = data['location']
|
||||||
|
|
||||||
res = splitstdata(l)
|
res = splitstdata(l)
|
||||||
times_location = res[0]
|
times_location = res[0]
|
||||||
latlong = res[1]
|
latlong = res[1]
|
||||||
@@ -377,7 +377,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='sporttracks',
|
|||||||
loncoord = np.zeros(len(times_distance))
|
loncoord = np.zeros(len(times_distance))
|
||||||
if workouttype in mytypes.otwtypes:
|
if workouttype in mytypes.otwtypes:
|
||||||
workouttype = 'rower'
|
workouttype = 'rower'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = splitstdata(data['cadence'])
|
res = splitstdata(data['cadence'])
|
||||||
times_spm = res[0]
|
times_spm = res[0]
|
||||||
@@ -385,7 +385,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='sporttracks',
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
times_spm = times_distance
|
times_spm = times_distance
|
||||||
spm = 0*times_distance
|
spm = 0*times_distance
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = splitstdata(data['heartrate'])
|
res = splitstdata(data['heartrate'])
|
||||||
hr = res[1]
|
hr = res[1]
|
||||||
@@ -417,7 +417,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='sporttracks',
|
|||||||
' HRCur (bpm)' : hrseries,
|
' HRCur (bpm)' : hrseries,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
df = pd.DataFrame(d)
|
df = pd.DataFrame(d)
|
||||||
|
|
||||||
@@ -427,7 +427,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='sporttracks',
|
|||||||
df[' ElapsedTime (sec)'] = cum_time
|
df[' ElapsedTime (sec)'] = cum_time
|
||||||
|
|
||||||
velo = df[' Horizontal (meters)'].diff()/df[' ElapsedTime (sec)'].diff()
|
velo = df[' Horizontal (meters)'].diff()/df[' ElapsedTime (sec)'].diff()
|
||||||
|
|
||||||
df[' Power (watts)'] = 0.0*velo
|
df[' Power (watts)'] = 0.0*velo
|
||||||
|
|
||||||
nr_rows = len(velo.values)
|
nr_rows = len(velo.values)
|
||||||
@@ -444,10 +444,10 @@ def add_workout_from_data(user,importid,data,strokedata,source='sporttracks',
|
|||||||
|
|
||||||
unixtime = cum_time+starttimeunix
|
unixtime = cum_time+starttimeunix
|
||||||
unixtime[0] = starttimeunix
|
unixtime[0] = starttimeunix
|
||||||
|
|
||||||
df['TimeStamp (sec)'] = unixtime
|
df['TimeStamp (sec)'] = unixtime
|
||||||
|
|
||||||
|
|
||||||
dt = np.diff(cum_time).mean()
|
dt = np.diff(cum_time).mean()
|
||||||
wsize = round(5./dt)
|
wsize = round(5./dt)
|
||||||
|
|
||||||
@@ -459,7 +459,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='sporttracks',
|
|||||||
df = df.fillna(0)
|
df = df.fillna(0)
|
||||||
|
|
||||||
df.sort_values(by='TimeStamp (sec)',ascending=True)
|
df.sort_values(by='TimeStamp (sec)',ascending=True)
|
||||||
|
|
||||||
timestr = strftime("%Y%m%d-%H%M%S")
|
timestr = strftime("%Y%m%d-%H%M%S")
|
||||||
|
|
||||||
# csvfilename ='media/Import_'+str(importid)+'.csv'
|
# csvfilename ='media/Import_'+str(importid)+'.csv'
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ def rower_strava_token_refresh(user):
|
|||||||
r.save()
|
r.save()
|
||||||
|
|
||||||
return r.stravatoken
|
return r.stravatoken
|
||||||
|
|
||||||
# Make authorization URL including random string
|
# Make authorization URL including random string
|
||||||
def make_authorization_url(request):
|
def make_authorization_url(request):
|
||||||
return imports_make_authorization_url(oauth_data)
|
return imports_make_authorization_url(oauth_data)
|
||||||
@@ -130,7 +130,7 @@ def get_strava_workouts(rower):
|
|||||||
thetoken = strava_open(rower.user)
|
thetoken = strava_open(rower.user)
|
||||||
except NoTokenError:
|
except NoTokenError:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
res = get_strava_workout_list(rower.user,limit_n=10)
|
res = get_strava_workout_list(rower.user,limit_n=10)
|
||||||
|
|
||||||
if (res.status_code != 200):
|
if (res.status_code != 200):
|
||||||
@@ -142,11 +142,11 @@ def get_strava_workouts(rower):
|
|||||||
'elapsed_time':item['elapsed_time'],
|
'elapsed_time':item['elapsed_time'],
|
||||||
'start_date':item['start_date'],
|
'start_date':item['start_date'],
|
||||||
} for item in res.json()]
|
} for item in res.json()]
|
||||||
|
|
||||||
alldata = {}
|
alldata = {}
|
||||||
for item in res.json():
|
for item in res.json():
|
||||||
alldata[item['id']] = item
|
alldata[item['id']] = item
|
||||||
|
|
||||||
|
|
||||||
wfailed = Workout.objects.filter(user=rower,uploadedtostrava=-1)
|
wfailed = Workout.objects.filter(user=rower,uploadedtostrava=-1)
|
||||||
|
|
||||||
@@ -159,12 +159,12 @@ def get_strava_workouts(rower):
|
|||||||
dd = datetime.min + timedelta(
|
dd = datetime.min + timedelta(
|
||||||
seconds=int(elapsed_time)
|
seconds=int(elapsed_time)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if datetime.time(dd) == w.duration:
|
if datetime.time(dd) == w.duration:
|
||||||
w.uploadedtostrava = int(stravaid)
|
w.uploadedtostrava = int(stravaid)
|
||||||
w.save()
|
w.save()
|
||||||
|
|
||||||
knownstravaids = [
|
knownstravaids = [
|
||||||
w.uploadedtostrava for w in Workout.objects.filter(user=rower)
|
w.uploadedtostrava for w in Workout.objects.filter(user=rower)
|
||||||
]
|
]
|
||||||
@@ -174,7 +174,7 @@ def get_strava_workouts(rower):
|
|||||||
]
|
]
|
||||||
|
|
||||||
knownstravaids = uniqify(knownstravaids+tombstones)
|
knownstravaids = uniqify(knownstravaids+tombstones)
|
||||||
|
|
||||||
newids = [stravaid for stravaid in stravaids if not stravaid in knownstravaids]
|
newids = [stravaid for stravaid in stravaids if not stravaid in knownstravaids]
|
||||||
|
|
||||||
for stravaid in newids:
|
for stravaid in newids:
|
||||||
@@ -220,10 +220,10 @@ def create_async_workout(alldata,user,stravaid,debug=False):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
c2intervaltype = data['workout_type']
|
c2intervaltype = data['workout_type']
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
c2intervaltype = ''
|
c2intervaltype = ''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
title = data['name']
|
title = data['name']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -237,22 +237,22 @@ def create_async_workout(alldata,user,stravaid,debug=False):
|
|||||||
workoutdate = rowdatetime.astimezone(
|
workoutdate = rowdatetime.astimezone(
|
||||||
pytz.timezone(thetimezone)
|
pytz.timezone(thetimezone)
|
||||||
).strftime('%Y-%m-%d')
|
).strftime('%Y-%m-%d')
|
||||||
|
|
||||||
starttime = rowdatetime.astimezone(
|
starttime = rowdatetime.astimezone(
|
||||||
pytz.timezone(thetimezone)
|
pytz.timezone(thetimezone)
|
||||||
).strftime('%H:%m:%S')
|
).strftime('%H:%m:%S')
|
||||||
|
|
||||||
totaltime = data['elapsed_time']
|
totaltime = data['elapsed_time']
|
||||||
duration = dataprep.totaltime_sec_to_string(totaltime)
|
duration = dataprep.totaltime_sec_to_string(totaltime)
|
||||||
|
|
||||||
weightcategory = 'hwt'
|
weightcategory = 'hwt'
|
||||||
|
|
||||||
# Create CSV file name and save data to CSV file
|
# Create CSV file name and save data to CSV file
|
||||||
csvfilename ='media/mailbox_attachments/{code}_{importid}.csv'.format(
|
csvfilename ='media/mailbox_attachments/{code}_{importid}.csv'.format(
|
||||||
importid=stravaid,
|
importid=stravaid,
|
||||||
code = uuid4().hex[:16]
|
code = uuid4().hex[:16]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Check if workout has stroke data, and get the stroke data
|
# Check if workout has stroke data, and get the stroke data
|
||||||
@@ -268,7 +268,7 @@ def create_async_workout(alldata,user,stravaid,debug=False):
|
|||||||
csvfilename,
|
csvfilename,
|
||||||
workouttype = workouttype,
|
workouttype = workouttype,
|
||||||
)
|
)
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
from rowers.utils import get_strava_stream
|
from rowers.utils import get_strava_stream
|
||||||
@@ -282,11 +282,11 @@ def get_workout(user,stravaid):
|
|||||||
except NoTokenError:
|
except NoTokenError:
|
||||||
s = "Token error"
|
s = "Token error"
|
||||||
return custom_exception_handler(401,s)
|
return custom_exception_handler(401,s)
|
||||||
|
|
||||||
r = Rower.objects.get(user=user)
|
r = Rower.objects.get(user=user)
|
||||||
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 custom_exception_handler(401,s)
|
return custom_exception_handler(401,s)
|
||||||
elif (r.stravatokenexpirydate is not None and timezone.now()>r.stravatokenexpirydate):
|
elif (r.stravatokenexpirydate is not None and timezone.now()>r.stravatokenexpirydate):
|
||||||
s = "Token expired. Needs to refresh."
|
s = "Token expired. Needs to refresh."
|
||||||
return custom_exception_handler(401,s)
|
return custom_exception_handler(401,s)
|
||||||
@@ -321,9 +321,9 @@ def get_workout(user,stravaid):
|
|||||||
else:
|
else:
|
||||||
duration = int(workoutsummary['elapsed_time'])
|
duration = int(workoutsummary['elapsed_time'])
|
||||||
t = pd.Series(range(duration+1))
|
t = pd.Series(range(duration+1))
|
||||||
|
|
||||||
nr_rows = len(t)
|
nr_rows = len(t)
|
||||||
|
|
||||||
|
|
||||||
if nr_rows == 0:
|
if nr_rows == 0:
|
||||||
return (0,"Error: Time data had zero length")
|
return (0,"Error: Time data had zero length")
|
||||||
@@ -336,7 +336,7 @@ def get_workout(user,stravaid):
|
|||||||
|
|
||||||
if power is None:
|
if power is None:
|
||||||
power = np.zeros(nr_rows)
|
power = np.zeros(nr_rows)
|
||||||
|
|
||||||
if hr is None:
|
if hr is None:
|
||||||
hr = np.zeros(nr_rows)
|
hr = np.zeros(nr_rows)
|
||||||
|
|
||||||
@@ -365,7 +365,7 @@ def get_workout(user,stravaid):
|
|||||||
strokelength = velo*60./(spm)
|
strokelength = velo*60./(spm)
|
||||||
strokelength[np.isinf(strokelength)] = 0.0
|
strokelength[np.isinf(strokelength)] = 0.0
|
||||||
|
|
||||||
|
|
||||||
pace = 500./(1.0*velo2)
|
pace = 500./(1.0*velo2)
|
||||||
pace[np.isinf(pace)] = 0.0
|
pace[np.isinf(pace)] = 0.0
|
||||||
|
|
||||||
@@ -379,16 +379,16 @@ def get_workout(user,stravaid):
|
|||||||
'power':power,
|
'power':power,
|
||||||
'strokelength':strokelength,
|
'strokelength':strokelength,
|
||||||
})
|
})
|
||||||
|
|
||||||
# startdatetime = datetime.datetime.strptime(startdatetime,"%Y-%m-%d-%H:%M:%S")
|
# startdatetime = datetime.datetime.strptime(startdatetime,"%Y-%m-%d-%H:%M:%S")
|
||||||
|
|
||||||
return [workoutsummary,df]
|
return [workoutsummary,df]
|
||||||
|
|
||||||
# Generate Workout data for Strava (a TCX file)
|
# Generate Workout data for Strava (a TCX file)
|
||||||
def createstravaworkoutdata(w,dozip=True):
|
def createstravaworkoutdata(w,dozip=True):
|
||||||
filename = w.csvfilename
|
filename = w.csvfilename
|
||||||
try:
|
try:
|
||||||
row = rowingdata(filename)
|
row = rowingdata(csvfile=filename)
|
||||||
except IOError:
|
except IOError:
|
||||||
data = dataprep.read_df_sql(w.id)
|
data = dataprep.read_df_sql(w.id)
|
||||||
try:
|
try:
|
||||||
@@ -402,12 +402,12 @@ def createstravaworkoutdata(w,dozip=True):
|
|||||||
index_label='index',
|
index_label='index',
|
||||||
compression='gzip')
|
compression='gzip')
|
||||||
try:
|
try:
|
||||||
row = rowingdata(filename)
|
row = rowingdata(csvfile=filename)
|
||||||
except IOError:
|
except IOError:
|
||||||
return '','Error - could not find rowing data'
|
return '','Error - could not find rowing data'
|
||||||
else:
|
else:
|
||||||
return '','Error - could not find rowing data'
|
return '','Error - could not find rowing data'
|
||||||
|
|
||||||
tcxfilename = filename[:-4]+'.tcx'
|
tcxfilename = filename[:-4]+'.tcx'
|
||||||
try:
|
try:
|
||||||
newnotes = w.notes+'\n from '+w.workoutsource+' via rowsandall.com'
|
newnotes = w.notes+'\n from '+w.workoutsource+' via rowsandall.com'
|
||||||
@@ -441,7 +441,7 @@ def handle_stravaexport(f2,workoutname,stravatoken,description='',
|
|||||||
client = stravalib.Client(access_token=stravatoken)
|
client = stravalib.Client(access_token=stravatoken)
|
||||||
|
|
||||||
act = client.upload_activity(f2,'tcx.gz',name=workoutname)
|
act = client.upload_activity(f2,'tcx.gz',name=workoutname)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = act.wait(poll_interval=5.0,timeout=30)
|
res = act.wait(poll_interval=5.0,timeout=30)
|
||||||
message = 'Workout successfully synchronized to Strava'
|
message = 'Workout successfully synchronized to Strava'
|
||||||
@@ -474,10 +474,10 @@ def add_workout_from_data(user,importid,data,strokedata,
|
|||||||
|
|
||||||
if workouttype.lower() == 'rowing':
|
if workouttype.lower() == 'rowing':
|
||||||
workouttype = 'rower'
|
workouttype = 'rower'
|
||||||
|
|
||||||
if 'summary_polyline' in data['map'] and workouttype=='rower':
|
if 'summary_polyline' in data['map'] and workouttype=='rower':
|
||||||
workouttype = 'water'
|
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'
|
||||||
try:
|
try:
|
||||||
@@ -497,14 +497,14 @@ def add_workout_from_data(user,importid,data,strokedata,
|
|||||||
rowdatetime = iso8601.parse_date(data['start_date'])
|
rowdatetime = iso8601.parse_date(data['start_date'])
|
||||||
except ParseError:
|
except ParseError:
|
||||||
rowdatetime = iso8601.parse_date(data['date'])
|
rowdatetime = iso8601.parse_date(data['date'])
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
intervaltype = data['workout_type']
|
intervaltype = data['workout_type']
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
intervaltype = ''
|
intervaltype = ''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
title = data['name']
|
title = data['name']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -550,7 +550,7 @@ def add_workout_from_data(user,importid,data,strokedata,
|
|||||||
spm = strokedata.loc[:,'spm']
|
spm = strokedata.loc[:,'spm']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
spm = 0*dist2
|
spm = 0*dist2
|
||||||
|
|
||||||
try:
|
try:
|
||||||
hr = strokedata.loc[:,'hr']
|
hr = strokedata.loc[:,'hr']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -568,7 +568,7 @@ def add_workout_from_data(user,importid,data,strokedata,
|
|||||||
|
|
||||||
#if power.std() == 0 and power.mean() == 0:
|
#if power.std() == 0 and power.mean() == 0:
|
||||||
# power = 2.8*velo**3
|
# power = 2.8*velo**3
|
||||||
|
|
||||||
# save csv
|
# save csv
|
||||||
# Create data frame with all necessary data to write to csv
|
# Create data frame with all necessary data to write to csv
|
||||||
df = pd.DataFrame({'TimeStamp (sec)':unixtime,
|
df = pd.DataFrame({'TimeStamp (sec)':unixtime,
|
||||||
@@ -590,10 +590,10 @@ def add_workout_from_data(user,importid,data,strokedata,
|
|||||||
' ElapsedTime (sec)':seconds
|
' ElapsedTime (sec)':seconds
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
df.sort_values(by='TimeStamp (sec)',ascending=True)
|
df.sort_values(by='TimeStamp (sec)',ascending=True)
|
||||||
|
|
||||||
|
|
||||||
timestr = strftime("%Y%m%d-%H%M%S")
|
timestr = strftime("%Y%m%d-%H%M%S")
|
||||||
|
|
||||||
|
|
||||||
@@ -623,7 +623,7 @@ def workout_strava_upload(user,w):
|
|||||||
thetoken = strava_open(user)
|
thetoken = strava_open(user)
|
||||||
except NoTokenError:
|
except NoTokenError:
|
||||||
return "Please connect to Strava first",0
|
return "Please connect to Strava first",0
|
||||||
|
|
||||||
message = "Uploading to Strava"
|
message = "Uploading to Strava"
|
||||||
stravaid=-1
|
stravaid=-1
|
||||||
r = Rower.objects.get(user=user)
|
r = Rower.objects.get(user=user)
|
||||||
@@ -652,7 +652,7 @@ def workout_strava_upload(user,w):
|
|||||||
except WindowsError:
|
except WindowsError:
|
||||||
pass
|
pass
|
||||||
return message,stravaid
|
return message,stravaid
|
||||||
|
|
||||||
w.uploadedtostrava = res
|
w.uploadedtostrava = res
|
||||||
w.save()
|
w.save()
|
||||||
try:
|
try:
|
||||||
@@ -704,7 +704,7 @@ def handle_strava_import_stroke_data(title,
|
|||||||
startdatetime = workoutsummary['start_date']
|
startdatetime = workoutsummary['start_date']
|
||||||
|
|
||||||
r = type('Rower', (object,), {"stravatoken": stravatoken})
|
r = type('Rower', (object,), {"stravatoken": stravatoken})
|
||||||
|
|
||||||
spm = get_strava_stream(r,'cadence',stravaid)
|
spm = get_strava_stream(r,'cadence',stravaid)
|
||||||
hr = get_strava_stream(r,'heartrate',stravaid)
|
hr = get_strava_stream(r,'heartrate',stravaid)
|
||||||
t = get_strava_stream(r,'time',stravaid)
|
t = get_strava_stream(r,'time',stravaid)
|
||||||
@@ -729,10 +729,10 @@ def handle_strava_import_stroke_data(title,
|
|||||||
|
|
||||||
if power is None:
|
if power is None:
|
||||||
power = np.zeros(nr_rows)
|
power = np.zeros(nr_rows)
|
||||||
|
|
||||||
if hr is None:
|
if hr is None:
|
||||||
hr = np.zeros(nr_rows)
|
hr = np.zeros(nr_rows)
|
||||||
|
|
||||||
if velo is None:
|
if velo is None:
|
||||||
velo = np.zeros(nr_rows)
|
velo = np.zeros(nr_rows)
|
||||||
|
|
||||||
@@ -747,7 +747,7 @@ def handle_strava_import_stroke_data(title,
|
|||||||
velo2 = savgol_filter(velo,windowsize,3)
|
velo2 = savgol_filter(velo,windowsize,3)
|
||||||
else:
|
else:
|
||||||
velo2 = velo
|
velo2 = velo
|
||||||
|
|
||||||
if coords is not None:
|
if coords is not None:
|
||||||
try:
|
try:
|
||||||
lat = coords[:,0]
|
lat = coords[:,0]
|
||||||
@@ -774,7 +774,7 @@ def handle_strava_import_stroke_data(title,
|
|||||||
unixtime = starttimeunix+t
|
unixtime = starttimeunix+t
|
||||||
|
|
||||||
strokedistance = 60.*velo2/spm
|
strokedistance = 60.*velo2/spm
|
||||||
|
|
||||||
nr_strokes = len(t)
|
nr_strokes = len(t)
|
||||||
|
|
||||||
df = pd.DataFrame({'TimeStamp (sec)':unixtime,
|
df = pd.DataFrame({'TimeStamp (sec)':unixtime,
|
||||||
@@ -810,13 +810,13 @@ workouttype {workouttype}""".format(
|
|||||||
stravaid=stravaid,
|
stravaid=stravaid,
|
||||||
workouttype=workouttype
|
workouttype=workouttype
|
||||||
)
|
)
|
||||||
|
|
||||||
msg = Message(mailbox=workoutsbox,
|
msg = Message(mailbox=workoutsbox,
|
||||||
from_header=useremail,
|
from_header=useremail,
|
||||||
subject=title,
|
subject=title,
|
||||||
body=body)
|
body=body)
|
||||||
msg.save()
|
msg.save()
|
||||||
|
|
||||||
a = MessageAttachment(message=msg,document=csvfilename[6:])
|
a = MessageAttachment(message=msg,document=csvfilename[6:])
|
||||||
a.save()
|
a.save()
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ def get_token(code):
|
|||||||
headers = {
|
headers = {
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
}
|
}
|
||||||
|
|
||||||
response = requests.post("https://oauth.trainingpeaks.com/oauth/token",
|
response = requests.post("https://oauth.trainingpeaks.com/oauth/token",
|
||||||
data=post_data)
|
data=post_data)
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ def get_token(code):
|
|||||||
thetoken = 0
|
thetoken = 0
|
||||||
expires_in = 0
|
expires_in = 0
|
||||||
refresh_token = 0
|
refresh_token = 0
|
||||||
|
|
||||||
return thetoken,expires_in,refresh_token
|
return thetoken,expires_in,refresh_token
|
||||||
|
|
||||||
# Make authorization URL including random string
|
# Make authorization URL including random string
|
||||||
@@ -97,7 +97,7 @@ def getidfromresponse(response):
|
|||||||
|
|
||||||
def createtpworkoutdata(w):
|
def createtpworkoutdata(w):
|
||||||
filename = w.csvfilename
|
filename = w.csvfilename
|
||||||
row = rowingdata(filename)
|
row = rowingdata(csvfile=filename)
|
||||||
tcxfilename = filename[:-4]+'.tcx'
|
tcxfilename = filename[:-4]+'.tcx'
|
||||||
try:
|
try:
|
||||||
newnotes = w.notes+'\n from '+w.workoutsource+' via rowsandall.com'
|
newnotes = w.notes+'\n from '+w.workoutsource+' via rowsandall.com'
|
||||||
@@ -105,7 +105,7 @@ def createtpworkoutdata(w):
|
|||||||
newnotes = 'from '+w.workoutsource+' via rowsandall.com'
|
newnotes = 'from '+w.workoutsource+' via rowsandall.com'
|
||||||
|
|
||||||
row.exporttotcx(tcxfilename,notes=newnotes)
|
row.exporttotcx(tcxfilename,notes=newnotes)
|
||||||
|
|
||||||
return tcxfilename
|
return tcxfilename
|
||||||
|
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ def tp_check(access_token):
|
|||||||
headers=headers)
|
headers=headers)
|
||||||
|
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
def uploadactivity(access_token,filename,description='',
|
def uploadactivity(access_token,filename,description='',
|
||||||
name='Rowsandall.com workout'):
|
name='Rowsandall.com workout'):
|
||||||
|
|
||||||
@@ -159,8 +159,8 @@ def uploadactivity(access_token,filename,description='',
|
|||||||
return resp.json()[0]["Id"],"ok",200,""
|
return resp.json()[0]["Id"],"ok",200,""
|
||||||
|
|
||||||
return 0,0,0,0
|
return 0,0,0,0
|
||||||
|
|
||||||
|
|
||||||
def workout_tp_upload(user,w):
|
def workout_tp_upload(user,w):
|
||||||
message = "Uploading to TrainingPeaks"
|
message = "Uploading to TrainingPeaks"
|
||||||
tpid = 0
|
tpid = 0
|
||||||
@@ -169,7 +169,7 @@ def workout_tp_upload(user,w):
|
|||||||
thetoken = tp_open(r.user)
|
thetoken = tp_open(r.user)
|
||||||
|
|
||||||
# need some code if token doesn't refresh
|
# need some code if token doesn't refresh
|
||||||
|
|
||||||
|
|
||||||
if (checkworkoutuser(user,w)):
|
if (checkworkoutuser(user,w)):
|
||||||
tcxfile = createtpworkoutdata(w)
|
tcxfile = createtpworkoutdata(w)
|
||||||
@@ -205,5 +205,5 @@ def workout_tp_upload(user,w):
|
|||||||
message = "You are not allowed to export this workout to TP"
|
message = "You are not allowed to export this workout to TP"
|
||||||
tpid = 0
|
tpid = 0
|
||||||
return message,tpid
|
return message,tpid
|
||||||
|
|
||||||
return message,tpid
|
return message,tpid
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ def get_workout(user,underarmourid):
|
|||||||
strokedata = pd.DataFrame.from_dict({
|
strokedata = pd.DataFrame.from_dict({
|
||||||
key: pd.Series(value) for key, value in data.items()
|
key: pd.Series(value) for key, value in data.items()
|
||||||
})
|
})
|
||||||
|
|
||||||
return data,strokedata
|
return data,strokedata
|
||||||
|
|
||||||
|
|
||||||
@@ -97,10 +97,10 @@ def get_workout(user,underarmourid):
|
|||||||
def createunderarmourworkoutdata(w):
|
def createunderarmourworkoutdata(w):
|
||||||
filename = w.csvfilename
|
filename = w.csvfilename
|
||||||
try:
|
try:
|
||||||
row = rowingdata(filename)
|
row = rowingdata(csvfile=filename)
|
||||||
except:
|
except:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
st = w.startdatetime.astimezone(pytz.timezone(w.timezone))
|
st = w.startdatetime.astimezone(pytz.timezone(w.timezone))
|
||||||
start_time = st.isoformat()
|
start_time = st.isoformat()
|
||||||
|
|
||||||
@@ -126,16 +126,16 @@ def createunderarmourworkoutdata(w):
|
|||||||
t = row.df.loc[:,'TimeStamp (sec)'].values #-row.df.ix[0,'TimeStamp (sec)']
|
t = row.df.loc[:,'TimeStamp (sec)'].values #-row.df.ix[0,'TimeStamp (sec)']
|
||||||
|
|
||||||
# t += arrow.get(st).timestamp
|
# t += arrow.get(st).timestamp
|
||||||
|
|
||||||
# t[0] = t[1]
|
# t[0] = t[1]
|
||||||
|
|
||||||
d = row.df.loc[:,'cum_dist'].values
|
d = row.df.loc[:,'cum_dist'].values
|
||||||
d[0] = d[1]
|
d[0] = d[1]
|
||||||
t = t.astype(float).tolist()
|
t = t.astype(float).tolist()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
d = d.astype(int).tolist()
|
d = d.astype(int).tolist()
|
||||||
spm = row.df[' Cadence (stokes/min)'].astype(int).tolist()
|
spm = row.df[' Cadence (stokes/min)'].astype(int).tolist()
|
||||||
spm[0] = spm[1]
|
spm[0] = spm[1]
|
||||||
@@ -146,10 +146,10 @@ def createunderarmourworkoutdata(w):
|
|||||||
speedmean = float(row.df[' AverageBoatSpeed (m/s)'].mean())
|
speedmean = float(row.df[' AverageBoatSpeed (m/s)'].mean())
|
||||||
speed = speed.replace(np.inf,0).tolist()
|
speed = speed.replace(np.inf,0).tolist()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
haslatlon=1
|
haslatlon=1
|
||||||
|
|
||||||
try:
|
try:
|
||||||
lat = row.df[' latitude'].tolist()
|
lat = row.df[' latitude'].tolist()
|
||||||
lon = row.df[' longitude'].tolist()
|
lon = row.df[' longitude'].tolist()
|
||||||
@@ -158,10 +158,10 @@ def createunderarmourworkoutdata(w):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
haslatlon = 0
|
haslatlon = 0
|
||||||
|
|
||||||
|
|
||||||
# path data
|
# path data
|
||||||
if haslatlon:
|
if haslatlon:
|
||||||
locdata = []
|
locdata = []
|
||||||
for e in zip(t,lat.values,lon.values):
|
for e in zip(t,lat.values,lon.values):
|
||||||
point = {
|
point = {
|
||||||
'lat':e[1],
|
'lat':e[1],
|
||||||
@@ -187,7 +187,7 @@ def createunderarmourworkoutdata(w):
|
|||||||
spmdata = []
|
spmdata = []
|
||||||
for e in zip(t,spm):
|
for e in zip(t,spm):
|
||||||
spmdata.append([e[0],e[1]])
|
spmdata.append([e[0],e[1]])
|
||||||
|
|
||||||
|
|
||||||
timeseries = {
|
timeseries = {
|
||||||
"distance": distancedata,
|
"distance": distancedata,
|
||||||
@@ -215,7 +215,7 @@ def createunderarmourworkoutdata(w):
|
|||||||
|
|
||||||
if haslatlon:
|
if haslatlon:
|
||||||
timeseries["position"] = locdata
|
timeseries["position"] = locdata
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"start_datetime": start_time,
|
"start_datetime": start_time,
|
||||||
"name": name,
|
"name": name,
|
||||||
@@ -235,7 +235,7 @@ def get_idfromuri(user,links):
|
|||||||
typeid = links['activity_type'][0]['id']
|
typeid = links['activity_type'][0]['id']
|
||||||
|
|
||||||
typename = get_typefromid(typeid,user)
|
typename = get_typefromid(typeid,user)
|
||||||
|
|
||||||
return id,typename
|
return id,typename
|
||||||
|
|
||||||
def getidfromresponse(response):
|
def getidfromresponse(response):
|
||||||
@@ -256,7 +256,7 @@ def refresh_ua_actlist(user):
|
|||||||
'Content-Type': 'application/json'}
|
'Content-Type': 'application/json'}
|
||||||
url = "https://api.ua.com/v7.1/activity_type/"
|
url = "https://api.ua.com/v7.1/activity_type/"
|
||||||
response = requests.get(url,headers=headers)
|
response = requests.get(url,headers=headers)
|
||||||
|
|
||||||
me_json = response.json()
|
me_json = response.json()
|
||||||
types = me_json["_embedded"]["activity_types"]
|
types = me_json["_embedded"]["activity_types"]
|
||||||
w = {int(t["_links"]["self"][0]["id"]):t["name"] for t in types}
|
w = {int(t["_links"]["self"][0]["id"]):t["name"] for t in types}
|
||||||
@@ -290,11 +290,11 @@ def get_typefromid(typeid,user):
|
|||||||
res = me_json['name']
|
res = me_json['name']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
res = 0
|
res = 0
|
||||||
|
|
||||||
return res
|
|
||||||
|
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Get user id, having access token
|
# Get user id, having access token
|
||||||
# Handy for checking if the API access is working
|
# Handy for checking if the API access is working
|
||||||
def get_userid(access_token):
|
def get_userid(access_token):
|
||||||
@@ -313,11 +313,11 @@ def get_userid(access_token):
|
|||||||
res = me_json['id']
|
res = me_json['id']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
res = 0
|
res = 0
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def default(o):
|
def default(o):
|
||||||
if isinstance(o, numpy.int64): return int(o)
|
if isinstance(o, numpy.int64): return int(o)
|
||||||
raise TypeError
|
raise TypeError
|
||||||
|
|
||||||
|
|
||||||
@@ -338,7 +338,7 @@ def workout_ua_upload(user,w):
|
|||||||
message = "Data error"
|
message = "Data error"
|
||||||
uaid = 0
|
uaid = 0
|
||||||
return message, uaid
|
return message, uaid
|
||||||
|
|
||||||
authorizationstring = str('Bearer ' + thetoken)
|
authorizationstring = str('Bearer ' + thetoken)
|
||||||
headers = {'Authorization': authorizationstring,
|
headers = {'Authorization': authorizationstring,
|
||||||
'Api-Key': UNDERARMOUR_CLIENT_KEY,
|
'Api-Key': UNDERARMOUR_CLIENT_KEY,
|
||||||
@@ -357,7 +357,7 @@ def workout_ua_upload(user,w):
|
|||||||
w.save()
|
w.save()
|
||||||
elif (response.status_code == 201 or response.status_code==200):
|
elif (response.status_code == 201 or response.status_code==200):
|
||||||
uaid = getidfromresponse(response)
|
uaid = getidfromresponse(response)
|
||||||
w.uploadedtounderarmour = uaid
|
w.uploadedtounderarmour = uaid
|
||||||
w.save()
|
w.save()
|
||||||
return 'Successfully synchronized with MapMyFitness',uaid
|
return 'Successfully synchronized with MapMyFitness',uaid
|
||||||
else:
|
else:
|
||||||
@@ -365,7 +365,7 @@ def workout_ua_upload(user,w):
|
|||||||
message = "Something went wrong in workout_underarmour_upload_view: %s - %s" % (s.reason,s.text)
|
message = "Something went wrong in workout_underarmour_upload_view: %s - %s" % (s.reason,s.text)
|
||||||
uaid = 0
|
uaid = 0
|
||||||
return message, uaid
|
return message, uaid
|
||||||
|
|
||||||
else:
|
else:
|
||||||
message = "You are not authorized to upload this workout"
|
message = "You are not authorized to upload this workout"
|
||||||
uaid = 0
|
uaid = 0
|
||||||
@@ -384,7 +384,7 @@ def add_workout_from_data(user,importid,data,strokedata,
|
|||||||
comments = data['notes']
|
comments = data['notes']
|
||||||
except:
|
except:
|
||||||
comments = ''
|
comments = ''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
thetimezone = tz(data['start_locale_timezone'])
|
thetimezone = tz(data['start_locale_timezone'])
|
||||||
except:
|
except:
|
||||||
@@ -405,8 +405,8 @@ def add_workout_from_data(user,importid,data,strokedata,
|
|||||||
rowdatetime = datetime.strptime(data['date'],"%Y-%m-%d %H:%M:%S")
|
rowdatetime = datetime.strptime(data['date'],"%Y-%m-%d %H:%M:%S")
|
||||||
rowdatetime = thetimezone.localize(rowdatetime).astimezone(utc)
|
rowdatetime = thetimezone.localize(rowdatetime).astimezone(utc)
|
||||||
starttimeunix = arrow.get(rowdatetime).timestamp
|
starttimeunix = arrow.get(rowdatetime).timestamp
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
title = data['name']
|
title = data['name']
|
||||||
except:
|
except:
|
||||||
@@ -414,7 +414,7 @@ def add_workout_from_data(user,importid,data,strokedata,
|
|||||||
|
|
||||||
timeseries = data['time_series']
|
timeseries = data['time_series']
|
||||||
|
|
||||||
# position, distance, speed, cadence, power,
|
# position, distance, speed, cadence, power,
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = splituadata(timeseries['distance'])
|
res = splituadata(timeseries['distance'])
|
||||||
@@ -427,7 +427,7 @@ def add_workout_from_data(user,importid,data,strokedata,
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
l = timeseries['position']
|
l = timeseries['position']
|
||||||
|
|
||||||
res = splituadata(l)
|
res = splituadata(l)
|
||||||
times_location = res[0]
|
times_location = res[0]
|
||||||
latlong = res[1]
|
latlong = res[1]
|
||||||
@@ -445,7 +445,7 @@ def add_workout_from_data(user,importid,data,strokedata,
|
|||||||
loncoord = np.zeros(len(times_distance))
|
loncoord = np.zeros(len(times_distance))
|
||||||
if workouttype in otwtypes:
|
if workouttype in otwtypes:
|
||||||
workouttype = 'rower'
|
workouttype = 'rower'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = splituadata(timeseries['cadence'])
|
res = splituadata(timeseries['cadence'])
|
||||||
times_spm = res[0]
|
times_spm = res[0]
|
||||||
@@ -453,7 +453,7 @@ def add_workout_from_data(user,importid,data,strokedata,
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
times_spm = times_distance
|
times_spm = times_distance
|
||||||
spm = 0*times_distance
|
spm = 0*times_distance
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = splituadata(timeseries['heartrate'])
|
res = splituadata(timeseries['heartrate'])
|
||||||
hr = res[1]
|
hr = res[1]
|
||||||
@@ -485,7 +485,7 @@ def add_workout_from_data(user,importid,data,strokedata,
|
|||||||
' HRCur (bpm)' : hrseries,
|
' HRCur (bpm)' : hrseries,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
df = pd.DataFrame(d)
|
df = pd.DataFrame(d)
|
||||||
|
|
||||||
@@ -495,7 +495,7 @@ def add_workout_from_data(user,importid,data,strokedata,
|
|||||||
df[' ElapsedTime (sec)'] = cum_time
|
df[' ElapsedTime (sec)'] = cum_time
|
||||||
|
|
||||||
velo = df[' Horizontal (meters)'].diff()/df[' ElapsedTime (sec)'].diff()
|
velo = df[' Horizontal (meters)'].diff()/df[' ElapsedTime (sec)'].diff()
|
||||||
|
|
||||||
df[' Power (watts)'] = 0.0*velo
|
df[' Power (watts)'] = 0.0*velo
|
||||||
|
|
||||||
nr_rows = len(velo.values)
|
nr_rows = len(velo.values)
|
||||||
@@ -512,17 +512,17 @@ def add_workout_from_data(user,importid,data,strokedata,
|
|||||||
|
|
||||||
unixtime = cum_time+starttimeunix
|
unixtime = cum_time+starttimeunix
|
||||||
unixtime[0] = starttimeunix
|
unixtime[0] = starttimeunix
|
||||||
|
|
||||||
df['TimeStamp (sec)'] = unixtime
|
df['TimeStamp (sec)'] = unixtime
|
||||||
|
|
||||||
|
|
||||||
dt = np.diff(cum_time).mean()
|
dt = np.diff(cum_time).mean()
|
||||||
wsize = round(5./dt)
|
wsize = round(5./dt)
|
||||||
|
|
||||||
df = df.fillna(0)
|
df = df.fillna(0)
|
||||||
|
|
||||||
df.sort_values(by='TimeStamp (sec)',ascending=True)
|
df.sort_values(by='TimeStamp (sec)',ascending=True)
|
||||||
|
|
||||||
timestr = strftime("%Y%m%d-%H%M%S")
|
timestr = strftime("%Y%m%d-%H%M%S")
|
||||||
|
|
||||||
csvfilename ='media/{code}_{importid}.csv'.format(
|
csvfilename ='media/{code}_{importid}.csv'.format(
|
||||||
@@ -540,4 +540,3 @@ def add_workout_from_data(user,importid,data,strokedata,
|
|||||||
notes=comments)
|
notes=comments)
|
||||||
|
|
||||||
return (id,message)
|
return (id,message)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user