Make `Viz.incr_info()` do treading with time-index, and appending with array-index

pre_viz_calls
Tyler Goodlet 2022-12-19 15:09:13 -05:00
parent 5e75b46665
commit 6da6881ec4
1 changed files with 45 additions and 42 deletions

View File

@ -959,21 +959,26 @@ class Viz(msgspec.Struct): # , frozen=True):
def incr_info( def incr_info(
self, self,
ds: DisplayState,
# NOTE: pass in a copy if you don't want your orignal mutated.
state: DisplayState,
update_state: bool = True,
update_uppx: float = 16, update_uppx: float = 16,
is_1m: bool = False, is_1m: bool = False,
) -> tuple: ) -> tuple:
_, _, _, r = self.bars_range() # most recent right datum index in-view _, _, _, r = self.bars_range() # most recent right datum index in-view
i_step = self.shm.array[-1][self.index_field] # last source index. lasts = self.shm.array[-1]
i_step = lasts['index'] # last index-specific step.
i_step_t = lasts['time'] # last time step.
fqsn = self.flume.symbol.fqsn
if is_1m:
print(f'{fqsn} 1Min index: {i_step}, t: {i_step_t}')
# check if "last (is) in view" -> is a real-time update necessary? # check if "last (is) in view" -> is a real-time update necessary?
liv = r >= i_step if self.index_field == 'index':
liv = (r >= i_step)
else:
liv = (r >= i_step_t)
# compute the first available graphic obj's x-units-per-pixel # compute the first available graphic obj's x-units-per-pixel
# TODO: make this not loop through all vizs each time! # TODO: make this not loop through all vizs each time!
@ -985,25 +990,25 @@ class Viz(msgspec.Struct): # , frozen=True):
# this simple index-diff and all the fsp sub-curve graphics # this simple index-diff and all the fsp sub-curve graphics
# are diffed on each draw cycle anyway; so updates to the # are diffed on each draw cycle anyway; so updates to the
# "curve" length is already automatic. # "curve" length is already automatic.
last_key = 'i_last_slow' if is_1m else 'i_last' globalz = ds.globalz
globalz = state.globalz varz = ds.hist_vars if is_1m else ds.vars
varz = state.hist_vars if is_1m else state.vars
last_key = 'i_last_slow_t' if is_1m else 'i_last_t'
glast = globalz[last_key] glast = globalz[last_key]
# when the current step is now greater then the last we # calc datums diff since last global increment
# have read from the display state globals, we presume that the i_diff_t: float = i_step_t - glast
# underlying source shm buffer has added a new sample and thus
# we should increment the global view a step iff the last datum
# is in view.
should_global_increment: bool = False
if i_step > glast:
globalz[last_key] = i_step
should_global_increment = True
# update global state for this chart # when the current step is now greater then the last we have
i_diff: float = i_step - glast # read from the display state globals, we presume that the
if i_diff > 0: # underlying source shm buffer has added a new sample and thus
varz['i_last'] = i_step # we should increment the global view a step (i.e. tread the
# view in place to keep the current datum at the same spot on
# screen).
should_tread: bool = False
if i_diff_t > 0:
globalz[last_key] = i_step_t
should_tread = True
# update the "last datum" (aka extending the vizs graphic with # update the "last datum" (aka extending the vizs graphic with
# new data) only if the number of unit steps is >= the number of # new data) only if the number of unit steps is >= the number of
@ -1012,43 +1017,41 @@ class Viz(msgspec.Struct): # , frozen=True):
# to a new pixel, we don't update yet. # to a new pixel, we don't update yet.
i_last_append = varz['i_last_append'] i_last_append = varz['i_last_append']
append_diff = i_step - i_last_append append_diff = i_step - i_last_append
do_append = (
append_diff >= uppx
and i_diff
)
do_rt_update = uppx < update_uppx do_px_step = append_diff >= uppx
do_rt_update = (uppx < update_uppx)
if ( if (
do_append do_px_step
and not is_1m
): ):
varz['i_last_append'] = i_step varz['i_last_append'] = i_step
# fqsn = self.flume.symbol.fqsn
# print( # print(
# f'DOING APPEND => {fqsn}\n' # f'DOING APPEND => {fqsn}\n'
# f'i_step: {i_step}\n' # f'i_step: {i_step}\n'
# f'i_step_t: {i_step_t}\n'
# f'glast: {glast}\n' # f'glast: {glast}\n'
# f'last_append: {i_last_append}\n' # f'last_append: {i_last_append}\n'
# f'r: {r}\n' # f'r: {r}\n'
# '-----------------------------\n'
# f'uppx: {uppx}\n' # f'uppx: {uppx}\n'
# f'liv: {liv}\n' # f'liv: {liv}\n'
# f'do_append:{do_append}\n' # f'do_px_step: {do_px_step}\n'
# f'i_diff:{i_diff}\n' # f'i_diff_t: {i_diff_t}\n'
# f'do_rt_update: {do_rt_update}\n' # f'do_rt_update: {do_rt_update}\n'
# f'append_diff: {append_diff}\n' # f'append_diff: {append_diff}\n'
# f'should_global_increment: {should_global_increment}\n' # f'should_tread: {should_tread}\n'
# ) # )
varz['i_last'] = i_step
# TODO: pack this into a struct? # TODO: pack this into a struct?
return ( return (
uppx, uppx,
liv, liv,
do_append, do_px_step,
i_diff, i_diff_t,
append_diff, append_diff,
do_rt_update, do_rt_update,
should_global_increment, should_tread,
) )