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