not working yet, need to complete in tasks.py
This commit is contained in:
@@ -77,6 +77,105 @@ def add(x, y):
|
||||
return x + y
|
||||
|
||||
|
||||
@app.task
|
||||
def handle_strava_import_stroke_data(stravatoken,
|
||||
stravaid,workoutid,
|
||||
starttimeunix,
|
||||
csvfilename,debug=True,**kwargs):
|
||||
# ready to fetch. Hurray
|
||||
fetchresolution = 'high'
|
||||
series_type = 'time'
|
||||
authorizationstring = str('Bearer ' + r.stravatoken)
|
||||
headers = {'Authorization': authorizationstring,
|
||||
'user-agent': 'sanderroosendaal',
|
||||
'Content-Type': 'application/json',
|
||||
'resolution': 'medium',}
|
||||
url = "https://www.strava.com/api/v3/activities/"+str(stravaid)
|
||||
workoutsummary = requests.get(url,headers=headers).json()
|
||||
|
||||
workoutsummary['timezone'] = "Etc/UTC"
|
||||
startdatetime = workoutsummary['start_date']
|
||||
|
||||
url = "https://www.strava.com/api/v3/activities/"+str(stravaid)+"/streams/cadence?resolution="+fetchresolution+"&series_type="+series_type
|
||||
spmjson = requests.get(url,headers=headers)
|
||||
url = "https://www.strava.com/api/v3/activities/"+str(stravaid)+"/streams/heartrate?resolution="+fetchresolution+"&series_type="+series_type
|
||||
hrjson = requests.get(url,headers=headers)
|
||||
url = "https://www.strava.com/api/v3/activities/"+str(stravaid)+"/streams/time?resolution="+fetchresolution+"&series_type="+series_type
|
||||
timejson = requests.get(url,headers=headers)
|
||||
url = "https://www.strava.com/api/v3/activities/"+str(stravaid)+"/streams/velocity_smooth?resolution="+fetchresolution+"&series_type="+series_type
|
||||
velojson = requests.get(url,headers=headers)
|
||||
url = "https://www.strava.com/api/v3/activities/"+str(stravaid)+"/streams/distance?resolution="+fetchresolution+"&series_type="+series_type
|
||||
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)
|
||||
|
||||
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")
|
||||
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")
|
||||
|
||||
try:
|
||||
spm = np.array(spmjson.json()[1]['data'])
|
||||
except:
|
||||
spm = np.zeros(nr_rows)
|
||||
|
||||
try:
|
||||
hr = np.array(hrjson.json()[1]['data'])
|
||||
except IndexError:
|
||||
hr = np.zeros(nr_rows)
|
||||
except KeyError:
|
||||
hr = np.zeros(nr_rows)
|
||||
|
||||
try:
|
||||
velo = np.array(velojson.json()[1]['data'])
|
||||
except IndexError:
|
||||
velo = np.zeros(nr_rows)
|
||||
except KeyError:
|
||||
velo = np.zeros(nr_rows)
|
||||
|
||||
dt = np.diff(t).mean()
|
||||
wsize = round(5./dt)
|
||||
|
||||
velo2 = ewmovingaverage(velo,wsize)
|
||||
coords = np.array(latlongjson.json()[0]['data'])
|
||||
try:
|
||||
lat = coords[:,0]
|
||||
lon = coords[:,1]
|
||||
except IndexError:
|
||||
lat = np.zeros(len(t))
|
||||
lon = np.zeros(len(t))
|
||||
except KeyError:
|
||||
lat = np.zeros(len(t))
|
||||
lon = np.zeros(len(t))
|
||||
|
||||
strokelength = velo*60./(spm)
|
||||
strokelength[np.isinf(strokelength)] = 0.0
|
||||
|
||||
pace = 500./(1.0*velo2)
|
||||
pace[np.isinf(pace)] = 0.0
|
||||
|
||||
df = pd.DataFrame({'t':10*t,
|
||||
'd':10*d,
|
||||
'p':10*pace,
|
||||
'spm':spm,
|
||||
'hr':hr,
|
||||
'lat':lat,
|
||||
'lon':lon,
|
||||
'strokelength':strokelength,
|
||||
})
|
||||
|
||||
# startdatetime = datetime.datetime.strptime(startdatetime,"%Y-%m-%d-%H:%M:%S")
|
||||
|
||||
return [workoutsummary,df]
|
||||
|
||||
|
||||
@app.task
|
||||
def handle_c2_import_stroke_data(c2token,
|
||||
c2id,workoutid,
|
||||
|
||||
Reference in New Issue
Block a user