cumulative flex now also for OTW
This commit is contained in:
@@ -2096,8 +2096,21 @@ def cum_flex(request,theuser=0,
|
||||
enddate=timezone.now()+datetime.timedelta(days=1),
|
||||
deltadays=-1,
|
||||
startdatestring="",
|
||||
enddatestring=""):
|
||||
enddatestring="",
|
||||
options={
|
||||
'includereststrokes':False,
|
||||
'workouttypes':['rower','dynamic','slides']
|
||||
}):
|
||||
|
||||
if 'options' in request.session:
|
||||
options = request.session['options']
|
||||
|
||||
workouttypes = options['workouttypes']
|
||||
includereststrokes = options['includereststrokes']
|
||||
workstrokesonly = not includereststrokes
|
||||
checktypes = ['water','rower','dynamic','slides','skierg',
|
||||
'paddle','snow','other']
|
||||
|
||||
if deltadays>0:
|
||||
startdate = enddate-datetime.timedelta(days=int(deltadays))
|
||||
|
||||
@@ -2131,6 +2144,7 @@ def cum_flex(request,theuser=0,
|
||||
if request.method == 'POST' and "daterange" in request.POST:
|
||||
form = DateRangeForm(request.POST)
|
||||
deltaform = DeltaDaysForm(request.POST)
|
||||
optionsform = StatsOptionsForm()
|
||||
if form.is_valid():
|
||||
startdate = form.cleaned_data['startdate']
|
||||
enddate = form.cleaned_data['enddate']
|
||||
@@ -2140,9 +2154,10 @@ def cum_flex(request,theuser=0,
|
||||
startdate = s
|
||||
elif request.method == 'POST' and "datedelta" in request.POST:
|
||||
deltaform = DeltaDaysForm(request.POST)
|
||||
optionsform = StatsOptionsForm()
|
||||
if deltaform.is_valid():
|
||||
deltadays = deltaform.cleaned_data['deltadays']
|
||||
if deltadays != 0:
|
||||
if deltadays != 0 and isinstance(deltadays, Number):
|
||||
enddate = timezone.now()
|
||||
startdate = enddate-datetime.timedelta(days=deltadays)
|
||||
if startdate > enddate:
|
||||
@@ -2153,23 +2168,50 @@ def cum_flex(request,theuser=0,
|
||||
'startdate': startdate,
|
||||
'enddate': enddate,
|
||||
})
|
||||
else:
|
||||
form = DateRangeForm()
|
||||
optionsform = StatsOptionsForm()
|
||||
elif request.method == 'POST' and 'options' in request.POST:
|
||||
optionsform = StatsOptionsForm(request.POST)
|
||||
if optionsform.is_valid():
|
||||
includereststrokes = optionsform.cleaned_data['includereststrokes']
|
||||
workstrokesonly = not includereststrokes
|
||||
workouttypes = []
|
||||
for type in checktypes:
|
||||
if optionsform.cleaned_data[type]:
|
||||
workouttypes.append(type)
|
||||
|
||||
options = {
|
||||
'includereststrokes':includereststrokes,
|
||||
'workouttypes':workouttypes,
|
||||
}
|
||||
form = DateRangeForm(initial={
|
||||
'startdate': startdate,
|
||||
'enddate': enddate,
|
||||
})
|
||||
deltaform = DeltaDaysForm()
|
||||
else:
|
||||
form = DateRangeForm(initial={
|
||||
'startdate': startdate,
|
||||
'enddate': enddate,
|
||||
})
|
||||
deltaform = DeltaDaysForm()
|
||||
else:
|
||||
form = DateRangeForm(initial={
|
||||
'startdate': startdate,
|
||||
'enddate': enddate,
|
||||
})
|
||||
deltaform = DeltaDaysForm()
|
||||
|
||||
optionsform = StatsOptionsForm()
|
||||
try:
|
||||
r2 = Rower.objects.get(user=theuser)
|
||||
allergworkouts = Workout.objects.filter(user=r2,
|
||||
workouttype__in=['rower','dynamic','slides'],
|
||||
startdatetime__gte=startdate,
|
||||
startdatetime__lte=enddate)
|
||||
allworkouts = Workout.objects.filter(user=r2,
|
||||
workouttype__in=workouttypes,
|
||||
startdatetime__gte=startdate,
|
||||
startdatetime__lte=enddate)
|
||||
|
||||
except Rower.DoesNotExist:
|
||||
allergworkouts = []
|
||||
allworkouts = []
|
||||
r2=0
|
||||
|
||||
try:
|
||||
@@ -2177,11 +2219,12 @@ def cum_flex(request,theuser=0,
|
||||
except User.DoesNotExist:
|
||||
u = ''
|
||||
|
||||
if allergworkouts:
|
||||
res = interactive_cum_flex_chart2(allergworkouts,xparam=xparam,
|
||||
if allworkouts:
|
||||
res = interactive_cum_flex_chart2(allworkouts,xparam=xparam,
|
||||
yparam1=yparam1,
|
||||
yparam2=yparam2,
|
||||
promember=promember)
|
||||
promember=promember,
|
||||
workstrokesonly=workstrokesonly)
|
||||
script = res[0]
|
||||
div = res[1]
|
||||
js_resources = res[2]
|
||||
@@ -2192,6 +2235,26 @@ def cum_flex(request,theuser=0,
|
||||
js_resources = ''
|
||||
css_resources = ''
|
||||
|
||||
axchoicesbasic = {ax[0]:ax[1] for ax in axes if ax[4]=='basic'}
|
||||
axchoicespro = {ax[0]:ax[1] for ax in axes if ax[4]=='pro'}
|
||||
noylist = ["time","distance"]
|
||||
axchoicesbasic.pop("cumdist")
|
||||
|
||||
# set options form correctly
|
||||
initial = {}
|
||||
initial['includereststrokes'] = includereststrokes
|
||||
|
||||
for wtype in checktypes:
|
||||
if wtype in workouttypes:
|
||||
initial[wtype] = True
|
||||
else:
|
||||
initial[wtype] = False
|
||||
|
||||
|
||||
optionsform = StatsOptionsForm(initial=initial)
|
||||
|
||||
request.session['options'] = options
|
||||
|
||||
return render(request, 'cum_flex.html',
|
||||
{'interactiveplot':script,
|
||||
'the_div':div,
|
||||
@@ -2202,12 +2265,16 @@ def cum_flex(request,theuser=0,
|
||||
'startdate':startdate,
|
||||
'enddate':enddate,
|
||||
'form':form,
|
||||
'optionsform':optionsform,
|
||||
'deltaform':deltaform,
|
||||
'xparam':xparam,
|
||||
'yparam1':yparam1,
|
||||
'yparam2':yparam2,
|
||||
'promember':promember,
|
||||
'teams':get_my_teams(request.user),
|
||||
'axchoicesbasic':axchoicesbasic,
|
||||
'axchoicespro':axchoicespro,
|
||||
'noylist':noylist,
|
||||
})
|
||||
|
||||
# Show the EMpower Oarlock generated Stroke Profile
|
||||
|
||||
Reference in New Issue
Block a user