From 4b185700bdd325334535e25927b286d018a2107f Mon Sep 17 00:00:00 2001 From: Sergey Revyakin Date: Mon, 16 Mar 2026 18:43:00 +0700 Subject: [PATCH] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=BA=D0=BE=D0=BF=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B1=D1=83=D1=84=D0=B5=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/data_buffer.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/core/data_buffer.py b/src/core/data_buffer.py index e7fc6aa..c7adb2c 100644 --- a/src/core/data_buffer.py +++ b/src/core/data_buffer.py @@ -42,6 +42,8 @@ class DataBuffer: self.buffer_mads = [0.0] * self.line_size self.buffer_alarms = [0] * self.line_size 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) suffix = f'_{self.freq_tag}' if self.freq_tag else '' @@ -96,6 +98,13 @@ class DataBuffer: except Exception: 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): """ Вычислить медиану и MAD по строкам буфера. @@ -178,15 +187,26 @@ class DataBuffer: if len(packet_timestamps) != self.line_size: 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: updated_column = self.current_column for i in range(self.line_size): - self.buffer[i][self.current_column] = data[i] - self.buffer_timestamps[i][self.current_column] = packet_timestamps[i] + samples = self.episode_history[i][:self.thinning_counter] + 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.medians() if self.check_init(): 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 if self.current_column == 0: if self.thinning_counter == 1: @@ -199,6 +219,7 @@ class DataBuffer: else: self.current_counter += 1 + def check_alarm(self, data): """ Проверка триггера системы по dBFS во времени.