Fix query-mode cursor labels to work with epoch-indexing

epoch_index_backup
Tyler Goodlet 2023-01-05 15:13:02 -05:00
parent 59483dc8e8
commit b5fa00d63d
1 changed files with 16 additions and 14 deletions

View File

@ -198,12 +198,11 @@ class ContentsLabel(pg.LabelItem):
self, self,
name: str, name: str,
index: int, ix: int,
array: np.ndarray, array: np.ndarray,
) -> None: ) -> None:
# this being "html" is the dumbest shit :eyeroll: # this being "html" is the dumbest shit :eyeroll:
first = array[0]['index']
self.setText( self.setText(
"<b>i</b>:{index}<br/>" "<b>i</b>:{index}<br/>"
@ -216,7 +215,7 @@ class ContentsLabel(pg.LabelItem):
"<b>C</b>:{}<br/>" "<b>C</b>:{}<br/>"
"<b>V</b>:{}<br/>" "<b>V</b>:{}<br/>"
"<b>wap</b>:{}".format( "<b>wap</b>:{}".format(
*array[index - first][ *array[ix][
[ [
'time', 'time',
'open', 'open',
@ -228,7 +227,7 @@ class ContentsLabel(pg.LabelItem):
] ]
], ],
name=name, name=name,
index=index, index=ix,
) )
) )
@ -236,14 +235,11 @@ class ContentsLabel(pg.LabelItem):
self, self,
name: str, name: str,
index: int, ix: int,
array: np.ndarray, array: np.ndarray,
) -> None: ) -> None:
data = array[ix][name]
first = array[0]['index']
if index < array[-1]['index'] and index > first:
data = array[index - first][name]
self.setText(f"{name}: {data:.2f}") self.setText(f"{name}: {data:.2f}")
@ -269,17 +265,20 @@ class ContentsLabels:
def update_labels( def update_labels(
self, self,
index: int, x_in: int,
) -> None: ) -> None:
for chart, name, label, update in self._labels: for chart, name, label, update in self._labels:
viz = chart.get_viz(name) viz = chart.get_viz(name)
array = viz.shm.array array = viz.shm.array
index = array[viz.index_field]
start = index[0]
stop = index[-1]
if not ( if not (
index >= 0 x_in >= start
and index < array[-1]['index'] and x_in <= stop
): ):
# out of range # out of range
print('WTF out of range?') print('WTF out of range?')
@ -288,7 +287,10 @@ class ContentsLabels:
# call provided update func with data point # call provided update func with data point
try: try:
label.show() label.show()
update(index, array) ix = np.searchsorted(index, x_in)
if ix > len(array):
breakpoint()
update(ix, array)
except IndexError: except IndexError:
log.exception(f"Failed to update label: {name}") log.exception(f"Failed to update label: {name}")