fixed strava better
This commit is contained in:
@@ -308,63 +308,47 @@ def get_workout(user,stravaid):
|
||||
except KeyError:
|
||||
startdatetime = timezone.now()
|
||||
|
||||
spmjson = get_strava_stream(r,'cadence',stravaid)
|
||||
hrjson = get_strava_stream(r,'heartrate',stravaid)
|
||||
timejson = get_strava_stream(r,'time',stravaid)
|
||||
velojson = get_strava_stream(r,'velocity_smooth',stravaid)
|
||||
distancejson = get_strava_stream(r,'distance',stravaid)
|
||||
latlongjson = get_strava_stream(r,'latlng',stravaid)
|
||||
powerjson = get_strava_stream(r,'power',stravaid)
|
||||
spm = get_strava_stream(r,'cadence',stravaid)
|
||||
hr = get_strava_stream(r,'heartrate',stravaid)
|
||||
t = get_strava_stream(r,'time',stravaid)
|
||||
velo = get_strava_stream(r,'velocity_smooth',stravaid)
|
||||
d = get_strava_stream(r,'distance',stravaid)
|
||||
coords = get_strava_stream(r,'latlng',stravaid)
|
||||
power = get_strava_stream(r,'power',stravaid)
|
||||
|
||||
try:
|
||||
t = np.array(timejson.json()[0]['data'])
|
||||
nr_rows = len(t)
|
||||
d = np.array(distancejson.json()[0]['data'])
|
||||
if nr_rows == 0:
|
||||
return (0,"Error: Time data had zero length")
|
||||
nr_rows = len(t)
|
||||
|
||||
except IndexError:
|
||||
if nr_rows == 0:
|
||||
return (0,"Error: Time data had zero length")
|
||||
|
||||
if d is None:
|
||||
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()[0]['data'])
|
||||
except:
|
||||
if spm is None:
|
||||
spm = np.zeros(nr_rows)
|
||||
|
||||
try:
|
||||
power = np.array(powerjson.json()[0]['data'])
|
||||
except IndexError:
|
||||
if power is None:
|
||||
power = np.zeros(nr_rows)
|
||||
|
||||
try:
|
||||
hr = np.array(hrjson.json()[0]['data'])
|
||||
except IndexError:
|
||||
hr = np.zeros(nr_rows)
|
||||
except KeyError:
|
||||
if hr is None:
|
||||
hr = np.zeros(nr_rows)
|
||||
|
||||
try:
|
||||
velo = np.array(velojson.json()[0]['data'])
|
||||
except IndexError:
|
||||
velo = np.zeros(nr_rows)
|
||||
except KeyError:
|
||||
if velo is None:
|
||||
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:
|
||||
|
||||
if coords is not None:
|
||||
try:
|
||||
lat = coords[:,0]
|
||||
lon = coords[:,1]
|
||||
except IndexError:
|
||||
lat = np.zeros(len(t))
|
||||
lon = np.zeros(len(t))
|
||||
else:
|
||||
lat = np.zeros(len(t))
|
||||
lon = np.zeros(len(t))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user