def store_error(self, component_info: ComponentInfo) -> None: try: if self.fault_state is not FaultStateLevel.NO_ERROR: log.MainLogger().error(component_info.name + ": FaultState " + str(self.fault_state) + ", FaultStr " + self.fault_str + ", Traceback: \n" + traceback.format_exc()) ramdisk = compatibility.is_ramdisk_in_use() if ramdisk: topic = self.type_topic_mapping_comp.get( component_info.type, component_info.type) prefix = "openWB/set/" + topic + "/" if component_info.id is not None: if topic == "lp": prefix += str(component_info.id) + "/socF" else: prefix += str(component_info.id) + "/f" else: prefix += "f" pub.pub_single(prefix + "aultStr", self.fault_str) pub.pub_single(prefix + "aultState", self.fault_state.value) else: topic = self.__type_topic_mapping(component_info.type) pub.Pub().pub( "openWB/set/" + topic + "/" + str(component_info.id) + "/get/fault_str", self.fault_str) pub.Pub().pub( "openWB/set/" + topic + "/" + str(component_info.id) + "/get/fault_state", self.fault_state.value) except Exception: log.MainLogger().exception("Fehler im Modul fault_state")
def __add_and_save_offset(self, daily_yield: float, counter: float, counter_start: float, counter_offset: float) -> float: ramdisk = compatibility.is_ramdisk_in_use() if daily_yield == 0 and \ counter > counter_start + counter_offset and \ self.component_config["configuration"]["ip_address2"] == "none": if ramdisk: with open("/var/www/html/openWB/ramdisk/pvkwh_start", "w") as f: f.write(str(counter)) with open("/var/www/html/openWB/ramdisk/pvkwh", "r") as ff: counter_old = float(ff.read()) else: topic = "openWB/set/system/device/" + str(self.__device_id)+"/component/" + \ str(self.component_config["id"])+"/pvkwh_start" pub.pub_single(topic, counter) topic = "openWB/pv/" + str( self.component_config["id"]) + "/counter" try: counter_old = float(Offset().offset(topic)) except ValueError: counter_old = 0 counter_offset = counter_old - counter counter += counter_offset if ramdisk: with open("/var/www/html/openWB/ramdisk/pvkwh_offset", "w") as f: f.write(str(counter_offset)) else: topic = "openWB/set/system/device/" + str(self.__device_id)+"/component/" + \ str(self.component_config["id"])+"/counter_offset" pub.pub_single(topic, counter_offset) else: if ramdisk: with open("/var/www/html/openWB/ramdisk/pvkwh_offset", "w") as f: f.write(str(counter_offset)) else: topic = "openWB/set/system/device/" + str(self.__device_id)+"/component/" + \ str(self.component_config["id"])+"/counter_offset" pub.pub_single(topic, counter_offset) return counter
def sim_count(self, power_present: float, topic: str = "", data: dict = {}, prefix: str = "") -> typing.Tuple[float, float]: """ emulate import export Parameters ---------- power_present: aktuelle Leistung topic: Topic, ungenutzt data: ungenutzt prefix: prefix für die ramdisk-Datei Return ------ imported: importierte Energie exported: exportierte Energie """ try: timestamp_present = time.time() power_previous, counter_export_present, counter_export_previous = 0, 0, 0 counter_import_present, counter_import_previous = 0, 0 timestamp_previous = 0.0 start_new = True if os.path.isfile('/var/www/html/openWB/ramdisk/' + prefix + 'sec0'): timestamp_previous = float(read_ramdisk_file(prefix + 'sec0')) power_previous = int(float(read_ramdisk_file(prefix + 'wh0'))) try: counter_import_present = int( float(read_ramdisk_file(prefix + 'watt0pos'))) except Exception: counter_import_present = int(Restore().restore_value( "watt0pos", prefix)) counter_import_previous = counter_import_present try: counter_export_present = int( float(read_ramdisk_file(prefix + 'watt0neg'))) except Exception: counter_export_present = int(Restore().restore_value( "watt0neg", prefix)) if counter_export_present < 0: # runs/simcount.py speichert das Zwischenergebnis des Exports negativ ab. counter_export_present = counter_export_present * -1 counter_export_previous = counter_export_present log.MainLogger().debug( "simcount Zwischenergebnisse letzte Berechnung: Import: " + str(counter_import_previous) + " Export: " + str(counter_export_previous) + " Power: " + str(power_previous)) start_new = False write_ramdisk_file(prefix + 'sec0', "%22.6f" % timestamp_present) write_ramdisk_file(prefix + 'wh0', power_present) if start_new: return 0, 0 else: timestamp_previous = timestamp_previous + 1 seconds_since_previous = timestamp_present - timestamp_previous imp_exp = calculate_import_export(seconds_since_previous, power_previous, power_present) counter_export_present = counter_export_present + imp_exp[1] counter_import_present = counter_import_present + imp_exp[0] log.MainLogger().debug( "simcount aufsummierte Energie: Bezug[Ws]: " + str(counter_import_present) + ", Einspeisung[Ws]: " + str(counter_export_present)) wattposkh = counter_import_present / 3600 wattnegkh = counter_export_present / 3600 log.MainLogger().info("simcount Ergebnis: Bezug[Wh]: " + str(wattposkh) + ", Einspeisung[Wh]: " + str(wattnegkh)) topic = get_topic(prefix) log.MainLogger().debug( "simcount Zwischenergebnisse atkuelle Berechnung: Import: " + str(counter_import_present) + " Export: " + str(counter_export_present) + " Power: " + str(power_present)) write_ramdisk_file(prefix + 'watt0pos', counter_import_present) if counter_import_present != counter_import_previous: pub.pub_single("openWB/" + topic + "/WHImported_temp", counter_import_present, no_json=True) write_ramdisk_file(prefix + 'watt0neg', counter_export_present) if counter_export_present != counter_export_previous: pub.pub_single("openWB/" + topic + "/WHExport_temp", counter_export_present, no_json=True) return wattposkh, wattnegkh except Exception as e: process_error(e)
def sim_count( self, power_present: float, topic: str = "", data: dict = {}, prefix: str = "" ) -> typing.Tuple[float, float]: """ emulate import export Parameters ---------- power_present: aktuelle Leistung topic: Topic, ungenutzt data: ungenutzt prefix: prefix für die ramdisk-Datei Return ------ imported: importierte Energie exported: exportierte Energie """ try: timestamp_present = time.time() power_previous, counter_export_present, counter_export_previous = 0, 0, 0 counter_import_present, counter_import_previous = 0, 0 timestamp_previous = 0.0 start_new = True if os.path.isfile('/var/www/html/openWB/ramdisk/'+prefix+'sec0'): timestamp_previous = float(read_ramdisk_file(prefix+'sec0')) power_previous = int(float(read_ramdisk_file(prefix+'wh0'))) try: counter_import_present = int(float(read_ramdisk_file(prefix+'watt0pos'))) except Exception: counter_import_present = int(Restore().restore_value("watt0pos", prefix)) counter_import_previous = counter_import_present try: counter_export_present = int(float(read_ramdisk_file(prefix+'watt0neg'))) except Exception: counter_export_present = int(Restore().restore_value("watt0neg", prefix)) if counter_export_present < 0: # runs/simcount.py speichert das Zwischenergebnis des Exports negativ ab. counter_export_present = counter_export_present * -1 counter_export_previous = counter_export_present log.debug("simcount Zwischenergebnisse letzte Berechnung: Import: " + str(counter_import_previous) + " Export: " + str(counter_export_previous) + " Leistung: " + str(power_previous)) start_new = False write_ramdisk_file(prefix+'sec0', "%22.6f" % timestamp_present) write_ramdisk_file(prefix+'wh0', int(power_present)) if start_new: log.debug("Neue Simulation starten.") if prefix == "bezug": imported = get_existing_imports_exports('bezugkwh') exported = get_existing_imports_exports('einspeisungkwh') elif prefix == "pv2": imported = 0 exported = get_existing_imports_exports('pv2kwh') elif prefix == "pv": imported = 0 exported = get_existing_imports_exports('pvkwh') else: imported = get_existing_imports_exports('speicherikwh') exported = get_existing_imports_exports('speicherekwh') return imported, exported else: # timestamp_previous = timestamp_previous + 1 # do not increment time if calculating areas! seconds_since_previous = timestamp_present - timestamp_previous imp_exp = calculate_import_export( seconds_since_previous, power_previous, power_present) counter_export_present = counter_export_present + imp_exp[1] counter_import_present = counter_import_present + imp_exp[0] log.debug( "simcount aufsummierte Energie: Bezug[Ws]: " + str(counter_import_present) + ", Einspeisung[Ws]: " + str(counter_export_present) ) energy_positive_kWh = counter_import_present / 3600 energy_negative_kWh = counter_export_present / 3600 log.info( "simcount Ergebnis: Bezug[Wh]: " + str(energy_positive_kWh) + ", Einspeisung[Wh]: " + str(energy_negative_kWh) ) topic = get_topic(prefix) log.debug( "simcount Zwischenergebnisse aktuelle Berechnung: Import: " + str(counter_import_present) + " Export: " + str(counter_export_present) + " Leistung: " + str(power_present) ) write_ramdisk_file(prefix+'watt0pos', counter_import_present) if counter_import_present != counter_import_previous: pub.pub_single("openWB/"+topic+"/WHImported_temp", counter_import_present, no_json=True) write_ramdisk_file(prefix+'watt0neg', counter_export_present) if counter_export_present != counter_export_previous: pub.pub_single("openWB/"+topic+"/WHExport_temp", counter_export_present, no_json=True) return energy_positive_kWh, energy_negative_kWh except Exception as e: process_error(e)