Private
Public Access
1
0

removing obsolete rowingdata(csvfile)

This commit is contained in:
Sander Roosendaal
2019-11-11 17:31:56 +01:00
parent 23909feabf
commit 2294603129
6 changed files with 152 additions and 156 deletions

View File

@@ -104,17 +104,17 @@ def get_workout(user,runkeeperid):
strokedata = pd.DataFrame.from_dict({
key: pd.Series(value) for key, value in data.items()
})
return data,strokedata
# Create Workout Data for upload to SportTracks
def createrunkeeperworkoutdata(w):
filename = w.csvfilename
try:
row = rowingdata(filename)
row = rowingdata(csvfile=filename)
except:
return 0
averagehr = int(row.df[' HRCur (bpm)'].mean())
maxhr = int(row.df[' HRCur (bpm)'].max())
duration = w.duration.hour*3600
@@ -134,9 +134,9 @@ def createrunkeeperworkoutdata(w):
spm = row.df[' Cadence (stokes/min)'].astype(int)
spm[0] = spm[1]
hr = row.df[' HRCur (bpm)'].astype(int)
haslatlon=1
try:
lat = row.df[' latitude'].values
lon = row.df[' longitude'].values
@@ -148,12 +148,12 @@ def createrunkeeperworkoutdata(w):
t = t.tolist()
hr = hr.tolist()
d = d.tolist()
# path data
if haslatlon:
lat = lat.tolist()
lon = lon.tolist()
locdata = []
locdata = []
for e in zip(t,lat,lon):
point = {'timestamp':e[0],
'latitude':e[1],
@@ -183,7 +183,7 @@ def createrunkeeperworkoutdata(w):
newnotes = w.notes+'\n from '+w.workoutsource+' via rowsandall.com'
except TypeError:
newnotes = 'from '+w.workoutsource+' via rowsandall.com'
if haslatlon:
data = {
"type": "Rowing",
@@ -222,7 +222,7 @@ def getidfromresponse(response):
tester = re.compile('^\/fitnessActivities\/(\d+)$')
id = int(tester.match(uri).group(1))
return int(id)
def geturifromid(access_token,id):
@@ -245,7 +245,7 @@ def geturifromid(access_token,id):
return res
# Get user id, having access token
# Handy for checking if the API access is working
def get_userid(access_token):
@@ -256,7 +256,7 @@ def get_userid(access_token):
import urllib
url = "https://api.runkeeper.com/user"
response = requests.get(url,headers=headers)
try:
me_json = response.json()
@@ -271,7 +271,7 @@ def get_userid(access_token):
return str(res)
def default(o):
if isinstance(o, numpy.int64): return int(o)
if isinstance(o, numpy.int64): return int(o)
raise TypeError
def workout_runkeeper_upload(user,w):
@@ -280,7 +280,7 @@ def workout_runkeeper_upload(user,w):
r = w.user
thetoken = runkeeper_open(r.user)
# ready to upload. Hurray
@@ -291,7 +291,7 @@ def workout_runkeeper_upload(user,w):
message = "Data error in Runkeeper Upload"
rkid = 0
return message, rkid
authorizationstring = str('Bearer ' + thetoken)
headers = {'Authorization': authorizationstring,
'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)
rkid = 0
return message, rkid
else:
message = "You are not authorized to upload this workout"
rkid = 0
@@ -338,7 +338,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
comments = data['notes']
except:
comments = ''
try:
utcoffset = tz(data['utcoffset'])
except:
@@ -362,8 +362,8 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
starttimeunix = arrow.get(rowdatetime).timestamp
#starttimeunix = mktime(rowdatetime.utctimetuple())
starttimeunix += utcoffset*3600
try:
title = data['name']
except:
@@ -378,7 +378,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
try:
l = data['path']
res = splitrunkeeperlatlongdata(l,'timestamp','latitude','longitude')
times_location = res[0]
latcoord = res[1]
@@ -390,7 +390,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
loncoord = np.zeros(len(times_distance))
if workouttype in types.otwtypes:
workouttype = 'rower'
try:
res = splitrunkeeperdata(data['cadence'],'timestamp','cadence')
times_spm = res[0]
@@ -398,7 +398,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
except KeyError:
times_spm = times_distance
spm = 0*times_distance
try:
res = splitrunkeeperdata(data['heart_rate'],'timestamp','heart_rate')
hr = res[1]
@@ -416,13 +416,13 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
latseries = latseries.groupby(latseries.index).first()
except TypeError:
latseries = 0.0*distseries
lonseries = pd.Series(loncoord,index=times_location)
try:
lonseries = lonseries.groupby(lonseries.index).first()
except TypeError:
lonseries = 0.0*distseries
spmseries = pd.Series(spm,index=times_spm)
spmseries = spmseries.groupby(spmseries.index).first()
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,
}
df = pd.DataFrame(d)
@@ -451,7 +451,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
df[' ElapsedTime (sec)'] = cum_time
velo = df[' Horizontal (meters)'].diff()/df[' ElapsedTime (sec)'].diff()
df[' Power (watts)'] = 0.0*velo
nr_rows = len(velo.values)
@@ -471,10 +471,10 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
unixtime[0] = starttimeunix
except IndexError:
return (0,'No data to import')
df['TimeStamp (sec)'] = unixtime
dt = np.diff(cum_time).mean()
wsize = round(5./dt)
@@ -486,7 +486,7 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
df = df.fillna(0)
df.sort_values(by='TimeStamp (sec)',ascending=True)
timestr = strftime("%Y%m%d-%H%M%S")
# csvfilename ='media/Import_'+str(importid)+'.csv'
@@ -505,4 +505,3 @@ def add_workout_from_data(user,importid,data,strokedata,source='runkeeper',
notes=comments)
return (id,message)