[ui/plot] rewriting continous plot, plotting chucks of the buffer

This commit is contained in:
wendtalexander 2024-10-10 09:58:54 +02:00
parent b6bd9e23a0
commit 523f5dc346

View File

@ -19,76 +19,48 @@ class Continously:
self.figure.setBackground("w")
self.daq_plot = self.figure.addPlot(row=0, col=0)
pen = pg.mkPen("red")
# self.time = np.zeros(self.buffer.size)
# self.data = np.zeros(self.buffer.size)
self.time = np.zeros(self.buffer.size)
self.data = np.zeros(self.buffer.size)
self.line = self.daq_plot.plot(
# self.time,
[0],
self.time,
self.data,
pen=pen,
setCliptoView=True,
symbol="o",
# symbol="o",
)
# self.item = 0
# while self.buffer.totalcount() < 3_000_000:
# log.debug(self.buffer.totalcount())
# self.time = np.roll(self.time, -1)
# self.data = np.roll(self.data, -1)
# try:
# item, time_index = self.buffer.get(self.item)
# except IndexError:
# item = 0
# time_index = 0
# self.time[-1] = time_index
# self.data[-1] = item
# self.line.setData(self.time, self.data)
# self.item += 1
self.plot_index = 0
self.CHUNK_PLOT = 1000
# self.plot_index = 0
self.CHUNK_PLOT = 1_000
self.timer = QTimer()
self.timer.setInterval(200)
self.timer.timeout.connect(self.update_plot)
self.timer.start()
# self.update_plot()
def update_plot(self):
log.debug(self.buffer.totalcount())
if self.buffer.totalcount() > self.CHUNK_PLOT:
log.debug(self.buffer.totalcount())
try:
# item, time_index = self.buffer.get(self.buffer.write_index() - 1)
items = self.buffer.read(
self.buffer.write_index() - self.CHUNK_PLOT, count=self.CHUNK_PLOT
times, items = self.buffer.read(
self.buffer.write_index() - self.CHUNK_PLOT, extend=self.CHUNK_PLOT
)
# times = (np.arange(len(items)) / self.buffer.samplerate) + self.time[-1]
except IndexError:
item = 0
except IndexError as e:
items = np.zeros(self.CHUNK_PLOT)
times = np.zeros(self.CHUNK_PLOT)
# log.debug("Stopping the timer")
# self.timer.stop()
time_index = 0
log.debug("No Data Available")
log.debug(f"Index Error {e}")
# self.time = np.roll(self.time, -len(items))
# self.data = np.roll(self.data, -len(items))
#
# # self.time[-len(times) :] = times
# self.time[-len(times) :] = times
# self.data[-len(items) :] = items
self.line.setData(
# self.time,
times,
items,
)
self.plot_index += len(items)
# self.plot_index += len(items)
else:
# self.timer.stop()
# embed()
# exit()
pass
def stop_plotting(self):