Verze po zapracovani prvni vlny pozadavku
This commit is contained in:
78
src/moving_average_dialog.py
Normal file
78
src/moving_average_dialog.py
Normal file
@@ -0,0 +1,78 @@
|
||||
import logging
|
||||
|
||||
from PyQt6.QtCore import Qt
|
||||
from PyQt6.QtGui import QIntValidator
|
||||
from PyQt6.QtWidgets import QDialog, QVBoxLayout, QLabel, QPushButton, QLineEdit, QHBoxLayout
|
||||
|
||||
from detektor_data import DetektorContainer
|
||||
from callbacks import CallbackDispatcher, CallbackType
|
||||
|
||||
|
||||
class MovingAverageDialog(QDialog):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.setWindowTitle("Klouzavý průměr")
|
||||
self.setModal(True) # Set the dialog as modal (blocks main window)
|
||||
self.resize(300, 150)
|
||||
|
||||
# Main layout
|
||||
main_layout = QVBoxLayout()
|
||||
self.setLayout(main_layout)
|
||||
|
||||
input_layout = QHBoxLayout()
|
||||
input_layout.setAlignment(Qt.AlignmentFlag.AlignLeft)
|
||||
|
||||
add_label = QLabel("Nastavit klouzavý průměr na ")
|
||||
input_layout.addWidget(add_label)
|
||||
|
||||
self.add_input = QLineEdit()
|
||||
self.add_input.setValidator(QIntValidator(1,9999))
|
||||
self.add_input.setText('30')
|
||||
self.add_input.setFixedWidth(50)
|
||||
input_layout.addWidget(self.add_input)
|
||||
|
||||
add_label = QLabel("sekund.")
|
||||
input_layout.addWidget(add_label)
|
||||
|
||||
main_layout.addLayout(input_layout)
|
||||
|
||||
# Buttons layout (aligned at the bottom, next to each other)
|
||||
button_layout = QHBoxLayout()
|
||||
|
||||
calibrate_button = QPushButton("Nastavit průměr")
|
||||
calibrate_button.clicked.connect(self.accept) # Close the dialog when the button is clicked
|
||||
button_layout.addWidget(calibrate_button)
|
||||
|
||||
cancel_button = QPushButton("Zrušit")
|
||||
cancel_button.clicked.connect(self.close) # Close the dialog when the button is clicked
|
||||
button_layout.addWidget(cancel_button)
|
||||
|
||||
# Add buttons to the main layout below both columns
|
||||
main_layout.addLayout(button_layout)
|
||||
|
||||
# Show the dialog
|
||||
self.exec()
|
||||
|
||||
def accept(self):
|
||||
DetektorContainer().duplicate()
|
||||
logging.debug(f'Setting moving average to {self.add_input.text()}s')
|
||||
# TODO: this thinks, that the interval of data is 1000ms
|
||||
number_of_samples = DetektorContainer().get().data_count()
|
||||
for c in DetektorContainer().get().channels:
|
||||
new_data = []
|
||||
|
||||
for k, _ in enumerate(c.data):
|
||||
start_index = k
|
||||
end_index = k + int(self.add_input.text())
|
||||
list_for_averaging = c.data[start_index:end_index]
|
||||
new_data.append(
|
||||
sum(list_for_averaging) / len(list_for_averaging)
|
||||
)
|
||||
|
||||
c.data = new_data
|
||||
CallbackDispatcher().call(CallbackType.UPDATE_CHANNEL, c.id, True)
|
||||
|
||||
CallbackDispatcher().call(CallbackType.DATA_TAINTED)
|
||||
super().accept()
|
||||
Reference in New Issue
Block a user