def export_data(data: MotorCalc, destination: str): if destination == "": destination = "results_" + dt.datetime.today().strftime( "%d-%m-%y %X").replace(":", ".") keys = [ "Limit", "kls", "klr", "gs", "gr", "Ps", "PAl", "Pss", "Pp", "stator_losses", "rotor_losses", "stator_fluxes", "rotor_fluxes" ] stator_losses = data.stator_losses_serializable() rotor_losses = data.rotor_losses_serializable() stator_fluxes = data.stator_fluxes_serializable() rotor_fluxes = data.rotor_fluxes_serializable() vals = [ data.limit, data.kls_, data.klr_, data.gs_, data.gr_, data.Ps, data.PAl, data.Pss, data.Pp, stator_losses, rotor_losses, stator_fluxes, rotor_fluxes ] f_cont = OrderedDict(zip(keys, vals)) if not destination.endswith(".json"): destination += ".json" dir_to_open = ROOT_DIR + f"/json/{destination}" result = 0 print(f_cont) print(destination) print(data) with open(dir_to_open, "w+") as f: result = f.write(json.dumps(f_cont, cls=NumpyEncoder)) return result != 0
def export_data(data: MotorCalc, destination: str) -> bool: limit = data.limit kls = data.kls_ klr = data.klr_ gs = data.gs_ gr = data.gr_ Ps = data.Ps PAl = data.PAl Pss = data.Pss Pp = data.Pp losses_pssv, losses_ppv = data.rotor_losses() losses_psv, losses_palv = data.stator_losses() stator_fluxes = data.stator_fluxes() rotor_fluxes = data.rotor_fluxes() losses_pssv = losses_pssv.to_list() losses_ppv = losses_ppv.to_list() losses_psv = losses_psv.to_list() losses_palv = losses_palv.to_list() stator_fluxes = stator_fluxes.to_list() rotor_fluxes = rotor_fluxes.to_list() kwargs = {"limit": limit, "kls": kls, "klr": klr, "gs": gs, "gr": gr, "Ps": Ps, "PAl": PAl, "Pss": Pss, "Pp": Pp, "losses_pssv": losses_pssv, "losses_ppv": losses_ppv, "losses_psv": losses_psv, "losses_palv": losses_palv, "stator_fluxes": stator_fluxes, "rotor_fluxes": rotor_fluxes} destination = destination + ".npz" if not destination.endswith(".npz") else destination path = ROOT_DIR + "/npz/" + destination np.savez(path, **kwargs) return True
def export_data(data: MotorCalc): vals_to_insert = (data.limit, data.kls_, data.klr_, data.gs_, data.gr_, data.Ps, data.PAl, data.Pss, data.Pp) Queries.insert_into_motor_results_table(vals_to_insert) id_added = Queries.getLastID(table_name="MotorResults") print(id_added) losses_pssv, losses_ppv = data.rotor_losses() losses_psv, losses_palv = data.stator_losses() stator_fluxes = data.stator_fluxes() rotor_fluxes = data.rotor_fluxes() Queries.insert_into_loss_table(loss_type=LossType.LOSS_PSS, losses=losses_pssv, id_to_add=id_added) Queries.insert_into_loss_table(loss_type=LossType.LOSS_PP, losses=losses_ppv, id_to_add=id_added) Queries.insert_into_loss_table(loss_type=LossType.LOSS_PS, losses=losses_psv, id_to_add=id_added) Queries.insert_into_loss_table(loss_type=LossType.LOSS_PAL, losses=losses_palv, id_to_add=id_added) Queries.insert_into_flux_table(flux_type=FluxType.StatorFlux, fluxes=stator_fluxes, id_to_add=id_added) Queries.insert_into_flux_table(flux_type=FluxType.RotorFlux, fluxes=rotor_fluxes, id_to_add=id_added) return id_added
def save_results(cls, filename, motor_calc: MotorCalc): losses_pssv, losses_ppv = motor_calc.rotor_losses() losses_psv, losses_palv = motor_calc.stator_losses() losses_array = np.array([[losses_psv], [losses_palv], [losses_pssv], [losses_ppv]]) np.savetxt('test.out', losses_array) # TODO: ADJUST THIS CODE TO MY NEEDS! import numpy as np a = np.array([1, 2, 3, 4, 5]) b = np.array([5.4, 2.3, 5.3, 2.4]) c = np.array([a, b]) print(c) np.savez('test.npz', c=c) d = np.load('test.npz', allow_pickle=True) print(d["c"]) print(list(d.keys()))
def runCalculations(self): input_vals = self.validateLimitVals() if len(input_vals) == 4: ks, kr, gs, gr = input_vals test_motor = Motor() motor_calc = MotorCalc(test_motor, limit=0, kls=ks, klr=kr, gs=gs, gr=gr) motor_calc.calculate() motor_results = MotorResults(motor_calc) self.results_tab = CalcResultsWidget(motor_results) self.results_tab.show() print(motor_results) else: print("Nie weszło!")
def run(self): step_count = 10 step_val = int((self.limit_upper - self.limit_lower) / step_count) or 1 step_range = range(self.limit_lower, self.limit_upper + 1, step_val) for i in step_range: motor_calc = MotorCalc(self.motor, limit=i) motor_calc.calculate() Ps, PAl, Pss, Pp = motor_calc.get_motor_losses() self.__Ps.append(Ps) self.__PAl.append(PAl) self.__Pss.append(Pss) self.__Pp.append(Pp) self.__limits.append(i) if i == step_range[len(step_range) - 1]: self._signal.emit(100) print("koniec!") else: val_to_send = (i / step_range[len(step_range) - 1]) * 100 self._signal.emit(val_to_send) print("wysyłanie ", val_to_send) print(self.__limits)
"value" REAL NOT NULL, "result_ID" INTEGER, PRIMARY KEY("ID" AUTOINCREMENT), FOREIGN KEY("result_ID") REFERENCES "MotorResults" ("ID")) ''' db.execute(stmt) # rotor_fluxes stmt = '''CREATE TABLE "rotor_fluxes" ( "ID" INTEGER, "order" INTEGER, "value" REAL NOT NULL, "result_ID" INTEGER, PRIMARY KEY("ID" AUTOINCREMENT), FOREIGN KEY("result_ID") REFERENCES "MotorResults" ("ID")) ''' db.execute(stmt) return True if __name__ == "__main__": from data_transfer.db_data_transfer import DBDataTransfer motor = Motor() motorCalc = MotorCalc(motor, limit=5) motorCalc.calculate() id_added = DBDataTransfer.export_data(motorCalc) losses_Pss, losses_Pp, losses_Ps, losses_PAl = DBDataTransfer.import_data( id_added) print(losses_Pss)
:param filename: name of file to be loaded. :return: str """ if filename is None: raise LoadFileError("Filename is empty!") with open(filename, 'r') as f: f_cont = f.read() return f_cont def __str__(self): return self.__motor_calc.__str__() if __name__ == "__main__": m = Motor() m_calc = MotorCalc(m, limit=15) m_calc.calculate() m_res = MotorResults(m_calc) m_res.save_to_json("test_3") # limit, Ps, PAl, Pss, Pp, stator_losses, rotor_losses = \ # loaded_json = m_res.load_from_json(r'json/testowy_1.json') # loaded_json = OrderedDict(loaded_json) # for k, v in loaded_json.items(): # print(k, v) # print(m_res.load_from_file(r'results/results_25-01-21 21.20.29.txt').splitlines()) # m_res.save_to_DB()