Hi everyone.
I have a graph I built using Bokeh that updates the graph (which contains multiple linegraphs) every time a notify message is sent from one of the Observable classes. The data point set (which includes a Key (which is the name of the line graph to update a timestamp and a value) is plot every time notify is called. for the first 2 hours the plot points are added seamlessly and the graph updates very quickly. But after that point the updates are trailing the notify message by a couple hours. (i.e. when i’m streaming time (14:50:18.518, val 89.000) its only graphing 10:51:18.532, val 76 - this is after 8 hours of streaming data in). I need a days worth of data to be shown which is why my stream buffer is 345600. The weird thing that confuses me is that the plot continue to update data from a couple hours ago, even though its a couple hours behind the real time inputs… my guess is that there is a data buffer that is pushing the values onto the graph.
Is there anything I am doing wrong? is there anyway to speed up the process? workarounds? Would down sampling possibly help? Thanks for your help!
Here is my code.
class LiveGrapher: #Observer
def __init__(self, observable):
self.datasetsDisplayed = observable.registerObserver(self)
self.source = {}
self.colors = ['red', 'green', 'blue', 'black', 'purple', 'brown','AliceBlue', 'AniqueWhite', 'Aqua', 'Aquamarine', 'Azure', 'Beige', 'Bisque']
for item in self.datasetsDisplayed:
self.source[item] = ColumnDataSource(data=dict(x=[], y=[], dateStampStr = [], timeStampStr = [], key = []))
self.doc = curdoc()
def notify(self, observable, *args, **kwargs):
timeStamp = ''
YKey = ''
YVal = 0
timeStamp = kwargs['timeStamp']
for key in kwargs.keys():
if key in self.datasetsDisplayed:
YKey = key
YVal = kwargs[YKey]
self.doc.add_next_tick_callback(partial(self.update, x=timeStamp, y=YVal, key =YKey))
def update(self, x, y, key):
self.source[key].stream(dict(x=[x], y=[y], key = [key], dateStampStr=[x.strftime('%m/%d/%Y')], timeStampStr=[x.strftime('%H:%M:%S')]), 345600)
def draw(self):
drawTools = [BoxZoomTool(), ResetTool(), HoverTool( tooltips=[('key', '@key'), ('date', '@dateStampStr'), ('time', '@timeStampStr'), ('value' , '@y')])]
p = figure(x_axis_type="datetime", y_range=[0,2000], tools=drawTools, plot_width=1000)
colorID = 0
for dataset in self.datasetsDisplayed:
p.line(x='x', y='y', legend = dataset, source=self.source[dataset], line_color=self.colors[colorID])
#p.square(x='x', y='y', legend= dataset, source=self.source[dataset], fill_color=None, line_color=self.colors[colorID])
colorID = colorID + 1
p.legend.location = "top_right"
p.legend.background_fill_color = "grey"
p.legend.background_fill_alpha = 0.5
self.doc.add_root(p)