Private
Public Access
1
0

seems to auto import well

This commit is contained in:
Sander Roosendaal
2018-06-25 22:08:47 +02:00
parent b313726478
commit 8c2c995aab
2 changed files with 30 additions and 9 deletions

View File

@@ -150,6 +150,7 @@ def add_stroke_data(user,stravaid,workoutid,startdatetime,csvfilename):
starttimeunix = arrow.get(startdatetime).timestamp
job = myqueue(queue,
handle_strava_import_stroke_data,
r.stravatoken,

View File

@@ -8,6 +8,7 @@ import numpy as np
import re
from scipy import optimize
from scipy.signal import savgol_filter
import rowingdata
@@ -20,6 +21,7 @@ import datetime
import pytz
import iso8601
from matplotlib.backends.backend_agg import FigureCanvas
#from matplotlib.backends.backend_cairo import FigureCanvasCairo as FigureCanvas
import matplotlib.pyplot as plt
@@ -108,25 +110,31 @@ def handle_strava_import_stroke_data(stravatoken,
distancejson = requests.get(url,headers=headers)
url = "https://www.strava.com/api/v3/activities/"+str(stravaid)+"/streams/latlng?resolution="+fetchresolution+"&series_type="+series_type
latlongjson = requests.get(url,headers=headers)
url = "https://www.strava.com/api/v3/activities/"+str(stravaid)+"/streams/watts?resolution="+fetchresolution+"&series_type="+series_type
wattsjson = requests.get(url,headers=headers)
try:
t = np.array(timejson.json()[0]['data'])
nr_rows = len(t)
d = np.array(distancejson.json()[1]['data'])
if nr_rows == 0:
return (0,"Error: Time data had zero length")
return 0
except IndexError:
d = 0*t
# return (0,"Error: No Distance information in the Strava data")
except KeyError:
return (0,"something went wrong with the Strava import")
return 0
try:
spm = np.array(spmjson.json()[1]['data'])
except:
spm = np.zeros(nr_rows)
try:
watts = np.array(wattsjson.json()[1]['data'])
except:
watts = np.zeros(nr_rows)
try:
hr = np.array(hrjson.json()[1]['data'])
except IndexError:
@@ -141,10 +149,17 @@ def handle_strava_import_stroke_data(stravatoken,
except KeyError:
velo = np.zeros(nr_rows)
dt = np.diff(t).mean()
wsize = round(5./dt)
f = np.diff(t).mean()
if f != 0:
windowsize = 2*(int(10./(f)))+1
else:
windowsize = 1
velo2 = ewmovingaverage(velo,wsize)
if windowsize > 3 and windowsize < len(velo):
velo2 = savgol_filter(velo,windowsize,3)
else:
velo2 = velo
coords = np.array(latlongjson.json()[0]['data'])
try:
lat = coords[:,0]
@@ -162,8 +177,10 @@ def handle_strava_import_stroke_data(stravatoken,
pace = 500./(1.0*velo2)
pace[np.isinf(pace)] = 0.0
unixtime = starttimeunix+10*t
unixtime = starttimeunix+t
strokedistance = 60.*velo2/spm
nr_strokes = len(t)
df = pd.DataFrame({'TimeStamp (sec)':unixtime,
@@ -178,15 +195,18 @@ def handle_strava_import_stroke_data(stravatoken,
'cum_dist':d,
' DragFactor':np.zeros(nr_strokes),
' DriveLength (meters)':np.zeros(nr_strokes),
' StrokeDistance (meters)':np.zeros(nr_strokes),
' StrokeDistance (meters)':strokedistance,
' DriveTime (ms)':np.zeros(nr_strokes),
' StrokeRecoveryTime (ms)':np.zeros(nr_strokes),
' AverageDriveForce (lbs)':np.zeros(nr_strokes),
' PeakDriveForce (lbs)':np.zeros(nr_strokes),
' lapIdx':np.zeros(nr_strokes),
' Power (watts)':0*d,
' Power (watts)':watts,
})
df.sort_values(by='TimeStamp (sec)',ascending=True)
res = df.to_csv(csvfilename+'.gz',index_label='index',compression='gzip')
data = dataprep(df,id=workoutid,bands=False,debug=debug)