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))
|
||||
|
||||
|
||||
@@ -239,10 +239,12 @@ class WorkoutViewTest(TestCase):
|
||||
|
||||
response = self.c.get(url,follow=True)
|
||||
self.assertEqual(response.status_code,200)
|
||||
|
||||
|
||||
@patch('rowers.dataprep.create_engine')
|
||||
@patch('rowers.dataprep.getsmallrowdata_db')
|
||||
def test_waterworkout_view(self, mocked_sqlalchemy, mocked_getsmallrowdata_db):
|
||||
# @patch('rowers.weather.requests.get', side_effect=mocked_requests)
|
||||
def test_waterworkout_view(self,
|
||||
mocked_sqlalchemy, mocked_getsmallrowdata_db):
|
||||
login = self.c.login(username=self.u.username, password=self.password)
|
||||
self.assertTrue(login)
|
||||
|
||||
|
||||
BIN
rowers/tests/testdata/testdata.csv.gz
vendored
BIN
rowers/tests/testdata/testdata.csv.gz
vendored
Binary file not shown.
@@ -490,8 +490,13 @@ def get_strava_stream(r,metric,stravaid,series_type='time',fetchresolution='high
|
||||
|
||||
|
||||
s = requests.get(url,headers=headers)
|
||||
|
||||
for data in s.json():
|
||||
y = None
|
||||
if data['type'] == metric:
|
||||
return np.array(data['data'])
|
||||
|
||||
return s
|
||||
return None
|
||||
|
||||
def allmonths(startdate,enddate):
|
||||
d = startdate
|
||||
|
||||
Reference in New Issue
Block a user