@@ -134,6 +134,7 @@ def callback_c(*args, **kwargs):
134
134
html .Div (id = 'button_local_counter' , children = "Press any button to start" ),
135
135
], className = "" )
136
136
137
+ #pylint: disable=too-many-arguments
137
138
@liveIn .expanded_callback (
138
139
dash .dependencies .Output ('button_local_counter' , 'children' ),
139
140
[dash .dependencies .Input ('red-button' , 'n_clicks' ),
@@ -186,10 +187,10 @@ def callback_liveIn_button_press(red_clicks, blue_clicks, green_clicks,
186
187
datetime .fromtimestamp (0.001 * timestamp ))
187
188
188
189
liveOut = DjangoDash ("LiveOutput" ,
189
- )#serve_locally=True)
190
+ )#serve_locally=True)
190
191
191
192
def _get_cache_key (state_uid ):
192
- return "demo-liveout-s4 -%s" % state_uid
193
+ return "demo-liveout-s6 -%s" % state_uid
193
194
194
195
def generate_liveOut_layout ():
195
196
'Generate the layout per-app, generating each tine a new uuid for the state_uid argument'
@@ -210,6 +211,7 @@ def generate_liveOut_layout():
210
211
211
212
liveOut .layout = generate_liveOut_layout
212
213
214
+ #pylint: disable=unused-argument
213
215
#@liveOut.expanded_callback(
214
216
@liveOut .callback (
215
217
dash .dependencies .Output ('internal_state' , 'children' ),
@@ -242,6 +244,18 @@ def callback_liveOut_pipe_in(named_count, state_uid, **kwargs):
242
244
colour_set = [(None , 0 , 100 ) for i in range (5 )]
243
245
244
246
_ , 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
+
245
259
if click_timestamp > last_ts :
246
260
colour_set .append ((user , click_timestamp , prev * random .lognormvariate (0.0 , 0.1 )),)
247
261
colour_set = colour_set [- 100 :]
@@ -268,23 +282,28 @@ def callback_show_timeseries(internal_state_string, state_uid, **kwargs):
268
282
269
283
colour_series = {}
270
284
285
+ colors = {'red' :'#FF0000' ,
286
+ 'blue' :'#0000FF' ,
287
+ 'green' :'#00FF00' ,
288
+ 'yellow' : '#FFFF00' ,
289
+ 'cyan' : '#00FFFF' ,
290
+ 'magenta' : '#FF00FF' ,
291
+ 'black' : '#000000' ,
292
+ }
293
+
271
294
for colour , values in state .items ():
272
295
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]
274
297
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 ()
276
300
277
301
df = pd .DataFrame (colour_series ).fillna (method = "ffill" ).reset_index ()[- 25 :]
278
302
279
- colors = {'red' :'#FF0000' ,
280
- 'blue' :'#0000FF' ,
281
- 'green' :'#00FF00' ,
282
- }
283
-
284
303
traces = [go .Scatter (y = df [colour ],
285
304
x = df ['index' ],
286
305
name = colour ,
287
- line = dict (color = colors [ colour ] ),
306
+ line = dict (color = colors . get ( colour , '#000000' ) ),
288
307
) for colour in colour_series ]
289
308
290
309
return {'data' :traces ,
0 commit comments