Private
Public Access
1
0

Merge branch 'develop' into feature/restapi

This commit is contained in:
Sander Roosendaal
2016-12-13 16:41:14 +01:00
5 changed files with 345 additions and 78 deletions

View File

@@ -1394,6 +1394,35 @@ def cum_flex(request,theuser=0,
'promember':promember,
})
@user_passes_test(promember,login_url="/",redirect_field_name=None)
def workout_forcecurve_view(request,id=0):
row = Workout.objects.get(id=id)
promember=0
mayedit=0
if not request.user.is_anonymous():
r = Rower.objects.get(user=request.user)
result = request.user.is_authenticated() and r.rowerplan=='pro'
if result:
promember=1
if request.user == row.user.user:
mayedit=1
if not promember:
return HttpResponseRedirect("/rowers/about/")
script,div,js_resources,css_resources = interactive_forcecurve([row])
return render(request,
'forcecurve_single.html',
{
'the_script':script,
'the_div':div,
'js_res': js_resources,
'css_res':css_resources,
'id':id,
'mayedit':mayedit,
})
@login_required()
def workout_histo_view(request,id=0):
row = Workout.objects.get(id=id)
@@ -1410,9 +1439,6 @@ def workout_histo_view(request,id=0):
if not promember:
return HttpResponseRedirect("/rowers/about/")
res = interactive_histoall([row])
script = res[0]
div = res[1]
@@ -2612,8 +2638,8 @@ def workout_flexchart3_view(request,*args,**kwargs):
result = request.user.is_authenticated() and r.rowerplan=='pro'
if result:
promember=1
if request.user == row.user.user:
mayedit=1
if request.user == row.user.user:
mayedit=1
workouttype = 'ote'
@@ -2692,10 +2718,20 @@ def workout_flexchart3_view(request,*args,**kwargs):
workstrokesonly = False
# create interactive plot
script,div,js_resources,css_resources = interactive_flex_chart2(id,xparam=xparam,yparam1=yparam1,
try:
script,div,js_resources,css_resources = interactive_flex_chart2(id,xparam=xparam,yparam1=yparam1,
yparam2=yparam2,
promember=promember,plottype=plottype,
workstrokesonly=workstrokesonly)
except ValueError:
script,div = interactive_flex_chart2(id,xparam=xparam,yparam1=yparam1,
yparam2=yparam2,
promember=promember,plottype=plottype,
workstrokesonly=workstrokesonly)
js_resources = ""
css_resources = ""
# script = res[0]
# div = res[1]
# js_resources = res[2]
@@ -2847,8 +2883,8 @@ def workout_biginteractive_view(request,id=0,message="",successmessage=""):
result = request.user.is_authenticated() and r.rowerplan=='pro'
if result:
promember=1
if request.user == row.user.user:
mayedit=1
if request.user == row.user.user:
mayedit=1
# create interactive plot
@@ -2883,8 +2919,8 @@ def workout_otwpowerplot_view(request,id=0,message="",successmessage=""):
result = request.user.is_authenticated() and r.rowerplan=='pro'
if result:
promember=1
if request.user == row.user.user:
mayedit=1
if request.user == row.user.user:
mayedit=1
# create interactive plot
res = interactive_otw_advanced_pace_chart(id,promember=promember)
@@ -3638,10 +3674,10 @@ def workout_upload_view(request,message=""):
f1 = res[0] # file name
f2 = res[1] # file name incl media directory
# new
fileformat = get_file_type(f2)
if fileformat == 'unknown':
message = "We couldn't recognize the file type"
url = reverse(workout_upload_view,
@@ -3695,6 +3731,10 @@ def workout_upload_view(request,message=""):
# handle speed coach GPS 2
if (fileformat == 'speedcoach2'):
row = SpeedCoach2Parser(f2)
try:
summary = row.allstats()
except:
pass
# handle ErgStick
if (fileformat == 'ergstick'):
@@ -3728,13 +3768,12 @@ def workout_upload_view(request,message=""):
if row == 0:
return HttpResponse("Error: CSV Data File Not Found")
# auto smoothing
pace = row.df[' Stroke500mPace (sec/500m)'].values
# auto smoothing
pace = row.df[' Stroke500mPace (sec/500m)'].values
velo = 500./pace
f = row.df['TimeStamp (sec)'].diff().mean()
windowsize = 2*(int(10./(f)))+1
if not 'originalvelo' in row.df:
row.df['originalvelo'] = velo
@@ -3746,9 +3785,9 @@ def workout_upload_view(request,message=""):
velo3 = pd.Series(velo2)
velo3 = velo3.replace([-np.inf,np.inf],np.nan)
velo3 = velo3.fillna(method='ffill')
pace2 = 500./abs(velo3)
pace2 = 500./abs(velo3)
row.df[' Stroke500mPace (sec/500m)'] = pace2
row.df = row.df.fillna(0)
@@ -3758,7 +3797,6 @@ def workout_upload_view(request,message=""):
os.remove(f2)
except:
pass
# recalculate power data
if workouttype == 'rower' or workouttype == 'dynamic' or workouttype == 'slides':
@@ -3769,19 +3807,18 @@ def workout_upload_view(request,message=""):
except:
pass
if fileformat != 'fit':
if fileformat != 'fit' and summary == '':
summary = row.summary()
summary += '\n'
summary += row.intervalstats_painsled()
averagehr = row.df[' HRCur (bpm)'].mean()
maxhr = row.df[' HRCur (bpm)'].max()
totaldist = row.df['cum_dist'].max()
totaltime = row.df['TimeStamp (sec)'].max()-row.df['TimeStamp (sec)'].min()
totaltime = totaltime+row.df.ix[0,' ElapsedTime (sec)']
hours = int(totaltime/3600.)
minutes = int((totaltime - 3600.*hours)/60.)
seconds = int(totaltime - 3600.*hours - 60.*minutes)
@@ -3802,7 +3839,6 @@ def workout_upload_view(request,message=""):
if (len(ws) != 0):
message = "Warning: This workout probably already exists in the database"
w = Workout(user=r,name=t,date=workoutdate,
workouttype=workouttype,
duration=duration,distance=totaldist,