Private
Public Access
1
0

some improvement in compare plot

This commit is contained in:
Sander Roosendaal
2017-02-23 15:03:56 +01:00
parent 27acec196a
commit 2b49407af3
3 changed files with 75 additions and 39 deletions

View File

@@ -19,7 +19,7 @@ from bokeh.layouts import layout,widgetbox
from bokeh.layouts import row as layoutrow from bokeh.layouts import row as layoutrow
from bokeh.layouts import column as layoutcolumn from bokeh.layouts import column as layoutcolumn
from bokeh.models import LinearAxis,LogAxis,Range1d,DatetimeTickFormatter,HoverTool from bokeh.models import LinearAxis,LogAxis,Range1d,DatetimeTickFormatter,HoverTool
from bokeh.io import output_file, show from bokeh.io import output_file, show, vplot
from bokeh.models import ( from bokeh.models import (
GMapPlot, GMapOptions, ColumnDataSource, Circle, GMapPlot, GMapOptions, ColumnDataSource, Circle,
DataRange1d, PanTool, WheelZoomTool, BoxSelectTool, DataRange1d, PanTool, WheelZoomTool, BoxSelectTool,
@@ -1725,7 +1725,7 @@ def interactive_multiple_compare_chart(ids,xparam,yparam,plottype='line',
def interactive_comparison_chart(id1=0,id2=0,xparam='distance',yparam='spm', def interactive_comparison_chart(id1=0,id2=0,xparam='distance',yparam='spm',
promember=0,plottype='line'): promember=0,plottype='line'):
@@ -1743,8 +1743,8 @@ def interactive_comparison_chart(id1=0,id2=0,xparam='distance',yparam='spm',
rowdata2 = dataprep.getsmallrowdata_db(columns,ids=[id2]) rowdata2 = dataprep.getsmallrowdata_db(columns,ids=[id2])
row1 = Workout.objects.get(id=id1) row1 = Workout.objects.get(id=id1)
row2 = Workout.objects.get(id=id2) row2 = Workout.objects.get(id=id2)
if rowdata1.empty: if rowdata1.empty:
return "","CSV Data File Not Found" return "","CSV Data File Not Found"
else: else:
@@ -1797,32 +1797,39 @@ def interactive_comparison_chart(id1=0,id2=0,xparam='distance',yparam='spm',
TOOLS = 'pan,box_zoom,wheel_zoom,reset,tap,hover,crosshair' TOOLS = 'pan,box_zoom,wheel_zoom,reset,tap,hover,crosshair'
data = pd.DataFrame( data1 = pd.DataFrame(
dict( dict(
x1=x1, x1=x1,
x2=x2,
y1=y1, y1=y1,
y2=y2,
ftime1=ftime1, ftime1=ftime1,
ftime2=ftime2,
fpace1=fpace1, fpace1=fpace1,
fpace2=fpace2,
hr1 = hr1, hr1 = hr1,
hr2 = hr2,
spm1 = spm1, spm1 = spm1,
spm2 = spm2,
distance1=distance1, distance1=distance1,
)
).dropna()
data2 = pd.DataFrame(
dict(
x2=x2,
y2=y2,
ftime2=ftime2,
fpace2=fpace2,
hr2 = hr2,
spm2 = spm2,
distance2=distance2, distance2=distance2,
) )
).dropna() ).dropna()
source = ColumnDataSource(
data source1 = ColumnDataSource(
data1
) )
source2 = ColumnDataSource(
data2
)
# create interactive plot # create interactive plot
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,
@@ -1831,21 +1838,28 @@ def interactive_comparison_chart(id1=0,id2=0,xparam='distance',yparam='spm',
toolbar_sticky=False) toolbar_sticky=False)
if plottype=='line': if plottype=='line':
plot.line('x1','y1',source=source,color="blue",legend=row1.name) l1 = plot.line('x1','y1',source=source1,
plot.line('x2','y2',source=source,color="red",legend=row2.name) color="blue",legend=row1.name,
)
l2 = plot.line('x2','y2',source=source2,
color="red",legend=row2.name,
)
elif plottype=='scatter': elif plottype=='scatter':
plot.scatter('x1','y1',source=source,legend=row1.name,fill_alpha=0.4, l1 = plot.scatter('x1','y1',source=source1,legend=row1.name,
line_color=None) fill_alpha=0.4,
plot.scatter('x2','y2',source=source,legend=row2.name,fill_alpha=0.4, line_color=None)
line_color=None,color="red") l2 = plot.scatter('x2','y2',source=source2,legend=row2.name,
fill_alpha=0.4,
line_color=None,color="red")
plot.legend.location = "bottom_right" plot.legend.location = "bottom_right"
plot.title.text = row1.name+' vs '+row2.name plot.title.text = row1.name+' vs '+row2.name
plot.title.text_font_size=value("1.2em") plot.title.text_font_size=value("1.2em")
plot.xaxis.axis_label = axlabels[xparam] plot.xaxis.axis_label = axlabels[xparam]
plot.yaxis.axis_label = axlabels[yparam]
if xparam == 'time': if xparam == 'time':
plot.xaxis[0].formatter = DatetimeTickFormatter( plot.xaxis[0].formatter = DatetimeTickFormatter(
@@ -1863,27 +1877,53 @@ def interactive_comparison_chart(id1=0,id2=0,xparam='distance',yparam='spm',
seconds = ["%S"], seconds = ["%S"],
minutes = ["%M"] minutes = ["%M"]
) )
plot.y_range = Range1d(ymin,ymax) plot.y_range = Range1d(ymin,ymax)
#plot.y_range = Range1d(ymin,ymax)
hover = plot.select(dict(type=HoverTool)) TIPS = OrderedDict([
hover.tooltips = OrderedDict([
('time1','@ftime1'), ('time1','@ftime1'),
('time2','@ftime2'), ('pace1','@fpace1'),
('pace1','@fpace1'),
('pace2','@fpace2'),
('hr1','@hr1'), ('hr1','@hr1'),
('hr2','@hr2'),
('spm1','@spm1{1.1}'), ('spm1','@spm1{1.1}'),
('spm2','@spm2{1.1}'),
('distance1','@distance1{5}'), ('distance1','@distance1{5}'),
])
TIPS2 = OrderedDict([
('time2','@ftime2'),
('pace2','@fpace2'),
('hr2','@hr2'),
('spm2','@spm2{1.1}'),
('distance2','@distance2{5}'), ('distance2','@distance2{5}'),
]) ])
plot.add_tools(HoverTool(renderers=[l1],tooltips=TIPS))
plot.add_tools(HoverTool(renderers=[l2],tooltips=TIPS2))
# hover1 = plot.select(dict(type=HoverTool))
# hover2 = plot.select(dict(type=HoverTool))
# hover1.renderers = [l1]
# hover2.renderers = [l2]
# hover1.tooltips = OrderedDict([
# ('time1','@ftime1'),
# ('pace1','@fpace1'),
# ('hr1','@hr1'),
# ('spm1','@spm1{1.1}'),
# ('distance1','@distance1{5}'),
# ])
# hover2.tooltips = OrderedDict([
# ('time2','@ftime2'),
# ('pace2','@fpace2'),
# ('hr2','@hr2'),
# ('spm2','@spm2{1.1}'),
# ('distance2','@distance2{5}'),
# ])
hover.mode = 'mouse'
# hover1.mode = 'mouse'
# hover2.mode = 'mouse'
script, div = components(plot) script, div = components(plot)
return [script,div] return [script,div]

View File

@@ -9,7 +9,7 @@
<div class="grid_12"> <div class="grid_12">
<div class="grid_8 suffix_4"> <div class="grid_8 suffix_4">
{% include "teambuttons.html" with teamid=teamid%} {% include "teambuttons.html" with teamid=team.id %}
</div> </div>
</div> </div>
<div class="grid_12 alpha"> <div class="grid_12 alpha">

View File

@@ -2065,10 +2065,6 @@ def multi_compare_view(request):
if result: if result:
promember=1 promember=1
if 'ids' in request.session:
print request.session['ids']
print request.POST
if request.method == 'POST' and 'workouts' in request.POST: if request.method == 'POST' and 'workouts' in request.POST:
form = WorkoutMultipleCompareForm(request.POST) form = WorkoutMultipleCompareForm(request.POST)