Merge branch 'release/3.42'
This commit is contained in:
@@ -73,7 +73,8 @@ def errorbar(fig, x, y, source=ColumnDataSource(),
|
|||||||
xerr=False, yerr=False, color='red',
|
xerr=False, yerr=False, color='red',
|
||||||
point_kwargs={}, error_kwargs={}):
|
point_kwargs={}, error_kwargs={}):
|
||||||
|
|
||||||
fig.circle(x, y, source=source, name='data',color=color, **point_kwargs)
|
fig.circle(x, y, source=source, name='data',color=color,
|
||||||
|
**point_kwargs)
|
||||||
|
|
||||||
xvalues = source.data[x]
|
xvalues = source.data[x]
|
||||||
yvalues = source.data[y]
|
yvalues = source.data[y]
|
||||||
@@ -1182,6 +1183,8 @@ def interactive_multiflex(datadf,xparam,yparam,groupby,extratitle='',
|
|||||||
|
|
||||||
if groupby == 'workoutid':
|
if groupby == 'workoutid':
|
||||||
groupname = 'Workout'
|
groupname = 'Workout'
|
||||||
|
elif groupby == 'date':
|
||||||
|
groupname = 'Date'
|
||||||
else:
|
else:
|
||||||
groupname = axlabels[groupby]
|
groupname = axlabels[groupby]
|
||||||
|
|
||||||
@@ -1234,12 +1237,29 @@ def interactive_multiflex(datadf,xparam,yparam,groupby,extratitle='',
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,resize,hover'
|
TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,resize'
|
||||||
|
|
||||||
|
if groupby != 'date':
|
||||||
|
hover = HoverTool(names=['data'],
|
||||||
|
tooltips = [
|
||||||
|
(groupby,'@groupval{1.1}')
|
||||||
|
])
|
||||||
|
else:
|
||||||
|
hover = HoverTool(names=['data'],
|
||||||
|
tooltips = [
|
||||||
|
(groupby,'@groupval')
|
||||||
|
])
|
||||||
|
|
||||||
|
hover.mode = 'mouse'
|
||||||
|
TOOLS = [SaveTool(),PanTool(),BoxZoomTool(),WheelZoomTool(),
|
||||||
|
ResetTool(),TapTool(),ResizeTool(),hover]
|
||||||
|
|
||||||
|
|
||||||
plot = Figure(x_axis_type=x_axis_type,y_axis_type=y_axis_type,
|
plot = Figure(x_axis_type=x_axis_type,y_axis_type=y_axis_type,
|
||||||
tools=TOOLS,
|
tools=TOOLS,
|
||||||
toolbar_location="above",
|
toolbar_location="above",
|
||||||
toolbar_sticky=False)
|
toolbar_sticky=False)
|
||||||
|
|
||||||
# add watermark
|
# add watermark
|
||||||
plot.extra_y_ranges = {"watermark": watermarkrange}
|
plot.extra_y_ranges = {"watermark": watermarkrange}
|
||||||
plot.extra_x_ranges = {"watermark": watermarkrange}
|
plot.extra_x_ranges = {"watermark": watermarkrange}
|
||||||
@@ -1264,7 +1284,7 @@ def interactive_multiflex(datadf,xparam,yparam,groupby,extratitle='',
|
|||||||
point_kwargs={
|
point_kwargs={
|
||||||
'line_color':None,
|
'line_color':None,
|
||||||
'legend':yparamname,
|
'legend':yparamname,
|
||||||
'size':10,
|
'size':"groupsize",
|
||||||
})
|
})
|
||||||
|
|
||||||
if xparam == 'workoutid':
|
if xparam == 'workoutid':
|
||||||
@@ -1290,20 +1310,6 @@ def interactive_multiflex(datadf,xparam,yparam,groupby,extratitle='',
|
|||||||
minutes = ["%M"]
|
minutes = ["%M"]
|
||||||
)
|
)
|
||||||
|
|
||||||
hover = plot.select(dict(type=HoverTool))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if groupby != 'date':
|
|
||||||
hover.tooltips = OrderedDict([
|
|
||||||
(groupby,'@groupval{1.1}'),
|
|
||||||
])
|
|
||||||
else:
|
|
||||||
hover.tooltips = OrderedDict([
|
|
||||||
(groupby,'@groupval'),
|
|
||||||
])
|
|
||||||
|
|
||||||
hover.mode = 'mouse'
|
|
||||||
|
|
||||||
script,div = components(plot)
|
script,div = components(plot)
|
||||||
|
|
||||||
|
|||||||
200
rowers/views.py
200
rowers/views.py
@@ -3469,6 +3469,56 @@ def multiflex_view(request,userid=0,
|
|||||||
ids = [int(w.id) for w in workouts]
|
ids = [int(w.id) for w in workouts]
|
||||||
request.session['ids'] = ids
|
request.session['ids'] = ids
|
||||||
|
|
||||||
|
else:
|
||||||
|
return HttpResponse("Form is not valid")
|
||||||
|
elif request.method == 'POST' and 'ids' in request.session:
|
||||||
|
chartform = MultiFlexChoiceForm(request.POST)
|
||||||
|
if chartform.is_valid():
|
||||||
|
xparam = chartform.cleaned_data['xparam']
|
||||||
|
yparam = chartform.cleaned_data['yparam']
|
||||||
|
includereststrokes = chartform.cleaned_data['includereststrokes']
|
||||||
|
ploterrorbars = chartform.cleaned_data['ploterrorbars']
|
||||||
|
request.session['ploterrorbars'] = ploterrorbars
|
||||||
|
request.session['includereststrokes'] = includereststrokes
|
||||||
|
workstrokesonly = not includereststrokes
|
||||||
|
|
||||||
|
groupby = chartform.cleaned_data['groupby']
|
||||||
|
binsize = chartform.cleaned_data['binsize']
|
||||||
|
if binsize <= 0:
|
||||||
|
binsize = 1
|
||||||
|
if groupby == 'pace':
|
||||||
|
binsize *= 1000.
|
||||||
|
|
||||||
|
spmmin = chartform.cleaned_data['spmmin']
|
||||||
|
spmmax = chartform.cleaned_data['spmmax']
|
||||||
|
workmin = chartform.cleaned_data['workmin']
|
||||||
|
workmax = chartform.cleaned_data['workmax']
|
||||||
|
|
||||||
|
ids = request.session['ids']
|
||||||
|
request.session['ids'] = ids
|
||||||
|
workouts = dataprep.get_workouts(ids,userid)
|
||||||
|
if not workouts:
|
||||||
|
message = 'Error: Workouts in session storage do not belong to this user.'
|
||||||
|
messages.error(request,message)
|
||||||
|
url = reverse(user_multiflex_select,
|
||||||
|
kwargs={
|
||||||
|
'userid':userid,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
|
# workouts = [Workout.objects.get(id=id) for id in ids]
|
||||||
|
|
||||||
|
labeldict = {
|
||||||
|
int(w.id): w.__unicode__() for w in workouts
|
||||||
|
}
|
||||||
|
|
||||||
|
else:
|
||||||
|
return HttpResponse("invalid form")
|
||||||
|
else:
|
||||||
|
url = reverse(user_multiflex_select)
|
||||||
|
return HttpResponseRedirect(url)
|
||||||
|
|
||||||
fieldlist,fielddict = dataprep.getstatsfields()
|
fieldlist,fielddict = dataprep.getstatsfields()
|
||||||
fieldlist = [xparam,yparam,groupby,
|
fieldlist = [xparam,yparam,groupby,
|
||||||
'workoutid','spm','driveenergy',
|
'workoutid','spm','driveenergy',
|
||||||
@@ -3517,12 +3567,17 @@ def multiflex_view(request,userid=0,
|
|||||||
yvalues = groups.mean()[yparam]
|
yvalues = groups.mean()[yparam]
|
||||||
xerror = groups.std()[xparam]
|
xerror = groups.std()[xparam]
|
||||||
yerror = groups.std()[yparam]
|
yerror = groups.std()[yparam]
|
||||||
|
groupsize = groups.count()[xparam]
|
||||||
|
|
||||||
|
#groupsize = 15.*np.log10(1+99.*groupsize/float(max(groupsize)))
|
||||||
|
groupsize = 30.*np.sqrt(groupsize/float(max(groupsize)))
|
||||||
|
|
||||||
df = pd.DataFrame({
|
df = pd.DataFrame({
|
||||||
xparam:xvalues,
|
xparam:xvalues,
|
||||||
yparam:yvalues,
|
yparam:yvalues,
|
||||||
'xerror':xerror,
|
'xerror':xerror,
|
||||||
'yerror':yerror,
|
'yerror':yerror,
|
||||||
|
'groupsize':groupsize,
|
||||||
})
|
})
|
||||||
|
|
||||||
if groupby != 'date':
|
if groupby != 'date':
|
||||||
@@ -3558,152 +3613,7 @@ def multiflex_view(request,userid=0,
|
|||||||
'userid':userid,
|
'userid':userid,
|
||||||
'teams':get_my_teams(request.user),
|
'teams':get_my_teams(request.user),
|
||||||
})
|
})
|
||||||
else:
|
|
||||||
return HttpResponse("Form is not valid")
|
|
||||||
elif request.method == 'POST' and 'ids' in request.session:
|
|
||||||
chartform = MultiFlexChoiceForm(request.POST)
|
|
||||||
if chartform.is_valid():
|
|
||||||
xparam = chartform.cleaned_data['xparam']
|
|
||||||
yparam = chartform.cleaned_data['yparam']
|
|
||||||
includereststrokes = chartform.cleaned_data['includereststrokes']
|
|
||||||
ploterrorbars = chartform.cleaned_data['ploterrorbars']
|
|
||||||
request.session['ploterrorbars'] = ploterrorbars
|
|
||||||
request.session['includereststrokes'] = includereststrokes
|
|
||||||
workstrokesonly = not includereststrokes
|
|
||||||
|
|
||||||
groupby = chartform.cleaned_data['groupby']
|
|
||||||
binsize = chartform.cleaned_data['binsize']
|
|
||||||
if binsize <= 0:
|
|
||||||
binsize = 1
|
|
||||||
if groupby == 'pace':
|
|
||||||
binsize *= 1000.
|
|
||||||
|
|
||||||
spmmin = chartform.cleaned_data['spmmin']
|
|
||||||
spmmax = chartform.cleaned_data['spmmax']
|
|
||||||
workmin = chartform.cleaned_data['workmin']
|
|
||||||
workmax = chartform.cleaned_data['workmax']
|
|
||||||
|
|
||||||
ids = request.session['ids']
|
|
||||||
request.session['ids'] = ids
|
|
||||||
workouts = dataprep.get_workouts(ids,userid)
|
|
||||||
if not workouts:
|
|
||||||
message = 'Error: Workouts in session storage do not belong to this user.'
|
|
||||||
messages.error(request,message)
|
|
||||||
url = reverse(user_multiflex_select,
|
|
||||||
kwargs={
|
|
||||||
'userid':userid,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return HttpResponseRedirect(url)
|
|
||||||
|
|
||||||
# workouts = [Workout.objects.get(id=id) for id in ids]
|
|
||||||
|
|
||||||
labeldict = {
|
|
||||||
int(w.id): w.__unicode__() for w in workouts
|
|
||||||
}
|
|
||||||
|
|
||||||
fieldlist,fielddict = dataprep.getstatsfields()
|
|
||||||
fieldlist = [xparam,yparam,groupby,
|
|
||||||
'workoutid','spm','driveenergy',
|
|
||||||
'workoutstate']
|
|
||||||
|
|
||||||
# prepare data frame
|
|
||||||
datadf = dataprep.read_cols_df_sql(ids,fieldlist)
|
|
||||||
|
|
||||||
|
|
||||||
datadf = dataprep.clean_df_stats(datadf,workstrokesonly=workstrokesonly)
|
|
||||||
|
|
||||||
datadf = dataprep.filter_df(datadf,'spm',spmmin,
|
|
||||||
largerthan=True)
|
|
||||||
datadf = dataprep.filter_df(datadf,'spm',spmmax,
|
|
||||||
largerthan=False)
|
|
||||||
datadf = dataprep.filter_df(datadf,'driveenergy',workmin,
|
|
||||||
largerthan=True)
|
|
||||||
datadf = dataprep.filter_df(datadf,'driveneergy',workmax,
|
|
||||||
largerthan=False)
|
|
||||||
|
|
||||||
datadf.dropna(axis=0,how='any',inplace=True)
|
|
||||||
|
|
||||||
|
|
||||||
datemapping = {
|
|
||||||
w.id:w.date for w in workouts
|
|
||||||
}
|
|
||||||
datadf['date'] = datadf['workoutid']
|
|
||||||
datadf['date'].replace(datemapping,inplace=True)
|
|
||||||
today = datetime.date.today()
|
|
||||||
datadf['days ago'] = map(lambda x : x.days, datadf.date - today)
|
|
||||||
|
|
||||||
if groupby != 'date':
|
|
||||||
bins = np.arange(datadf[groupby].min()-binsize,
|
|
||||||
datadf[groupby].max()+binsize,
|
|
||||||
binsize)
|
|
||||||
groups = datadf.groupby(pd.cut(datadf[groupby],bins,
|
|
||||||
labels=False))
|
|
||||||
else:
|
|
||||||
bins = np.arange(datadf['days ago'].min()-binsize,
|
|
||||||
datadf['days ago'].max()+binsize,
|
|
||||||
binsize,
|
|
||||||
)
|
|
||||||
groups = datadf.groupby(pd.cut(datadf['days ago'], bins,
|
|
||||||
labels=False))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
xvalues = groups.mean()[xparam]
|
|
||||||
yvalues = groups.mean()[yparam]
|
|
||||||
xerror = groups.std()[xparam]
|
|
||||||
yerror = groups.std()[yparam]
|
|
||||||
|
|
||||||
df = pd.DataFrame({
|
|
||||||
xparam:xvalues,
|
|
||||||
yparam:yvalues,
|
|
||||||
'xerror':xerror,
|
|
||||||
'yerror':yerror,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
if groupby == 'pace':
|
|
||||||
df['groupval'] = groups.mean()[groupby].fillna(value=0)/1000.
|
|
||||||
elif groupby != 'date':
|
|
||||||
try:
|
|
||||||
df['groupval'] = groups.mean()[groupby],
|
|
||||||
except ValueError:
|
|
||||||
df['groupval'] = groups.mean()[groupby].fillna(value=0)
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
df['groupval'] = [x.strftime("%Y-%m-%d") for x in groups.min()[groupby]]
|
|
||||||
except AttributeError:
|
|
||||||
df['groupval'] = groups.mean()['days ago'].fillna(value=0)
|
|
||||||
|
|
||||||
|
|
||||||
if userid == 0:
|
|
||||||
extratitle = ''
|
|
||||||
else:
|
|
||||||
u = User.objects.get(id=userid)
|
|
||||||
extratitle = ' '+u.first_name+' '+u.last_name
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
script,div = interactive_multiflex(df,xparam,yparam,
|
|
||||||
groupby,
|
|
||||||
extratitle=extratitle,
|
|
||||||
ploterrorbars=ploterrorbars)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return render(request,'multiflex.html',
|
|
||||||
{'interactiveplot':script,
|
|
||||||
'the_div':div,
|
|
||||||
'chartform':chartform,
|
|
||||||
'userid':userid,
|
|
||||||
'teams':get_my_teams(request.user),
|
|
||||||
})
|
|
||||||
else:
|
|
||||||
return HttpResponse("invalid form")
|
|
||||||
else:
|
|
||||||
url = reverse(user_multiflex_select)
|
|
||||||
return HttpResponseRedirect(url)
|
|
||||||
|
|
||||||
# Box plots
|
# Box plots
|
||||||
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)
|
@user_passes_test(ispromember,login_url="/",redirect_field_name=None)
|
||||||
|
|||||||
Reference in New Issue
Block a user