Merge branch 'feature/sliders' into develop
This commit is contained in:
@@ -787,10 +787,24 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
|
||||
thedata['driveenergy'] = thedata[' DriveLength (meters)']*thedata[' AverageDriveForce (lbs)']*4.44822
|
||||
|
||||
# throw out zeros from dataframe
|
||||
thedata = thedata[thedata[csvcolumns[yparam1]] > 0]
|
||||
thedata = thedata[thedata[csvcolumns[xparam]] > 0]
|
||||
if yparam2 != 'None':
|
||||
thedata = thedata[thedata[csvcolumns[yparam2]] > 0]
|
||||
|
||||
# check if dataframe not empty
|
||||
if thedata.empty:
|
||||
return ['','<p>No non-zero data in selection</p>','','']
|
||||
|
||||
spm = thedata.ix[:,csvcolumns['spm']]
|
||||
|
||||
f = thedata['TimeStamp (sec)'].diff().mean()
|
||||
windowsize = 2*(int(10./(f)))+1
|
||||
if not np.isnan(f):
|
||||
windowsize = 2*(int(10./(f)))+1
|
||||
else:
|
||||
windowsize = 5
|
||||
|
||||
if windowsize <= 3:
|
||||
windowsize = 5
|
||||
|
||||
@@ -806,8 +820,6 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
|
||||
thedata['drivespeed'] = drivelength/thedata[' DriveTime (ms)']*1.0e3
|
||||
|
||||
# get user
|
||||
# u = User.objects.get(id=row.user.id)
|
||||
|
||||
x1 = thedata.ix[:,csvcolumns[xparam]]
|
||||
|
||||
@@ -819,9 +831,31 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
|
||||
|
||||
if xparam=='time':
|
||||
xaxmax = get_datetimes([x1.max()])[0]
|
||||
xaxmin = get_datetimes([x1.min()])[0]
|
||||
xaxmax = x1.max()
|
||||
xaxmin = x1.min()
|
||||
xaxmax = get_datetimes([xaxmax],tzinfo=1)[0]
|
||||
xaxmin = get_datetimes([xaxmin],tzinfo=1)[0]
|
||||
x1 = get_datetimes(x1,tzinfo=1)
|
||||
elif xparam=='distance':
|
||||
xaxmax = x1.max()
|
||||
xaxmin = x1.min()
|
||||
else:
|
||||
xaxmax = yaxmaxima[xparam]
|
||||
xaxmin = yaxminima[xparam]
|
||||
|
||||
# average values
|
||||
if xparam != 'time':
|
||||
x1mean = x1.mean()
|
||||
else:
|
||||
x1mean = 0
|
||||
|
||||
y1mean = y1.mean()
|
||||
y2mean = y2.mean()
|
||||
|
||||
if xparam != 'time':
|
||||
xvals = xaxmin+np.arange(100)*(xaxmax-xaxmin)/100.
|
||||
else:
|
||||
xvals = np.arange(100)
|
||||
|
||||
x_axis_type = 'linear'
|
||||
y_axis_type = 'linear'
|
||||
@@ -836,7 +870,6 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
|
||||
|
||||
time = thedata.ix[:,csvcolumns['time']]
|
||||
time = time-time[0]
|
||||
|
||||
hr = thedata.ix[:,csvcolumns['hr']]
|
||||
if windowsize > 3:
|
||||
@@ -849,6 +882,7 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
|
||||
power = thedata.ix[:,csvcolumns['power']]
|
||||
|
||||
|
||||
# Add hover to this comma-separated string and see what changes
|
||||
if (promember==1):
|
||||
TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,hover,resize,crosshair'
|
||||
@@ -856,11 +890,21 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
TOOLS = 'pan,box_zoom,wheel_zoom,reset,tap,hover,crosshair'
|
||||
|
||||
plot = Figure(x_axis_type=x_axis_type,y_axis_type=y_axis_type,
|
||||
plot_width=900,
|
||||
tools=TOOLS,
|
||||
toolbar_location="above",
|
||||
toolbar_sticky=False)
|
||||
|
||||
x1means = Span(location=x1mean,dimension='height',line_color='green',
|
||||
line_dash=[6,6], line_width=2)
|
||||
|
||||
y1means = Span(location=y1mean,dimension='width',line_color='blue',
|
||||
line_dash=[6,6],line_width=2)
|
||||
y2means = y1means
|
||||
|
||||
if (xparam != 'time') and (xparam != 'distance'):
|
||||
plot.add_layout(x1means)
|
||||
|
||||
plot.add_layout(y1means)
|
||||
|
||||
source = ColumnDataSource(
|
||||
data = dict(
|
||||
@@ -877,9 +921,24 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
)
|
||||
)
|
||||
|
||||
source2 = ColumnDataSource(
|
||||
data = dict(
|
||||
x1=x1,
|
||||
y1=y1,
|
||||
y2=y2,
|
||||
time=niceformat(get_datetimes(time,tzinfo=1)),
|
||||
pace=nicepaceformat(get_datetimes(pace)),
|
||||
hr = hr,
|
||||
spm = spm,
|
||||
spmc=np.rint(10*spm)/10.,
|
||||
distance=distance,
|
||||
power=power,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
# plot.circle('x1','y1',source=source,legend=yparam1,size=3)
|
||||
plot.circle('x1','y1',source=source,fill_alpha=0.3,line_color=None,
|
||||
plot.circle('x1','y1',source=source2,fill_alpha=0.3,line_color=None,
|
||||
legend=yparamname1,
|
||||
)
|
||||
|
||||
@@ -921,11 +980,17 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
|
||||
plot.circle('x1','y2',color="red",y_range_name="yax2",
|
||||
legend=yparamname2,
|
||||
source=source,fill_alpha=0.3,line_color=None)
|
||||
source=source2,fill_alpha=0.3,line_color=None)
|
||||
|
||||
plot.add_layout(LinearAxis(y_range_name="yax2",
|
||||
axis_label=axlabels[yparam2]),'right')
|
||||
|
||||
y2means = Span(location=y2mean,dimension='width',line_color='red',
|
||||
line_dash=[6,6],line_width=2,y_range_name="yax2")
|
||||
|
||||
|
||||
plot.add_layout(y2means)
|
||||
|
||||
hover = plot.select(dict(type=HoverTool))
|
||||
|
||||
|
||||
@@ -939,11 +1004,119 @@ def interactive_cum_flex_chart(theworkouts,promember=0,
|
||||
|
||||
hover.mode = 'mouse'
|
||||
|
||||
callback = CustomJS(args = dict(source=source,source2=source2,
|
||||
x1means=x1means,
|
||||
y1means=y1means,
|
||||
y2means=y2means), code="""
|
||||
var data = source.data
|
||||
var data2 = source2.data
|
||||
var x1 = data['x1']
|
||||
var y1 = data['y1']
|
||||
var y2 = data['y2']
|
||||
var spm1 = data['spm']
|
||||
var time1 = data['time']
|
||||
var pace1 = data['pace']
|
||||
var hr1 = data['hr']
|
||||
var spmc1 = data['spmc']
|
||||
var distance1 = data['distance']
|
||||
var power1 = data['power']
|
||||
|
||||
var minspm = minspm.value
|
||||
var maxspm = maxspm.value
|
||||
var mindist = mindist.value
|
||||
var maxdist = maxdist.value
|
||||
var xm = 0
|
||||
var ym1 = 0
|
||||
var ym2 = 0
|
||||
|
||||
data2['x1'] = []
|
||||
data2['y1'] = []
|
||||
data2['y2'] = []
|
||||
data2['spm'] = []
|
||||
data2['time'] = []
|
||||
data2['pace'] = []
|
||||
data2['hr'] = []
|
||||
data2['spmc'] = []
|
||||
data2['distance'] = []
|
||||
data2['power'] = []
|
||||
data2['x1mean'] = []
|
||||
data2['y1mean'] = []
|
||||
data2['y2mean'] = []
|
||||
data2['xvals'] = []
|
||||
data2['y1vals'] = []
|
||||
data2['y2vals'] = []
|
||||
|
||||
for (i=0; i<x1.length; i++) {
|
||||
if (spm1[i]>=minspm && spm1[i]<=maxspm) {
|
||||
if (distance1[i]>=mindist && distance1[i]<=maxdist) {
|
||||
data2['x1'].push(x1[i])
|
||||
data2['y1'].push(y1[i])
|
||||
data2['y2'].push(y2[i])
|
||||
data2['spm'].push(spm1[i])
|
||||
data2['time'].push(time1[i])
|
||||
data2['pace'].push(pace1[i])
|
||||
data2['hr'].push(hr1[i])
|
||||
data2['spmc'].push(spmc1[i])
|
||||
data2['distance'].push(distance1[i])
|
||||
data2['power'].push(power1[i])
|
||||
|
||||
xm += x1[i]
|
||||
ym1 += y1[i]
|
||||
ym2 += y2[i]
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xm /= data2['x1'].length
|
||||
ym1 /= data2['x1'].length
|
||||
ym2 /= data2['x1'].length
|
||||
|
||||
data2['x1mean'] = [xm,xm]
|
||||
data2['y1mean'] = [ym1,ym1]
|
||||
data2['y2mean'] = [ym2,ym2]
|
||||
x1means.location = xm
|
||||
y1means.location = ym1
|
||||
y2means.location = ym2
|
||||
|
||||
source2.trigger('change');
|
||||
""")
|
||||
|
||||
slider_spm_min = Slider(start=15.0, end=55,value=15.0, step=.1,
|
||||
title="Min SPM",callback=callback)
|
||||
callback.args["minspm"] = slider_spm_min
|
||||
|
||||
|
||||
slider_spm_max = Slider(start=15.0, end=55,value=55.0, step=.1,
|
||||
title="Max SPM",callback=callback)
|
||||
callback.args["maxspm"] = slider_spm_max
|
||||
|
||||
distmax = 100+100*int(distance.max()/100.)
|
||||
|
||||
slider_dist_min = Slider(start=0,end=distmax,value=0,step=1,
|
||||
title="Min Distance",callback=callback)
|
||||
callback.args["mindist"] = slider_dist_min
|
||||
|
||||
slider_dist_max = Slider(start=0,end=distmax,value=distmax,
|
||||
step=1,
|
||||
title="Max Distance",callback=callback)
|
||||
callback.args["maxdist"] = slider_dist_max
|
||||
|
||||
layout = layoutrow([layoutcolumn([slider_spm_min,
|
||||
slider_spm_max,
|
||||
slider_dist_min,
|
||||
slider_dist_max,
|
||||
],
|
||||
),
|
||||
plot])
|
||||
|
||||
script, div = components(layout)
|
||||
js_resources = INLINE.render_js()
|
||||
css_resources = INLINE.render_css()
|
||||
|
||||
|
||||
script, div = components(plot)
|
||||
|
||||
return [script,div]
|
||||
return [script,div,js_resources,css_resources]
|
||||
|
||||
|
||||
|
||||
@@ -1389,7 +1562,6 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
y2 = y1
|
||||
|
||||
if xparam=='time':
|
||||
|
||||
xaxmax = x1.max()
|
||||
xaxmin = x1.min()
|
||||
xaxmax = get_datetimes([xaxmax],tzinfo=1)[0]
|
||||
@@ -1574,6 +1746,7 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
plot.line('x1','y2',color="red",y_range_name="yax2",
|
||||
legend=axlabels[yparam2],
|
||||
source=source2)
|
||||
<<<<<<< HEAD
|
||||
|
||||
elif plottype=='scatter':
|
||||
# plot.circle(x1,y2,color="red",y_range_name="yax2",legend=yparam2,
|
||||
@@ -1605,6 +1778,39 @@ def interactive_flex_chart2(id=0,promember=0,
|
||||
|
||||
hover.mode = 'mouse'
|
||||
|
||||
=======
|
||||
|
||||
elif plottype=='scatter':
|
||||
# plot.circle(x1,y2,color="red",y_range_name="yax2",legend=yparam2,
|
||||
# source=source,size=3)
|
||||
plot.scatter('x1','y2',source=source2,legend=axlabels[yparam2]
|
||||
,fill_alpha=0.4,
|
||||
line_color=None,color="red",y_range_name="yax2")
|
||||
|
||||
plot.add_layout(LinearAxis(y_range_name="yax2",
|
||||
axis_label=axlabels[yparam2]),'right')
|
||||
|
||||
y2means = Span(location=y2mean,dimension='width',line_color='red',
|
||||
line_dash=[6,6],line_width=2,y_range_name="yax2")
|
||||
|
||||
|
||||
plot.add_layout(y2means)
|
||||
|
||||
hover = plot.select(dict(type=HoverTool))
|
||||
|
||||
|
||||
hover.tooltips = OrderedDict([
|
||||
('Time','@time'),
|
||||
('Distance','@distance'),
|
||||
('Pace','@pace'),
|
||||
('HR','@hr'),
|
||||
('SPM','@spmc{1.1}'),
|
||||
('Power','@power{int}'),
|
||||
])
|
||||
|
||||
hover.mode = 'mouse'
|
||||
|
||||
>>>>>>> feature/sliders
|
||||
callback = CustomJS(args = dict(source=source,source2=source2,
|
||||
x1means=x1means,
|
||||
y1means=y1means,
|
||||
|
||||
Reference in New Issue
Block a user