@@ -134,6 +134,7 @@ def callback_c(*args, **kwargs):
134134 html .Div (id = 'button_local_counter' , children = "Press any button to start" ),
135135 ], className = "" )
136136
137+ #pylint: disable=too-many-arguments
137138@liveIn .expanded_callback (
138139 dash .dependencies .Output ('button_local_counter' , 'children' ),
139140 [dash .dependencies .Input ('red-button' , 'n_clicks' ),
@@ -186,10 +187,10 @@ def callback_liveIn_button_press(red_clicks, blue_clicks, green_clicks,
186187 datetime .fromtimestamp (0.001 * timestamp ))
187188
188189liveOut = DjangoDash ("LiveOutput" ,
189- )#serve_locally=True)
190+ )#serve_locally=True)
190191
191192def _get_cache_key (state_uid ):
192- return "demo-liveout-s4 -%s" % state_uid
193+ return "demo-liveout-s6 -%s" % state_uid
193194
194195def generate_liveOut_layout ():
195196 'Generate the layout per-app, generating each tine a new uuid for the state_uid argument'
@@ -210,6 +211,7 @@ def generate_liveOut_layout():
210211
211212liveOut .layout = generate_liveOut_layout
212213
214+ #pylint: disable=unused-argument
213215#@liveOut.expanded_callback(
214216@liveOut .callback (
215217 dash .dependencies .Output ('internal_state' , 'children' ),
@@ -242,6 +244,18 @@ def callback_liveOut_pipe_in(named_count, state_uid, **kwargs):
242244 colour_set = [(None , 0 , 100 ) for i in range (5 )]
243245
244246 _ , last_ts , prev = colour_set [- 1 ]
247+
248+ # Loop over all existing timestamps and find the latest one
249+ if not click_timestamp or click_timestamp < 1 :
250+ click_timestamp = 0
251+
252+ for _ , the_colour_set in state .items ():
253+ _ , lts , _ = the_colour_set [- 1 ]
254+ if lts > click_timestamp :
255+ click_timestamp = lts
256+
257+ click_timestamp = click_timestamp + 1000
258+
245259 if click_timestamp > last_ts :
246260 colour_set .append ((user , click_timestamp , prev * random .lognormvariate (0.0 , 0.1 )),)
247261 colour_set = colour_set [- 100 :]
@@ -268,23 +282,28 @@ def callback_show_timeseries(internal_state_string, state_uid, **kwargs):
268282
269283 colour_series = {}
270284
285+ colors = {'red' :'#FF0000' ,
286+ 'blue' :'#0000FF' ,
287+ 'green' :'#00FF00' ,
288+ 'yellow' : '#FFFF00' ,
289+ 'cyan' : '#00FFFF' ,
290+ 'magenta' : '#FF00FF' ,
291+ 'black' : '#000000' ,
292+ }
293+
271294 for colour , values in state .items ():
272295 timestamps = [datetime .fromtimestamp (int (0.001 * ts )) for _ , ts , _ in values if ts > 0 ]
273- users = [user for user , ts , _ in values if ts > 0 ]
296+ # users = [user for user, ts, _ in values if ts > 0]
274297 levels = [level for _ , ts , level in values if ts > 0 ]
275- colour_series [colour ] = pd .Series (levels , index = timestamps ).groupby (level = 0 ).first ()
298+ if colour in colors :
299+ colour_series [colour ] = pd .Series (levels , index = timestamps ).groupby (level = 0 ).first ()
276300
277301 df = pd .DataFrame (colour_series ).fillna (method = "ffill" ).reset_index ()[- 25 :]
278302
279- colors = {'red' :'#FF0000' ,
280- 'blue' :'#0000FF' ,
281- 'green' :'#00FF00' ,
282- }
283-
284303 traces = [go .Scatter (y = df [colour ],
285304 x = df ['index' ],
286305 name = colour ,
287- line = dict (color = colors [ colour ] ),
306+ line = dict (color = colors . get ( colour , '#000000' ) ),
288307 ) for colour in colour_series ]
289308
290309 return {'data' :traces ,
0 commit comments