delayed load of data on cum_flex
Ajax call to load data for cumulative flex chart. It works. Yay!
This commit is contained in:
150
rowers/views.py
150
rowers/views.py
@@ -2526,6 +2526,94 @@ def histo_all(request,theuser=0,
|
||||
})
|
||||
|
||||
# The Flex plot for a large selection of workouts
|
||||
@login_required()
|
||||
def cum_flex_data(
|
||||
request,
|
||||
options={
|
||||
'includereststrokes':False,
|
||||
'workouttypes':['rower','dynamic','slides'],
|
||||
'waterboattype':['1x','2x','2-','4x','4-','8+'],
|
||||
'theuser':0,
|
||||
'xparam':'spm',
|
||||
'yparam1':'power',
|
||||
'yparam2':'None',
|
||||
'enddatestring':'',
|
||||
'startdatestring':'',
|
||||
'deltadays':-1,
|
||||
}):
|
||||
|
||||
if 'options' in request.session:
|
||||
options = request.session['options']
|
||||
|
||||
workouttypes = options['workouttypes']
|
||||
includereststrokes = options['includereststrokes']
|
||||
waterboattype = options['waterboattype']
|
||||
workstrokesonly = not includereststrokes
|
||||
theuser = options['theuser']
|
||||
xparam = options['xparam']
|
||||
yparam1 = options['yparam1']
|
||||
yparam2 = options['yparam2']
|
||||
startdatestring = options['startdatestring']
|
||||
enddatestring = options['enddatestring']
|
||||
deltadays = options['deltadays']
|
||||
|
||||
|
||||
|
||||
startdate = iso8601.parse_date(startdatestring)
|
||||
|
||||
enddate = iso8601.parse_date(enddatestring)
|
||||
|
||||
if deltadays>0:
|
||||
startdate = enddate-datetime.timedelta(days=int(deltadays))
|
||||
|
||||
|
||||
if enddate < startdate:
|
||||
s = enddate
|
||||
enddate = startdate
|
||||
startdate = s
|
||||
|
||||
promember=0
|
||||
if theuser == 0:
|
||||
theuser = request.user.id
|
||||
|
||||
if not request.user.is_anonymous():
|
||||
r = getrower(request.user)
|
||||
result = request.user.is_authenticated() and ispromember(request.user)
|
||||
if result:
|
||||
promember=1
|
||||
|
||||
r2 = getrower(theuser)
|
||||
allworkouts = Workout.objects.filter(user=r2,
|
||||
workouttype__in=workouttypes,
|
||||
boattype__in=waterboattype,
|
||||
startdatetime__gte=startdate,
|
||||
startdatetime__lte=enddate)
|
||||
|
||||
if allworkouts:
|
||||
res = interactive_cum_flex_chart2(allworkouts,xparam=xparam,
|
||||
yparam1=yparam1,
|
||||
yparam2=yparam2,
|
||||
promember=promember,
|
||||
workstrokesonly=workstrokesonly)
|
||||
script = res[0]
|
||||
div = res[1]
|
||||
else:
|
||||
script = ''
|
||||
div = '<p>No erg pieces uploaded for this date range.</p>'
|
||||
|
||||
scripta = script.split('\n')[2:-1]
|
||||
script = ''.join(scripta)
|
||||
|
||||
data = {
|
||||
"script":script,
|
||||
"div":div,
|
||||
}
|
||||
|
||||
return JSONResponse(data)
|
||||
|
||||
|
||||
|
||||
|
||||
@login_required()
|
||||
def cum_flex(request,theuser=0,
|
||||
xparam='spm',
|
||||
@@ -2651,38 +2739,19 @@ def cum_flex(request,theuser=0,
|
||||
})
|
||||
deltaform = DeltaDaysForm()
|
||||
optionsform = StatsOptionsForm()
|
||||
try:
|
||||
r2 = getrower(theuser)
|
||||
allworkouts = Workout.objects.filter(user=r2,
|
||||
workouttype__in=workouttypes,
|
||||
boattype__in=waterboattype,
|
||||
startdatetime__gte=startdate,
|
||||
startdatetime__lte=enddate)
|
||||
|
||||
except Rower.DoesNotExist:
|
||||
allworkouts = []
|
||||
r2=0
|
||||
|
||||
try:
|
||||
u = User.objects.get(id=theuser)
|
||||
except User.DoesNotExist:
|
||||
u = ''
|
||||
|
||||
if allworkouts:
|
||||
res = interactive_cum_flex_chart2(allworkouts,xparam=xparam,
|
||||
yparam1=yparam1,
|
||||
yparam2=yparam2,
|
||||
promember=promember,
|
||||
workstrokesonly=workstrokesonly)
|
||||
script = res[0]
|
||||
div = res[1]
|
||||
js_resources = res[2]
|
||||
css_resources = res[3]
|
||||
else:
|
||||
script = ''
|
||||
div = '<p>No erg pieces uploaded for this date range.</p>'
|
||||
js_resources = ''
|
||||
css_resources = ''
|
||||
script = ''
|
||||
div = """
|
||||
<div id="id_sitready">
|
||||
<p>
|
||||
<blockquote>
|
||||
Sit Ready! We're counting strokes and loading data
|
||||
</blockquote>
|
||||
</p>
|
||||
</div>
|
||||
"""
|
||||
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'}
|
||||
@@ -2702,8 +2771,26 @@ def cum_flex(request,theuser=0,
|
||||
initial[wtype] = False
|
||||
|
||||
|
||||
try:
|
||||
u = User.objects.get(id=theuser)
|
||||
except User.DoesNotExist:
|
||||
u = ''
|
||||
|
||||
optionsform = StatsOptionsForm(initial=initial)
|
||||
|
||||
|
||||
options['includereststrokes'] = includereststrokes
|
||||
options['workouttypes'] =workouttypes
|
||||
options['waterboattype'] =waterboattype
|
||||
options['theuser'] =theuser
|
||||
options['xparam'] =xparam
|
||||
options['yparam1'] =yparam1
|
||||
options['yparam2'] =yparam2
|
||||
options['startdatestring'] = startdatestring
|
||||
options['enddatestring'] =enddatestring
|
||||
options['deltadays'] =deltadays
|
||||
|
||||
|
||||
request.session['options'] = options
|
||||
|
||||
return render(request, 'cum_flex.html',
|
||||
@@ -2728,6 +2815,7 @@ def cum_flex(request,theuser=0,
|
||||
'noylist':noylist,
|
||||
})
|
||||
|
||||
|
||||
# Show the EMpower Oarlock generated Stroke Profile
|
||||
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)
|
||||
def workout_forcecurve_view(request,id=0,workstrokesonly=False):
|
||||
|
||||
Reference in New Issue
Block a user