force curve with lines
This commit is contained in:
@@ -17,6 +17,7 @@ from math import pi
|
||||
from django.utils import timezone
|
||||
|
||||
from bokeh.palettes import Dark2_8 as palette
|
||||
from bokeh.models.glyphs import MultiLine
|
||||
import itertools
|
||||
from bokeh.plotting import figure, ColumnDataSource, Figure,curdoc
|
||||
from bokeh.models import CustomJS,Slider, TextInput,BoxAnnotation
|
||||
@@ -374,7 +375,7 @@ def interactive_activitychart(workouts,startdate,enddate,stack='type'):
|
||||
script,div = components(p)
|
||||
return script,div
|
||||
|
||||
def interactive_forcecurve(theworkouts,workstrokesonly=False):
|
||||
def interactive_forcecurve(theworkouts,workstrokesonly=True,plottype='scatter'):
|
||||
TOOLS = 'save,pan,box_zoom,wheel_zoom,reset,tap,hover,crosshair'
|
||||
|
||||
ids = [int(w.id) for w in theworkouts]
|
||||
@@ -642,12 +643,20 @@ def interactive_forcecurve(theworkouts,workstrokesonly=False):
|
||||
rowdata
|
||||
)
|
||||
|
||||
sourcepoints = ColumnDataSource(
|
||||
data = dict(
|
||||
peakforceangle = rowdata['peakforceangle'],
|
||||
peakforce = rowdata['peakforce']
|
||||
if plottype == 'scatter':
|
||||
sourcepoints = ColumnDataSource(
|
||||
data = dict(
|
||||
peakforceangle = rowdata['peakforceangle'],
|
||||
peakforce = rowdata['peakforce']
|
||||
)
|
||||
)
|
||||
else:
|
||||
sourcepoints = ColumnDataSource(
|
||||
data = dict(
|
||||
peakforceangle = [],
|
||||
peakforce = []
|
||||
))
|
||||
|
||||
|
||||
sourcerange = ColumnDataSource(
|
||||
data = dict(
|
||||
@@ -697,6 +706,50 @@ def interactive_forcecurve(theworkouts,workstrokesonly=False):
|
||||
plot.circle('xslip','yslip',source=sourceslipwash,color="red")
|
||||
|
||||
plot.circle('peakforceangle','peakforce',source=sourcepoints,color='black',alpha=0.1)
|
||||
|
||||
if plottype == 'line':
|
||||
multilinedatax = []
|
||||
multilinedatay = []
|
||||
for i in range(len(rowdata)):
|
||||
x = [
|
||||
rowdata['catch'].values[i],
|
||||
rowdata['slip'].values[i]+rowdata['catch'].values[i],
|
||||
rowdata['peakforceangle'].values[i],
|
||||
rowdata['finish'].values[i]-rowdata['wash'].values[i],
|
||||
rowdata['finish'].values[i]
|
||||
]
|
||||
|
||||
|
||||
y = [
|
||||
0,
|
||||
thresholdforce,
|
||||
rowdata['peakforce'].values[i],
|
||||
thresholdforce,
|
||||
0]
|
||||
|
||||
multilinedatax.append(x)
|
||||
multilinedatay.append(y)
|
||||
|
||||
sourcemultiline = ColumnDataSource(dict(
|
||||
x=multilinedatax,
|
||||
y=multilinedatay,
|
||||
))
|
||||
|
||||
sourcemultiline2 = ColumnDataSource(dict(
|
||||
x=multilinedatax,
|
||||
y=multilinedatay,
|
||||
))
|
||||
|
||||
glyph = MultiLine(xs='x',ys='y',line_color='black',line_alpha=0.05)
|
||||
plot.add_glyph(sourcemultiline,glyph)
|
||||
else:
|
||||
sourcemultiline = ColumnDataSource(dict(
|
||||
x=[],y=[]))
|
||||
|
||||
sourcemultiline2 = ColumnDataSource(dict(
|
||||
x=[],y=[]))
|
||||
|
||||
|
||||
plot.line('x','y',source=source,color="red")
|
||||
|
||||
plot.add_layout(avf)
|
||||
@@ -801,11 +854,20 @@ def interactive_forcecurve(theworkouts,workstrokesonly=False):
|
||||
peakforceanglelabel=peakforceanglelabel,
|
||||
annolabel=annolabel,
|
||||
sliderlabel=sliderlabel,
|
||||
plottype=plottype,
|
||||
sourcemultiline=sourcemultiline,
|
||||
sourcemultiline2=sourcemultiline2
|
||||
), code="""
|
||||
var data = source.data
|
||||
var data2 = source2.data
|
||||
var dataslipwash = sourceslipwash.data
|
||||
var datapoints = sourcepoints.data
|
||||
var multilines = sourcemultiline.data
|
||||
var multilines2 = sourcemultiline2.data
|
||||
var plottype = plottype
|
||||
|
||||
var multilinesx = multilines['xs']
|
||||
var multilinesy = multilines['ys']
|
||||
|
||||
var x = data['x']
|
||||
var y = data['y']
|
||||
@@ -826,6 +888,9 @@ def interactive_forcecurve(theworkouts,workstrokesonly=False):
|
||||
var peakforce = data2['peakforce']
|
||||
var averageforce = data2['averageforce']
|
||||
|
||||
var peakforcepoints = datapoints['peakforce']
|
||||
var peakforceanglepoints = datapoints['peakforceangle']
|
||||
|
||||
var annotation = annotation.value
|
||||
var minspm = minspm.value
|
||||
var maxspm = maxspm.value
|
||||
@@ -849,13 +914,21 @@ def interactive_forcecurve(theworkouts,workstrokesonly=False):
|
||||
|
||||
datapoints['peakforceangle'] = []
|
||||
datapoints['peakforce'] = []
|
||||
multilines['xs'] = []
|
||||
multilines['ys'] = []
|
||||
|
||||
for (i=0; i<c.length; i++) {
|
||||
if (spm1[i]>=minspm && spm1[i]<=maxspm) {
|
||||
if (distance1[i]>=mindist && distance1[i]<=maxdist) {
|
||||
if (driveenergy1[i]>=minwork && driveenergy1[i]<=maxwork) {
|
||||
datapoints['peakforceangle'].push(peakforceangle[i])
|
||||
datapoints['peakforce'].push(peakforce[i])
|
||||
if (plottype=='scatter') {
|
||||
datapoints['peakforceangle'].push(peakforceangle[i])
|
||||
datapoints['peakforce'].push(peakforce[i])
|
||||
}
|
||||
if (plottype=='line') {
|
||||
multilines['xs'].push(multilinesx[i])
|
||||
multilines['ys'].push(multilinesy[i])
|
||||
}
|
||||
catchav += c[i]
|
||||
finishav += finish[i]
|
||||
slipav += slip[i]
|
||||
@@ -897,6 +970,7 @@ def interactive_forcecurve(theworkouts,workstrokesonly=False):
|
||||
source.change.emit();
|
||||
sourceslipwash.change.emit()
|
||||
sourcepoints.change.emit();
|
||||
sourcemultiline.change.emit();
|
||||
""")
|
||||
|
||||
annotation = TextInput(title="Type your plot notes here", value="",
|
||||
|
||||
Reference in New Issue
Block a user