--- a/controls/DebugVariablePanel/DebugVariableItem.py Fri Jun 11 11:56:07 2021 +0200
+++ b/controls/DebugVariablePanel/DebugVariableItem.py Mon Jun 14 16:48:39 2021 +0200
@@ -26,8 +26,9 @@
from __future__ import absolute_import
from datetime import timedelta
import binascii
-import numpy
+import numpy as np
from graphics.DebugDataConsumer import DebugDataConsumer, TYPE_TRANSLATOR
+from controls.DebugVariablePanel.RingBuffer import RingBuffer
# -------------------------------------------------------------------------------
# Constant for calculate CRC for string variables
@@ -142,8 +143,8 @@
@return: Data as numpy.array([(tick, value, forced),...])
"""
# Return immediately if data empty or none
- if self.Data is None or len(self.Data) == 0:
- return self.Data
+ if self.Data is None or self.Data.count == 0:
+ return None
# Find nearest data outside given range indexes
start_idx = (self.GetNearestData(start_tick, -1)
@@ -154,7 +155,7 @@
else len(self.Data))
# Return data between indexes
- return self.Data[start_idx:end_idx]
+ return self.Data.view[start_idx:end_idx]
def GetRawValue(self, index):
"""
@@ -195,8 +196,8 @@
if len(values) > 0:
# Return value range for data in given tick range
return (data,
- data[numpy.argmin(values), 1],
- data[numpy.argmax(values), 1])
+ data[np.argmin(values), 1],
+ data[np.argmax(values), 1])
# Return default values
return data, None, None
@@ -207,7 +208,7 @@
"""
if self.StoreData and self.IsNumVariable():
# Init table storing data
- self.Data = numpy.array([]).reshape(0, 3)
+ self.Data = RingBuffer(3)
# Init table storing raw data if variable is strin
self.RawData = ([]
@@ -294,7 +295,7 @@
[float(tick), num_value, extra_value])
# Add New data to stored data table
- self.Data = numpy.append(self.Data, data_values, axis=0)
+ self.Data.append(data_values)
# Signal to debug variable panel to refresh
self.Parent.HasNewData = True
@@ -337,7 +338,7 @@
if tick is not None and self.Data is not None:
# Return current value and forced flag if data empty
- if len(self.Data) == 0:
+ if self.Data.count == 0:
return self.Value, self.IsForced()
# Get index of nearest data from tick given
@@ -345,9 +346,9 @@
# Get value and forced flag at given index
value, forced = \
- self.RawData[int(self.Data[idx, 2])] \
+ self.RawData[int(self.Data.view[idx, 2])] \
if self.VariableType in ["STRING", "WSTRING"] \
- else self.Data[idx, 1:3]
+ else self.Data.view[idx, 1:3]
if self.VariableType in ["TIME", "TOD", "DT", "DATE"]:
value = timedelta(seconds=value)
@@ -380,10 +381,10 @@
return None
# Extract data ticks
- ticks = self.Data[:, 0]
+ ticks = self.Data.view[:, 0]
# Get nearest data from tick
- idx = numpy.argmin(abs(ticks - tick))
+ idx = np.searchsorted(ticks, tick)
# Adjust data index according to constraint
if adjust < 0 and ticks[idx] > tick and idx > 0 or \