Private
Public Access
1
0

Merge branch 'feature/stravaimport' into develop

This commit is contained in:
Sander Roosendaal
2018-11-12 22:24:59 +01:00
2 changed files with 34 additions and 22 deletions

View File

@@ -220,11 +220,11 @@ def get_session_metrics(ps):
return thedict
cratiocolors = {
'started': "lightgreen",
'almost complete': "mediumgreen",
'completed': "green",
'a bit too much': "purple",
'way too much': "violet",
'better than nothing': "lightgreen",
'partial': "mediumgreen",
'on target': "green",
'over target': "purple",
'way over target': "violet",
'missed': "black",
'not done': "white",
}
@@ -250,11 +250,11 @@ def is_session_complete_ws(ws,ps):
cratiomax = 1
cratios = {
'started':0,
'almost complete':0.6,
'completed':0.8,
'a bit too much':1.2,
'way too much': 1.5
'better than nothing':0,
'partial':0.6,
'on target':0.8,
'over target':1.2,
'way over target': 1.5
}
@@ -263,8 +263,8 @@ def is_session_complete_ws(ws,ps):
cratiomin = 0.8
cratiomax = 1.2
else:
cratios['completed'] = 0.9167
cratios['a bit too much'] = 1.0833
cratios['on target'] = 0.9167
cratios['over target'] = 1.0833
cratiomin = 0.9167
cratiomax = 1.0833
@@ -293,19 +293,19 @@ def is_session_complete_ws(ws,ps):
ratio = score/float(value)
verdict = 'started'
verdict = 'better than nothing'
if ps.sessiontype in ['session','cycletarget']:
if ps.criterium == 'exact':
if ratio == 1.0:
return ratio,'completed',completiondate
return ratio,'on target',completiondate
else:
if not completiondate:
completiondate = ws.reverse()[0].date
return ratio,'partial',completiondate
elif ps.criterium == 'minimum':
if ratio >= 1.0:
return ratio,'completed',completiondate
return ratio,'on target',completiondate
else:
if not completiondate:
completiondate = ws.reverse()[0].date
@@ -320,18 +320,18 @@ def is_session_complete_ws(ws,ps):
return ratio,verdict,completiondate
elif ps.sessiontype == 'test':
if ratio==1.0:
return ratio,'completed',completiondate
return ratio,'on target',completiondate
else:
return ratio,'partial',completiondate
elif ps.sessiontype == 'challenge':
if ps.criterium == 'exact':
if ratio == 1.0:
return ratio,'completed',completiondate
return ratio,'on target',completiondate
else:
return ratio,'partial',completiondate
elif ps.criterium == 'minimum':
if ratio > 1.0:
return ratio,'completed',completiondate
return ratio,'on target',completiondate
else:
if not completiondate:
completiondate = ws.reverse()[0].date
@@ -347,7 +347,7 @@ def is_session_complete_ws(ws,ps):
if record.workoutid in wids:
if record.coursecompleted:
ratio = record.distance/ps.sessionvalue
return ratio,'completed',completiondate
return ratio,'on target',completiondate
else:
ratio = record.distance/ps.sessionvalue
return ratio,'partial',completiondate
@@ -359,7 +359,7 @@ def is_session_complete_ws(ws,ps):
if record.workoutid in wids:
if record.coursecompleted:
ratio = record.distance/float(ps.sessionvalue)
return ratio,'completed',completiondate
return ratio,'on target',completiondate
else:
ratio = record.distance/float(ps.sessionvalue)
return ratio,'partial',completiondate

View File

@@ -248,7 +248,7 @@ def get_workout(user,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)
try:
@@ -269,6 +269,11 @@ def get_workout(user,stravaid):
except:
spm = np.zeros(nr_rows)
try:
power = np.array(powerjson.json()[1]['data'])
except IndexError:
power = np.zeros(nr_rows)
try:
hr = np.array(hrjson.json()[1]['data'])
except IndexError:
@@ -315,6 +320,7 @@ def get_workout(user,stravaid):
'hr':hr,
'lat':lat,
'lon':lon,
'power':power,
'strokelength':strokelength,
})
@@ -494,7 +500,13 @@ def add_workout_from_data(user,importid,data,strokedata,
velo = 500./pace
power = 2.8*velo**3
try:
power = strokedata.ix[:,'power']
except KeyError:
power = 2.8*velo**3
if power.std() == 0 and power.mean() == 0:
power = 2.8*velo**3
# save csv
# Create data frame with all necessary data to write to csv