334 lines
11 KiB
Python
334 lines
11 KiB
Python
import sys
|
|
from lector import *
|
|
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QHBoxLayout, QVBoxLayout, QGridLayout
|
|
from PyQt5.QtWidgets import QLabel, QLineEdit, QPushButton
|
|
from PyQt5.QtCore import QTimer, Qt
|
|
from PyQt5.QtGui import QFont
|
|
from clase_ploteador import *
|
|
|
|
class MainWindow(QMainWindow):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.setWindowTitle("Analizador")
|
|
self.setGeometry(0, 0, 1000, 800)
|
|
self.center_window()
|
|
|
|
central_widget = QWidget()
|
|
self.setCentralWidget(central_widget)
|
|
font = QFont('Arial',14)
|
|
|
|
central_widget.setFont(font)
|
|
|
|
layout = QHBoxLayout()
|
|
layout_parametros = QVBoxLayout()
|
|
layout_graficas = QGridLayout()
|
|
|
|
self.fs = 1000
|
|
self.buff = 100
|
|
self.act = 500
|
|
self.mult_V1 = 1
|
|
self.mult_I1 = 1
|
|
self.mult_V2 = 1
|
|
self.mult_I2 = 1
|
|
self.selec_fft = 'V1'
|
|
|
|
layout_parametros = self.modulo_botones(layout_parametros)
|
|
layout_graficas = self.modulo_graficas(layout_graficas)
|
|
|
|
layout.addLayout(layout_graficas)
|
|
layout.addLayout(layout_parametros)
|
|
|
|
layout.setStretchFactor(layout_graficas, 6)
|
|
layout.setStretchFactor(layout_parametros, 1)
|
|
|
|
central_widget.setLayout(layout)
|
|
|
|
|
|
|
|
def center_window(self):
|
|
screen = QApplication.primaryScreen()
|
|
|
|
frame_geom = self.frameGeometry()
|
|
|
|
screen_center = screen.availableGeometry().center()
|
|
|
|
frame_geom.moveCenter(screen_center)
|
|
self.move(frame_geom.topLeft())
|
|
|
|
|
|
|
|
def modulo_botones(self, layout):
|
|
self.label_fs = QLabel("Fecuencia Medida: 1 kHz")
|
|
self.label_buff= QLabel("Tamaño de Paquete Datos: 100")
|
|
self.label_act= QLabel("Frecuencia Actualizacion Graficos: 2 fps")
|
|
self.label_V1= QLabel("Multiplicador Tension 1º: 1")
|
|
self.label_I1= QLabel("Multiplicador Corriente 1º: 1")
|
|
self.label_V2= QLabel("Multiplicador Tension 2º: 1")
|
|
self.label_I2= QLabel("Multiplicador Corriente 2º: 1")
|
|
|
|
self.input_fs = QLineEdit()
|
|
self.input_fs.setPlaceholderText('Frecuencia de medida')
|
|
|
|
self.input_buff = QLineEdit()
|
|
self.input_buff.setPlaceholderText('Tamaño del Paquete')
|
|
|
|
self.input_act = QLineEdit()
|
|
self.input_act.setPlaceholderText('Frecuencia de Actualizacion')
|
|
|
|
self.input_V1 = QLineEdit()
|
|
self.input_V1.setPlaceholderText('Multiplicador Tension 1º')
|
|
|
|
self.input_I1 = QLineEdit()
|
|
self.input_I1.setPlaceholderText('Multiplicador Corriente 1º')
|
|
|
|
self.input_V2 = QLineEdit()
|
|
self.input_V2.setPlaceholderText('Multiplicador Tension 2º')
|
|
|
|
self.input_I2 = QLineEdit()
|
|
self.input_I2.setPlaceholderText('Multiplicador Corriente 2º')
|
|
|
|
self.update_button = QPushButton('Actualizar Medidas')
|
|
self.update_button.clicked.connect(self.actualizar_metodo_medida)
|
|
|
|
self.update_button = QPushButton('Actualizar Medidas')
|
|
self.update_button.clicked.connect(self.actualizar_metodo_medida)
|
|
|
|
layout.addWidget(self.label_fs)
|
|
layout.addWidget(self.input_fs)
|
|
layout.addWidget(self.label_buff)
|
|
layout.addWidget(self.input_buff)
|
|
layout.addWidget(self.label_act)
|
|
layout.addWidget(self.input_act)
|
|
layout.addWidget(self.label_V1)
|
|
layout.addWidget(self.input_V1)
|
|
layout.addWidget(self.label_I1)
|
|
layout.addWidget(self.input_I1)
|
|
layout.addWidget(self.label_V2)
|
|
layout.addWidget(self.input_V2)
|
|
layout.addWidget(self.label_I2)
|
|
layout.addWidget(self.input_I2)
|
|
layout.addWidget(self.update_button)
|
|
|
|
layout.setAlignment(Qt.AlignRight)
|
|
|
|
return layout
|
|
|
|
|
|
|
|
def actualizar_metodo_medida(self):
|
|
|
|
if self.input_fs.text():
|
|
temp = self.input_fs.text()
|
|
|
|
try:
|
|
self.fs = float(temp) * 1000 #Guardo el Valor
|
|
self.label_fs.setText(f"Fecuencia Medida: {temp} kHz")
|
|
|
|
except: self.label_fs.setText(f"Fecuencia Medida: ¡No valido!")
|
|
|
|
if self.input_buff.text():
|
|
temp = self.input_buff.text()
|
|
|
|
try:
|
|
self.buff = int(temp) # guardo el valor
|
|
self.label_buff.setText(f"Tamaño de Paquete Datos: {temp}")
|
|
|
|
except: self.label_buff.setText(f"Tamaño de Paquete Datos: ¡No valido!")
|
|
|
|
if self.input_act.text():
|
|
temp = self.input_act.text()
|
|
self.act = 1000/float(temp)
|
|
|
|
try:
|
|
if self.act >= self.buff/self.fs:
|
|
self.act = temp # guardo el valor
|
|
self.label_act.setText(f"Frecuencia Actualizacion Graficos: {temp} fps")
|
|
|
|
else: self.label_act.setText(f"Frecuencia Actualizacion Graficos: ¡No valido!")
|
|
|
|
except: self.label_act.setText(f"Frecuencia Actualizacion Graficos: ¡No valido!")
|
|
|
|
if self.input_V1.text():
|
|
temp = self.input_V1.text()
|
|
|
|
try:
|
|
self.mult_V1 = float(temp) # guardo el valor
|
|
self.label_V1.setText(f"Multiplicador Tension 1º: {temp}")
|
|
|
|
except: self.label_V1.setText("Multiplicador Tension 1º: ¡No valido!")
|
|
|
|
if self.input_I1.text():
|
|
temp = self.input_I1.text()
|
|
|
|
try:
|
|
self.mult_I1 = float(temp) # guardo el valor
|
|
self.label_I1.setText(f"Multiplicador Corriente 1º: {temp}")
|
|
|
|
except: self.label_I1.setText("Multiplicador Corriente 1º: ¡No valido!")
|
|
|
|
if self.input_V2.text():
|
|
temp = self.input_V2.text()
|
|
|
|
try:
|
|
self.mult_V2 = float(temp) # guardo el valor
|
|
self.label_V2.setText(f"Multiplicador Tension 2º: {temp}")
|
|
|
|
except: self.label_V2.setText("Multiplicador Tension 2º: ¡No valido!")
|
|
|
|
if self.input_I2.text():
|
|
temp = self.input_I2.text()
|
|
|
|
try:
|
|
self.mult_I2 = float(temp) # guardo el valor
|
|
self.label_I2.setText(f"Multiplicador Corriente 2º: {temp}")
|
|
|
|
except: self.label_I2.setText("Multiplicador Corriente 2º: ¡No valido!")
|
|
|
|
self.input_fs.clear()
|
|
self.input_buff.clear()
|
|
self.input_act.clear()
|
|
self.input_V1.clear()
|
|
self.input_I1.clear()
|
|
self.input_V2.clear()
|
|
self.input_I2.clear()
|
|
|
|
def modulo_seleccionador_fft(self, layout):
|
|
self.boton_fft_V1 = QPushButton("Tension 1")
|
|
self.boton_fft_I1 = QPushButton("Corriente 1")
|
|
self.boton_fft_V2 = QPushButton("Tension 2")
|
|
self.boton_fft_I2 = QPushButton("Corriente 2")
|
|
|
|
self.boton_fft_V1.clicked.connect(lambda:self.seleccion_fft('V1'))
|
|
self.boton_fft_I1.clicked.connect(lambda:self.seleccion_fft('I1'))
|
|
self.boton_fft_V2.clicked.connect(lambda:self.seleccion_fft('V2'))
|
|
self.boton_fft_I2.clicked.connect(lambda:self.seleccion_fft('I2'))
|
|
|
|
layout.addWidget(self.boton_fft_V1)
|
|
layout.addWidget(self.boton_fft_I1)
|
|
layout.addWidget(self.boton_fft_V2)
|
|
layout.addWidget(self.boton_fft_I2)
|
|
|
|
return layout
|
|
|
|
|
|
|
|
def seleccion_fft(self, seleccion):
|
|
self.selec_fft = seleccion
|
|
|
|
|
|
|
|
def modulo_graficas(self, layout):
|
|
datos = generar_paquete_ejemplo(self.fs, self.buff)
|
|
|
|
tiempo = np.arange(0, self.buff/self.fs, 1/self.fs)
|
|
|
|
# Crear Layout Primero
|
|
layout_primario_main = QVBoxLayout()
|
|
layout_analisis_1 = QHBoxLayout()
|
|
|
|
V, I, FP, tipo = analizar_ondas(datos['V1'], datos['I1'])
|
|
|
|
self.label_V1rms = QLabel(f'V_rms = {V}V')
|
|
self.label_I1rms = QLabel(f'I_rms = {I}A')
|
|
self.label_FP1 = QLabel(f'PF = {FP} {tipo}')
|
|
|
|
layout_analisis_1.addWidget(self.label_V1rms)
|
|
layout_analisis_1.addWidget(self.label_I1rms)
|
|
layout_analisis_1.addWidget(self.label_FP1)
|
|
|
|
self.primario = Ploteador_VI(t=tiempo, V = datos['V1'], I = datos['I1'], Titulo = 'VI Primario')
|
|
|
|
layout_primario_main.addWidget(self.primario)
|
|
layout_primario_main.addLayout(layout_analisis_1)
|
|
|
|
layout_primario_main.setStretchFactor(self.primario, 8)
|
|
layout_primario_main.setStretchFactor(layout_analisis_1, 1)
|
|
|
|
|
|
# Crear Layout Secundario
|
|
layout_secundario_main = QVBoxLayout()
|
|
layout_analisis_2 = QHBoxLayout()
|
|
|
|
V, I, FP, tipo = analizar_ondas(datos['V2'], datos['I2'])
|
|
|
|
self.label_V2rms = QLabel(f'V_rms = {V}V')
|
|
self.label_I2rms = QLabel(f'I_rms = {I}A')
|
|
self.label_FP2 = QLabel(f'PF = {FP} {tipo}')
|
|
|
|
layout_analisis_2.addWidget(self.label_V2rms)
|
|
layout_analisis_2.addWidget(self.label_I2rms)
|
|
layout_analisis_2.addWidget(self.label_FP2)
|
|
|
|
self.secundario = Ploteador_VI(t=tiempo, V = datos['V2'], I = datos['I2'], Titulo= 'VI Secundario')
|
|
|
|
layout_secundario_main.addWidget(self.secundario)
|
|
layout_secundario_main.addLayout(layout_analisis_2)
|
|
|
|
layout_secundario_main.setStretchFactor(self.secundario, 8)
|
|
layout_secundario_main.setStretchFactor(layout_analisis_2, 1)
|
|
|
|
# Crear Layout del Termico
|
|
self.termico = Ploteador_Termico(t=tiempo, Temperatura1=datos['T1'], Temperatura2=datos['T2'])
|
|
|
|
# crear layout de la fft
|
|
layout_fft_main = QVBoxLayout()
|
|
layout_fft_selector = QHBoxLayout()
|
|
|
|
layout_fft_selector = self.modulo_seleccionador_fft(layout_fft_selector)
|
|
|
|
self.fourier = Ploteador_fft(t=tiempo, onda = datos[self.selec_fft], fs = self.fs, param= self.selec_fft)
|
|
|
|
layout_fft_main.addWidget(self.fourier)
|
|
layout_fft_main.addLayout(layout_fft_selector)
|
|
|
|
# Agregar los widgets de gráficos al layout de la cuadrícula
|
|
layout.addLayout(layout_primario_main, 0, 0)
|
|
layout.addLayout(layout_secundario_main, 0, 1)
|
|
layout.addWidget(self.termico, 1, 0)
|
|
layout.addLayout(layout_fft_main, 1, 1)
|
|
|
|
layout.setRowStretch(0,1)
|
|
layout.setRowStretch(1,1)
|
|
|
|
# Configurar el temporizador para actualizar las gráficas en tiempo real
|
|
self.timer = QTimer(self)
|
|
self.timer.timeout.connect(self.update_graphs)
|
|
self.timer.start(self.act) # Actualiza plots
|
|
|
|
return layout
|
|
|
|
|
|
|
|
def update_graphs(self):
|
|
# Generar nuevos datos en tiempo real (puedes reemplazar con datos reales)
|
|
datos = generar_paquete_ejemplo(self.fs, self.buff)
|
|
tiempo = np.arange(0, self.buff/self.fs, 1/self.fs)
|
|
|
|
# Actualizar cada gráfico
|
|
self.primario.actualizar_plot(tiempo, self.mult_V1 * datos['V1'], self.mult_I1 * datos['I1'])
|
|
self.secundario.actualizar_plot(tiempo, self.mult_V2 * datos['V2'], self.mult_I2 * datos['I2'])
|
|
self.termico.actualizar_plot(tiempo, datos['T1'], datos['T2'])
|
|
self.fourier.actualizar_plot(tiempo, datos[self.selec_fft], self.fs, self.selec_fft)
|
|
|
|
# Actualizar Los analisis
|
|
V, I, FP, tipo = analizar_ondas(datos['V1'], datos['I1'])
|
|
self.label_V1rms.setText(f"Vrms = {V} V")
|
|
self.label_I1rms.setText(f"Irms = {I} A")
|
|
self.label_FP1.setText(f"FP = {FP} {tipo}")
|
|
|
|
V, I, FP, tipo = analizar_ondas(datos['V2'], datos['I2'])
|
|
self.label_V2rms.setText(f"Vrms = {V} V")
|
|
self.label_I2rms.setText(f"Irms = {I} A")
|
|
self.label_FP2.setText(f"FP = {FP} {tipo}")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app = QApplication(sys.argv)
|
|
|
|
window = MainWindow()
|
|
window.show()
|
|
|
|
sys.exit(app.exec_()) |