|
|
|
@ -42,6 +42,8 @@ class DataBuffer:
|
|
|
|
self.buffer_mads = [0.0] * self.line_size
|
|
|
|
self.buffer_mads = [0.0] * self.line_size
|
|
|
|
self.buffer_alarms = [0] * self.line_size
|
|
|
|
self.buffer_alarms = [0] * self.line_size
|
|
|
|
self.last_alarm_channels = []
|
|
|
|
self.last_alarm_channels = []
|
|
|
|
|
|
|
|
self.episode_history = [[0.0 for _ in range(self.num_of_thinning_iter)] for _ in range(self.line_size)]
|
|
|
|
|
|
|
|
self.episode_history_timestamps = [[None for _ in range(self.num_of_thinning_iter)] for _ in range(self.line_size)]
|
|
|
|
|
|
|
|
|
|
|
|
self.freq_tag = '' if freq_tag is None else str(freq_tag)
|
|
|
|
self.freq_tag = '' if freq_tag is None else str(freq_tag)
|
|
|
|
suffix = f'_{self.freq_tag}' if self.freq_tag else ''
|
|
|
|
suffix = f'_{self.freq_tag}' if self.freq_tag else ''
|
|
|
|
@ -96,6 +98,13 @@ class DataBuffer:
|
|
|
|
except Exception:
|
|
|
|
except Exception:
|
|
|
|
return str(timestamp)
|
|
|
|
return str(timestamp)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
|
|
|
def _mean_timestamp(timestamps):
|
|
|
|
|
|
|
|
filtered = [float(ts) for ts in timestamps if ts is not None]
|
|
|
|
|
|
|
|
if not filtered:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
return sum(filtered) / len(filtered)
|
|
|
|
|
|
|
|
|
|
|
|
def medians(self):
|
|
|
|
def medians(self):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Вычислить медиану и MAD по строкам буфера.
|
|
|
|
Вычислить медиану и MAD по строкам буфера.
|
|
|
|
@ -178,15 +187,26 @@ class DataBuffer:
|
|
|
|
if len(packet_timestamps) != self.line_size:
|
|
|
|
if len(packet_timestamps) != self.line_size:
|
|
|
|
raise ValueError('packet_timestamps length must match number of channels')
|
|
|
|
raise ValueError('packet_timestamps length must match number of channels')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sample_idx = self.current_counter - 1
|
|
|
|
|
|
|
|
for i in range(self.line_size):
|
|
|
|
|
|
|
|
self.episode_history[i][sample_idx] = float(data[i])
|
|
|
|
|
|
|
|
self.episode_history_timestamps[i][sample_idx] = packet_timestamps[i]
|
|
|
|
|
|
|
|
|
|
|
|
if self.current_counter == self.thinning_counter:
|
|
|
|
if self.current_counter == self.thinning_counter:
|
|
|
|
updated_column = self.current_column
|
|
|
|
updated_column = self.current_column
|
|
|
|
for i in range(self.line_size):
|
|
|
|
for i in range(self.line_size):
|
|
|
|
self.buffer[i][self.current_column] = data[i]
|
|
|
|
samples = self.episode_history[i][:self.thinning_counter]
|
|
|
|
self.buffer_timestamps[i][self.current_column] = packet_timestamps[i]
|
|
|
|
timestamps = self.episode_history_timestamps[i][:self.thinning_counter]
|
|
|
|
|
|
|
|
self.buffer[i][self.current_column] = float(sum(samples) / len(samples))
|
|
|
|
|
|
|
|
self.buffer_timestamps[i][self.current_column] = self._mean_timestamp(timestamps)
|
|
|
|
self.current_column = (self.current_column + 1) % self.columns_size
|
|
|
|
self.current_column = (self.current_column + 1) % self.columns_size
|
|
|
|
self.medians()
|
|
|
|
self.medians()
|
|
|
|
if self.check_init():
|
|
|
|
if self.check_init():
|
|
|
|
self.log_threshold_update(updated_column)
|
|
|
|
self.log_threshold_update(updated_column)
|
|
|
|
|
|
|
|
for i in range(self.line_size):
|
|
|
|
|
|
|
|
for j in range(self.thinning_counter):
|
|
|
|
|
|
|
|
self.episode_history[i][j] = 0.0
|
|
|
|
|
|
|
|
self.episode_history_timestamps[i][j] = None
|
|
|
|
self.current_counter = 1
|
|
|
|
self.current_counter = 1
|
|
|
|
if self.current_column == 0:
|
|
|
|
if self.current_column == 0:
|
|
|
|
if self.thinning_counter == 1:
|
|
|
|
if self.thinning_counter == 1:
|
|
|
|
@ -199,6 +219,7 @@ class DataBuffer:
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.current_counter += 1
|
|
|
|
self.current_counter += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_alarm(self, data):
|
|
|
|
def check_alarm(self, data):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Проверка триггера системы по dBFS во времени.
|
|
|
|
Проверка триггера системы по dBFS во времени.
|
|
|
|
|