[ui/continously] updating plot to plot the last chunk
This commit is contained in:
parent
4f7ebbe8c3
commit
038327bfeb
@ -15,6 +15,7 @@ class Continously:
|
|||||||
def __init__(self, figure: pg.GraphicsLayoutWidget, buffer: CircBuffer):
|
def __init__(self, figure: pg.GraphicsLayoutWidget, buffer: CircBuffer):
|
||||||
self.figure = figure
|
self.figure = figure
|
||||||
self.buffer = buffer
|
self.buffer = buffer
|
||||||
|
self.last_plotted_index = 0
|
||||||
|
|
||||||
def plot(self, *args, **kwargs):
|
def plot(self, *args, **kwargs):
|
||||||
self.figure.setBackground("w")
|
self.figure.setBackground("w")
|
||||||
@ -38,7 +39,6 @@ class Continously:
|
|||||||
self.timer = QTimer()
|
self.timer = QTimer()
|
||||||
self.CHUNK_PLOT = int(self.buffer.samplerate / 6)
|
self.CHUNK_PLOT = int(self.buffer.samplerate / 6)
|
||||||
self.PLOT_HISTORY = 500_000 # The amount of data you want to keep on screen
|
self.PLOT_HISTORY = 500_000 # The amount of data you want to keep on screen
|
||||||
self.last_plotted_index = 0
|
|
||||||
self.timer.setInterval(150)
|
self.timer.setInterval(150)
|
||||||
self.timer.timeout.connect(self.update_plot)
|
self.timer.timeout.connect(self.update_plot)
|
||||||
self.timer.start()
|
self.timer.start()
|
||||||
@ -49,11 +49,11 @@ class Continously:
|
|||||||
|
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
if total_count - self.last_plotted_index >= self.CHUNK_PLOT:
|
if total_count - self.last_plotted_index >= self.CHUNK_PLOT:
|
||||||
|
try:
|
||||||
times, items = self.buffer.read(
|
times, items = self.buffer.read(
|
||||||
self.last_plotted_index,
|
self.last_plotted_index,
|
||||||
extend=self.CHUNK_PLOT,
|
extend=self.CHUNK_PLOT,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.time = np.concatenate((self.time, times))[-self.PLOT_HISTORY :]
|
self.time = np.concatenate((self.time, times))[-self.PLOT_HISTORY :]
|
||||||
self.data = np.concatenate((self.data, items))[-self.PLOT_HISTORY :]
|
self.data = np.concatenate((self.data, items))[-self.PLOT_HISTORY :]
|
||||||
self.line.setData(
|
self.line.setData(
|
||||||
@ -61,6 +61,8 @@ class Continously:
|
|||||||
self.data,
|
self.data,
|
||||||
)
|
)
|
||||||
self.last_plotted_index += self.CHUNK_PLOT
|
self.last_plotted_index += self.CHUNK_PLOT
|
||||||
|
except IndexError:
|
||||||
|
log.error("Could not acces the data from the buffer for plotting")
|
||||||
end_time = time.time()
|
end_time = time.time()
|
||||||
log.debug(f"total time for plotting {end_time - start_time}")
|
log.debug(f"total time for plotting {end_time - start_time}")
|
||||||
else:
|
else:
|
||||||
@ -68,6 +70,18 @@ class Continously:
|
|||||||
|
|
||||||
def stop_plotting(self):
|
def stop_plotting(self):
|
||||||
self.timer.stop()
|
self.timer.stop()
|
||||||
|
total_count = self.buffer.totalcount()
|
||||||
|
times, items = self.buffer.read(
|
||||||
|
self.last_plotted_index,
|
||||||
|
extend=total_count - self.last_plotted_index,
|
||||||
|
)
|
||||||
|
self.time = np.concatenate((self.time, times))[-self.PLOT_HISTORY :]
|
||||||
|
self.data = np.concatenate((self.data, items))[-self.PLOT_HISTORY :]
|
||||||
|
self.line.setData(
|
||||||
|
self.time,
|
||||||
|
self.data,
|
||||||
|
)
|
||||||
|
self.last_plotted_index += total_count - self.last_plotted_index
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
self.continous_ax.enableAutoRange()
|
self.continous_ax.enableAutoRange()
|
||||||
|
Loading…
Reference in New Issue
Block a user