From 8e424d007e74d864d46c237872dd88f398eb5185 Mon Sep 17 00:00:00 2001 From: LeoBarreiro Date: Fri, 27 Aug 2021 18:32:22 -0300 Subject: [PATCH] =?UTF-8?q?FIX:=20Eliminada=20implantaci=C3=B3n=20de=20cal?= =?UTF-8?q?culo=20rms=20num=C3=A9rico.=20Se=20usa=20solamente=20el=20m?= =?UTF-8?q?=C3=A9todo=20simb=C3=B3lico.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dimmer.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/dimmer.py b/dimmer.py index 0ab3d98..aa1add9 100644 --- a/dimmer.py +++ b/dimmer.py @@ -1,5 +1,6 @@ import numpy as np from scipy.optimize import bisect +from tabulate import tabulate class Dimmer: @@ -26,10 +27,10 @@ def _v_sine(self, t): omega = 2 * np.pi * self.frequency return self.amplitud * np.sin(omega * t) - def v_dimmer(self, t): + def v_dimmer(self, t): per = self.periode tint = self.time_interrupt - + # sourcery skip: flip-comparison if (0 <= t and t < tint): return 0 elif (tint <= t and t < 0.5 * per): @@ -39,15 +40,6 @@ def v_dimmer(self, t): elif (0.5*per + tint <= t and t < per): return self._v_sine(t) - def vrms_num(self): - t_series = np.arange(0, self.periode, self.periode / 200) - v_series = [self.v_dimmer(t) for t in t_series] - v_sum = 0 - for i in v_series: - v_sum = v_sum + i**2 - rms = np.sqrt(v_sum / len(v_series)) - return rms - def vrms_simbolic(self): amp, omega = self.amplitud, 2 * np.pi * self.frequency per, tint = self.periode, self.time_interrupt @@ -90,3 +82,15 @@ def function(tint, bias=0): self.time_interrupt = time_interrupt_backup return root + + def print_dimmer_state(self): + # TODO: Ver si conviene agregar un atributo de vrms actual. Se repite el calculo en ocaciones. + vrms = self.vrms_simbolic() + duty = self.convert_rms_duty(vrms) + header = ["Amplitud [V]", "Frecuencia [Hz]", "InterrupciĆ³n [s]", "Vrms [V]", "Duty [%]"] + data = [[self.amplitud, self.frequency, self.time_interrupt, vrms, duty]] + print_table(header, data) + +def print_table(header, data): + print(tabulate(tabular_data=data, headers=header, tablefmt="simple", + numalign="center", stralign="center")) \ No newline at end of file