histo now also OTW
This commit is contained in:
121
rowers/views.py
121
rowers/views.py
@@ -2039,7 +2039,45 @@ def rower_process_testcallback(request):
|
||||
|
||||
# View around the Histogram of all strokes. Not implemented in UI
|
||||
@login_required()
|
||||
def histo_all(request,theuser=0):
|
||||
def histo_all(request,theuser=0,
|
||||
startdate=timezone.now()-datetime.timedelta(days=10),
|
||||
enddate=timezone.now()+datetime.timedelta(days=1),
|
||||
deltadays=-1,
|
||||
startdatestring="",
|
||||
enddatestring="",
|
||||
options={
|
||||
'includereststrokes':False,
|
||||
'workouttypes':['rower','dynamic','slides'],
|
||||
'waterboattype':['1x','2x','2-','4x','4-','8+']
|
||||
}):
|
||||
|
||||
if 'options' in request.session:
|
||||
options = request.session['options']
|
||||
|
||||
workouttypes = options['workouttypes']
|
||||
includereststrokes = options['includereststrokes']
|
||||
waterboattype = options['waterboattype']
|
||||
workstrokesonly = not includereststrokes
|
||||
|
||||
|
||||
checktypes = ['water','rower','dynamic','slides','skierg',
|
||||
'paddle','snow','coastal','other']
|
||||
|
||||
|
||||
if deltadays>0:
|
||||
startdate = enddate-datetime.timedelta(days=int(deltadays))
|
||||
|
||||
if startdatestring != "":
|
||||
startdate = iso8601.parse_date(startdatestring)
|
||||
|
||||
if enddatestring != "":
|
||||
enddate = iso8601.parse_date(enddatestring)
|
||||
|
||||
if enddate < startdate:
|
||||
s = enddate
|
||||
enddate = startdate
|
||||
startdate = s
|
||||
|
||||
promember=0
|
||||
if theuser == 0:
|
||||
theuser = request.user.id
|
||||
@@ -2192,6 +2230,7 @@ def cum_flex(request,theuser=0,
|
||||
'workouttypes':workouttypes,
|
||||
'waterboattype':waterboattype,
|
||||
}
|
||||
request.session['options'] = options
|
||||
form = DateRangeForm(initial={
|
||||
'startdate': startdate,
|
||||
'enddate': enddate,
|
||||
@@ -2391,7 +2430,24 @@ def histo(request,theuser=0,
|
||||
enddate=timezone.now(),
|
||||
deltadays=-1,
|
||||
startdatestring="",
|
||||
enddatestring=""):
|
||||
enddatestring="",
|
||||
options={
|
||||
'includereststrokes':False,
|
||||
'workouttypes':['water','rower','dynamic','slides'],
|
||||
'waterboattype':['1x','2x','2-','4x','4-','8+']
|
||||
}):
|
||||
|
||||
if 'options' in request.session:
|
||||
options = request.session['options']
|
||||
|
||||
workouttypes = options['workouttypes']
|
||||
includereststrokes = options['includereststrokes']
|
||||
waterboattype = options['waterboattype']
|
||||
workstrokesonly = not includereststrokes
|
||||
|
||||
|
||||
checktypes = ['water','rower','dynamic','slides','skierg',
|
||||
'paddle','snow','coastal','other']
|
||||
|
||||
if deltadays>0:
|
||||
startdate = enddate-datetime.timedelta(days=int(deltadays))
|
||||
@@ -2426,6 +2482,7 @@ def histo(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']
|
||||
@@ -2435,6 +2492,7 @@ def histo(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 and deltadays != None:
|
||||
@@ -2450,6 +2508,36 @@ def histo(request,theuser=0,
|
||||
})
|
||||
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
|
||||
waterboattype = optionsform.cleaned_data['waterboattype']
|
||||
workouttypes = []
|
||||
for type in checktypes:
|
||||
if optionsform.cleaned_data[type]:
|
||||
workouttypes.append(type)
|
||||
|
||||
|
||||
options = {
|
||||
'includereststrokes':includereststrokes,
|
||||
'workouttypes':workouttypes,
|
||||
'waterboattype':waterboattype,
|
||||
}
|
||||
request.session['options'] = options
|
||||
form = DateRangeForm(initial={
|
||||
'startdate': startdate,
|
||||
'enddate': enddate,
|
||||
})
|
||||
deltaform = DeltaDaysForm()
|
||||
else:
|
||||
form = DateRangeForm(initial={
|
||||
'startdate': startdate,
|
||||
'enddate': enddate,
|
||||
})
|
||||
deltaform = DeltaDaysForm()
|
||||
|
||||
else:
|
||||
form = DateRangeForm(initial={
|
||||
@@ -2457,11 +2545,12 @@ def histo(request,theuser=0,
|
||||
'enddate': enddate,
|
||||
})
|
||||
deltaform = DeltaDaysForm()
|
||||
|
||||
optionsform = StatsOptionsForm()
|
||||
try:
|
||||
r2 = getrower(theuser)
|
||||
allergworkouts = Workout.objects.filter(user=r2,
|
||||
workouttype__in=['rower','dynamic','slides'],
|
||||
workouttype__in=workouttypes,
|
||||
boattype__in=waterboattype,
|
||||
startdatetime__gte=startdate,
|
||||
startdatetime__lte=enddate)
|
||||
|
||||
@@ -2480,8 +2569,28 @@ def histo(request,theuser=0,
|
||||
div = res[1]
|
||||
else:
|
||||
script = ''
|
||||
div = '<p>No erg pieces uploaded for this date range.</p>'
|
||||
typesstring = ', '.join('{}'.format(item) for i,item in enumerate(workouttypes))
|
||||
if 'water' in workouttypes:
|
||||
boatsstring = 'water ('+', '.join('{}'.format(item) for i,item in enumerate(waterboattype))+')'
|
||||
typesstring = typesstring.replace('water',boatsstring)
|
||||
div = '<p>No pieces found for '+typesstring+' for this date range.</p>'
|
||||
|
||||
# set options form correctly
|
||||
initial = {}
|
||||
initial['includereststrokes'] = includereststrokes
|
||||
|
||||
initial['waterboattype'] = waterboattype
|
||||
|
||||
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, 'histo.html',
|
||||
{'interactiveplot':script,
|
||||
@@ -2491,6 +2600,7 @@ def histo(request,theuser=0,
|
||||
'startdate':startdate,
|
||||
'enddate':enddate,
|
||||
'form':form,
|
||||
'optionsform':optionsform,
|
||||
'deltaform':deltaform,
|
||||
'teams':get_my_teams(request.user),
|
||||
})
|
||||
@@ -5208,6 +5318,7 @@ def cumstats(request,theuser=0,
|
||||
'workouttypes':workouttypes,
|
||||
'waterboattype':waterboattype,
|
||||
}
|
||||
request.session['options'] = options
|
||||
form = DateRangeForm()
|
||||
deltaform = DeltaDaysForm()
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user