diff --git a/hisim/components/heating_meter.py b/hisim/components/heating_meter.py index 9f059ae6e..7fd224f87 100644 --- a/hisim/components/heating_meter.py +++ b/hisim/components/heating_meter.py @@ -382,7 +382,7 @@ def get_component_kpi_entries( break total_heating_energy_consumption_in_building_in_kwh_entry = KpiEntry( - name="Total heating energy used in building", + name="Total heat consumption from grid", unit="kWh", value=total_used_energy_in_kwh, tag=KpiTagEnumClass.HEATING_METER, @@ -392,7 +392,7 @@ def get_component_kpi_entries( # try to get opex costs opex_costs = self.get_cost_opex(all_outputs=all_outputs, postprocessing_results=postprocessing_results) opex_costs_in_euro_entry = KpiEntry( - name="Opex costs of heat consumption in building", + name="Opex costs of heat consumption from grid", unit="Euro", value=opex_costs.opex_energy_cost_in_euro, tag=KpiTagEnumClass.HEATING_METER, @@ -400,7 +400,7 @@ def get_component_kpi_entries( ) list_of_kpi_entries.append(opex_costs_in_euro_entry) co2_footprint_in_kg_entry = KpiEntry( - name="CO2 footprint of heat consumption in building", + name="CO2 footprint of heat consumption from grid", unit="kg", value=opex_costs.co2_footprint_in_kg, tag=KpiTagEnumClass.HEATING_METER, diff --git a/hisim/postprocessing/kpi_computation/compute_kpis.py b/hisim/postprocessing/kpi_computation/compute_kpis.py index 7e286db30..2a1142f35 100644 --- a/hisim/postprocessing/kpi_computation/compute_kpis.py +++ b/hisim/postprocessing/kpi_computation/compute_kpis.py @@ -33,7 +33,7 @@ def __post_init__(self): self.create_kpi_collection(building_objects_in_district) for building_objects_in_district in self.building_objects_in_district_list: - if building_objects_in_district in DistrictNames.__members__: + if any(word in building_objects_in_district for word in DistrictNames): self.create_overall_district_kpi(district_name=building_objects_in_district) self.kpi_collection_dict_sorted = self.sort_kpi_collection_according_to_kpi_tags( @@ -63,7 +63,7 @@ def create_kpi_collection(self, building_objects_in_district): building_objects_in_district=building_objects_in_district, kpi_tag=( KpiTagEnumClass.GENERAL - if building_objects_in_district not in DistrictNames.__members__ + if not any(word in building_objects_in_district for word in DistrictNames) else KpiTagEnumClass.ELECTRICITY_GRID ), ) @@ -76,7 +76,7 @@ def create_kpi_collection(self, building_objects_in_district): building_objects_in_district=building_objects_in_district, kpi_tag=( KpiTagEnumClass.GENERAL - if building_objects_in_district not in DistrictNames.__members__ + if not any(word in building_objects_in_district for word in DistrictNames) else KpiTagEnumClass.ELECTRICITY_GRID ), ) @@ -88,7 +88,7 @@ def create_kpi_collection(self, building_objects_in_district): building_objects_in_district=building_objects_in_district, kpi_tag=( KpiTagEnumClass.GENERAL - if building_objects_in_district not in DistrictNames.__members__ + if not any(word in building_objects_in_district for word in DistrictNames) else KpiTagEnumClass.ELECTRICITY_GRID ), ) @@ -100,7 +100,7 @@ def create_kpi_collection(self, building_objects_in_district): building_objects_in_district=building_objects_in_district, kpi_tag=( KpiTagEnumClass.GENERAL - if building_objects_in_district not in DistrictNames.__members__ + if not any(word in building_objects_in_district for word in DistrictNames) else KpiTagEnumClass.ELECTRICITY_GRID ), ) @@ -112,7 +112,7 @@ def create_kpi_collection(self, building_objects_in_district): building_objects_in_district=building_objects_in_district, kpi_tag=( KpiTagEnumClass.GENERAL - if building_objects_in_district not in DistrictNames.__members__ + if not any(word in building_objects_in_district for word in DistrictNames) else KpiTagEnumClass.ELECTRICITY_GRID ), ) @@ -125,7 +125,7 @@ def create_kpi_collection(self, building_objects_in_district): building_objects_in_district=building_objects_in_district, kpi_tag=( KpiTagEnumClass.GENERAL - if building_objects_in_district not in DistrictNames.__members__ + if not any(word in building_objects_in_district for word in DistrictNames) else KpiTagEnumClass.ELECTRICITY_GRID ), ) @@ -141,7 +141,7 @@ def create_kpi_collection(self, building_objects_in_district): building_objects_in_district=building_objects_in_district, kpi_tag=( KpiTagEnumClass.GENERAL - if building_objects_in_district not in DistrictNames.__members__ + if not any(word in building_objects_in_district for word in DistrictNames) else KpiTagEnumClass.ELECTRICITY_GRID ), ) @@ -152,7 +152,7 @@ def create_kpi_collection(self, building_objects_in_district): building_objects_in_district=building_objects_in_district, kpi_tag=( KpiTagEnumClass.GENERAL - if building_objects_in_district not in DistrictNames.__members__ + if not any(word in building_objects_in_district for word in DistrictNames) else KpiTagEnumClass.ELECTRICITY_GRID ), ) @@ -162,7 +162,7 @@ def create_kpi_collection(self, building_objects_in_district): building_objects_in_district=building_objects_in_district, kpi_tag=( KpiTagEnumClass.GENERAL - if building_objects_in_district not in DistrictNames.__members__ + if not any(word in building_objects_in_district for word in DistrictNames) else KpiTagEnumClass.ELECTRICITY_GRID ), ) diff --git a/hisim/postprocessing/kpi_computation/kpi_preparation.py b/hisim/postprocessing/kpi_computation/kpi_preparation.py index e9f6cbcc3..453ba12e1 100644 --- a/hisim/postprocessing/kpi_computation/kpi_preparation.py +++ b/hisim/postprocessing/kpi_computation/kpi_preparation.py @@ -64,7 +64,7 @@ def filter_results_according_to_postprocessing_flags( output: ComponentOutput for index, output in enumerate(all_outputs): - if (building_objects_in_district in str(output.get_pretty_name()) or + if (building_objects_in_district == output.component_name.split("_")[0] or not self.simulation_parameters.multiple_buildings): if output.postprocessing_flag is not None: if InandOutputType.ELECTRICITY_PRODUCTION in output.postprocessing_flag: @@ -229,7 +229,7 @@ def compute_electricity_consumption_and_production_and_battery_kpis( windturbine_production_entry = KpiEntry( name="Windturbine production", unit="kWh", value=windturbine_production_in_kilowatt_hour, tag=kpi_tag ) - if building_objects_in_district in DistrictNames.__members__: + if any(word in building_objects_in_district for word in DistrictNames): building_consumption_entry = KpiEntry( name="Total building electricity consumption", unit="kWh", @@ -268,7 +268,7 @@ def compute_electricity_consumption_and_production_and_battery_kpis( battery_losses_entry.name: battery_losses_entry.to_dict(), } ) - if building_objects_in_district in DistrictNames.__members__: + if any(word in building_objects_in_district for word in DistrictNames): self.kpi_collection_dict_unsorted[building_objects_in_district].update( { building_production_entry.name: building_production_entry.to_dict(), @@ -416,8 +416,8 @@ def get_electricity_to_and_from_grid_from_electricty_meter( if ( isinstance(kpi_entry["description"], str) and ElectricityMeter.get_classname() in kpi_entry["description"] + and building_objects_in_district == kpi_entry["description"].split("_")[0] ): - if kpi_entry["name"] == "Total energy from grid" and kpi_entry["unit"] == "kWh": total_energy_from_grid_in_kwh = kpi_entry["value"] elif kpi_entry["name"] == "Total energy to grid" and kpi_entry["unit"] == "kWh": @@ -585,9 +585,9 @@ def read_opex_and_capex_costs_from_results(self, building_object: str) -> None: gas_co2_in_kg = kpi_entry["value"] elif kpi_entry["tag"] == KpiTagEnumClass.HEATING_METER.value: - if kpi_name == "Opex costs of heat consumption in building": + if kpi_name == "Opex costs of heat consumption from grid": heating_costs_in_euro = kpi_entry["value"] - if kpi_name == "CO2 footprint of heat consumption in building": + if kpi_name == "CO2 footprint of heat consumption from grid": heating_co2_in_kg = kpi_entry["value"] # get CAPEX and OPEX costs for simulated period @@ -684,7 +684,7 @@ def read_opex_and_capex_costs_from_results(self, building_object: str) -> None: value=electricity_costs_in_euro, tag=( KpiTagEnumClass.COSTS - if building_object not in DistrictNames.__members__ + if not any(word in building_object for word in DistrictNames) else KpiTagEnumClass.COSTS_DISTRICT_GRID ), ) @@ -694,7 +694,7 @@ def read_opex_and_capex_costs_from_results(self, building_object: str) -> None: value=electricity_co2_in_kg, tag=( KpiTagEnumClass.EMISSIONS - if building_object not in DistrictNames.__members__ + if not any(word in building_object for word in DistrictNames) else KpiTagEnumClass.EMISSIONS_DISTRICT_GRID ), ) @@ -704,7 +704,7 @@ def read_opex_and_capex_costs_from_results(self, building_object: str) -> None: value=gas_costs_in_euro, tag=( KpiTagEnumClass.COSTS - if building_object not in DistrictNames.__members__ + if not any(word in building_object for word in DistrictNames) else KpiTagEnumClass.COSTS_DISTRICT_GRID ), ) @@ -714,27 +714,27 @@ def read_opex_and_capex_costs_from_results(self, building_object: str) -> None: value=gas_co2_in_kg, tag=( KpiTagEnumClass.EMISSIONS - if building_object not in DistrictNames.__members__ + if not any(word in building_object for word in DistrictNames) else KpiTagEnumClass.EMISSIONS_DISTRICT_GRID ), ) total_heat_costs_entry = KpiEntry( - name="Costs of grid heat to building for simulated period", + name="Costs of grid heat for simulated period", unit="EUR", value=heating_costs_in_euro, tag=( KpiTagEnumClass.COSTS - if building_object not in DistrictNames.__members__ + if not any(word in building_object for word in DistrictNames) else KpiTagEnumClass.COSTS_DISTRICT_GRID ), ) total_heat_co2_emissions_entry = KpiEntry( - name="CO2 footprint of grid heat consumption to building for simulated period", + name="CO2 footprint of grid heat consumption for simulated period", unit="kg", value=heating_co2_in_kg, tag=( KpiTagEnumClass.EMISSIONS - if building_object not in DistrictNames.__members__ + if not any(word in building_object for word in DistrictNames) else KpiTagEnumClass.EMISSIONS_DISTRICT_GRID ), ) @@ -744,7 +744,7 @@ def read_opex_and_capex_costs_from_results(self, building_object: str) -> None: value=total_investment_cost_per_simulated_period, tag=( KpiTagEnumClass.COSTS - if building_object not in DistrictNames.__members__ + if not any(word in building_object for word in DistrictNames) else KpiTagEnumClass.COSTS_DISTRICT_GRID ), ) @@ -754,7 +754,7 @@ def read_opex_and_capex_costs_from_results(self, building_object: str) -> None: value=total_device_co2_footprint_per_simulated_period, tag=( KpiTagEnumClass.EMISSIONS - if building_object not in DistrictNames.__members__ + if not any(word in building_object for word in DistrictNames) else KpiTagEnumClass.EMISSIONS_DISTRICT_GRID ), ) @@ -764,7 +764,7 @@ def read_opex_and_capex_costs_from_results(self, building_object: str) -> None: value=total_maintenance_cost_per_simulated_period, tag=( KpiTagEnumClass.COSTS - if building_object not in DistrictNames.__members__ + if not any(word in building_object for word in DistrictNames) else KpiTagEnumClass.COSTS_DISTRICT_GRID ), ) @@ -778,7 +778,7 @@ def read_opex_and_capex_costs_from_results(self, building_object: str) -> None: + heating_costs_in_euro, tag=( KpiTagEnumClass.COSTS - if building_object not in DistrictNames.__members__ + if not any(word in building_object for word in DistrictNames) else KpiTagEnumClass.COSTS_DISTRICT_GRID ), ) @@ -791,7 +791,7 @@ def read_opex_and_capex_costs_from_results(self, building_object: str) -> None: + heating_co2_in_kg, tag=( KpiTagEnumClass.EMISSIONS - if building_object not in DistrictNames.__members__ + if not any(word in building_object for word in DistrictNames) else KpiTagEnumClass.EMISSIONS_DISTRICT_GRID ), ) @@ -802,7 +802,7 @@ def read_opex_and_capex_costs_from_results(self, building_object: str) -> None: value=total_investment_cost_per_simulated_period_without_hp, tag=( KpiTagEnumClass.COSTS - if building_object not in DistrictNames.__members__ + if not any(word in building_object for word in DistrictNames) else KpiTagEnumClass.COSTS_DISTRICT_GRID ), ) @@ -812,7 +812,7 @@ def read_opex_and_capex_costs_from_results(self, building_object: str) -> None: value=total_device_co2_footprint_per_simulated_period_without_hp, tag=( KpiTagEnumClass.EMISSIONS - if building_object not in DistrictNames.__members__ + if not any(word in building_object for word in DistrictNames) else KpiTagEnumClass.EMISSIONS_DISTRICT_GRID ), ) @@ -822,7 +822,7 @@ def read_opex_and_capex_costs_from_results(self, building_object: str) -> None: value=total_maintenance_cost_per_simulated_period_without_hp, tag=( KpiTagEnumClass.COSTS - if building_object not in DistrictNames.__members__ + if not any(word in building_object for word in DistrictNames) else KpiTagEnumClass.COSTS_DISTRICT_GRID ), ) @@ -836,7 +836,7 @@ def read_opex_and_capex_costs_from_results(self, building_object: str) -> None: + heating_costs_in_euro, tag=( KpiTagEnumClass.COSTS - if building_object not in DistrictNames.__members__ + if not any(word in building_object for word in DistrictNames) else KpiTagEnumClass.COSTS_DISTRICT_GRID ), ) @@ -849,7 +849,7 @@ def read_opex_and_capex_costs_from_results(self, building_object: str) -> None: + heating_co2_in_kg, tag=( KpiTagEnumClass.EMISSIONS - if building_object not in DistrictNames.__members__ + if not any(word in building_object for word in DistrictNames) else KpiTagEnumClass.EMISSIONS_DISTRICT_GRID ), ) @@ -860,7 +860,7 @@ def read_opex_and_capex_costs_from_results(self, building_object: str) -> None: value=total_investment_cost_per_simulated_period_only_hp, tag=( KpiTagEnumClass.COSTS - if building_object not in DistrictNames.__members__ + if not any(word in building_object for word in DistrictNames) else KpiTagEnumClass.COSTS_DISTRICT_GRID ), ) @@ -870,7 +870,7 @@ def read_opex_and_capex_costs_from_results(self, building_object: str) -> None: value=total_device_co2_footprint_per_simulated_period_only_hp, tag=( KpiTagEnumClass.EMISSIONS - if building_object not in DistrictNames.__members__ + if not any(word in building_object for word in DistrictNames) else KpiTagEnumClass.EMISSIONS_DISTRICT_GRID ), ) @@ -880,7 +880,7 @@ def read_opex_and_capex_costs_from_results(self, building_object: str) -> None: value=total_maintenance_cost_per_simulated_period_only_hp, tag=( KpiTagEnumClass.COSTS - if building_object not in DistrictNames.__members__ + if not any(word in building_object for word in DistrictNames) else KpiTagEnumClass.COSTS_DISTRICT_GRID ), ) @@ -892,7 +892,7 @@ def read_opex_and_capex_costs_from_results(self, building_object: str) -> None: ), tag=( KpiTagEnumClass.COSTS - if building_object not in DistrictNames.__members__ + if not any(word in building_object for word in DistrictNames) else KpiTagEnumClass.COSTS_DISTRICT_GRID ), ) @@ -902,7 +902,7 @@ def read_opex_and_capex_costs_from_results(self, building_object: str) -> None: value=total_device_co2_footprint_per_simulated_period_only_hp, tag=( KpiTagEnumClass.EMISSIONS - if building_object not in DistrictNames.__members__ + if not any(word in building_object for word in DistrictNames) else KpiTagEnumClass.EMISSIONS_DISTRICT_GRID ), ) @@ -948,7 +948,7 @@ def create_overall_district_kpi_collection(self, district_name: str) -> Tuple[ self_consumption_district_in_kilowatt_hour = 0.0 for building_objects_in_district in self.building_objects_in_district_list: - if building_objects_in_district not in DistrictNames.__members__: + if not any(word in building_objects_in_district for word in DistrictNames): electricity_consumption_all_single_buildings_in_kilowatt_hour += self.kpi_collection_dict_unsorted[ building_objects_in_district ]["Total electricity consumption"]["value"] @@ -959,7 +959,7 @@ def create_overall_district_kpi_collection(self, district_name: str) -> Tuple[ building_objects_in_district ]["Self-consumption of electricity"]["value"] - if building_objects_in_district in DistrictNames.__members__: + if any(word in building_objects_in_district for word in DistrictNames): electricity_production_district_in_kilowatt_hour += ( self.kpi_collection_dict_unsorted[building_objects_in_district]["Total electricity production"][ "value" @@ -1086,7 +1086,7 @@ def create_overall_district_costs_collection(self, district_name): total_maintenance_cost_per_simulated_period_only_hp_district = 0.0 for building_objects_in_district in self.building_objects_in_district_list: - if building_objects_in_district not in DistrictNames.__members__: + if not any(word in building_objects_in_district for word in DistrictNames): total_investment_cost_for_equipment_per_simulated_period_all_single_buildings += ( self.kpi_collection_dict_unsorted[building_objects_in_district][ "Investment costs for equipment per simulated period" @@ -1121,7 +1121,7 @@ def create_overall_district_costs_collection(self, district_name): ]["value"] ) - if building_objects_in_district in DistrictNames.__members__: + if any(word in building_objects_in_district for word in DistrictNames): total_investment_cost_for_equipment_per_simulated_period_district = self.kpi_collection_dict_unsorted[ building_objects_in_district ]["Investment costs for equipment per simulated period"]["value"] @@ -1338,7 +1338,7 @@ def create_overall_district_emissions_collection(self, district_name): total_co2_emissions_for_equipment_per_simulated_period_only_hp_district = 0.0 for building_objects_in_district in self.building_objects_in_district_list: - if building_objects_in_district not in DistrictNames.__members__: + if not any(word in building_objects_in_district for word in DistrictNames): total_co2_emissions_for_equipment_per_simulated_period_all_single_buildings += ( self.kpi_collection_dict_unsorted[building_objects_in_district][ "CO2 footprint for equipment per simulated period" @@ -1357,7 +1357,7 @@ def create_overall_district_emissions_collection(self, district_name): ]["value"] ) - if building_objects_in_district in DistrictNames.__members__: + if any(word in building_objects_in_district for word in DistrictNames): total_co2_emissions_for_equipment_per_simulated_period_district = self.kpi_collection_dict_unsorted[ building_objects_in_district ]["CO2 footprint for equipment per simulated period"]["value"] @@ -1473,7 +1473,7 @@ def create_overall_district_contracting_collection(self, district_name, all_outp set_of_buildings_in_contracting = set() for building_objekt in self.building_objects_in_district_list: for output in all_outputs: - if building_objekt in output.component_name and district_name in output.component_name: + if building_objekt == output.component_name.split("_")[0] and district_name in output.component_name: set_of_buildings_in_contracting.add(building_objekt) if district_name in set_of_buildings_in_contracting: @@ -1606,7 +1606,7 @@ def get_all_component_kpis(self, wrapped_components: List[ComponentWrapper]) -> for kpi_entry in my_component_kpi_entry_list: for object_name in self.kpi_collection_dict_unsorted.keys(): - if (object_name in my_component.component_name or + if (object_name == my_component.component_name.split("_")[0] or not self.simulation_parameters.multiple_buildings): self.kpi_collection_dict_unsorted[object_name][kpi_entry.name] = kpi_entry.to_dict() break diff --git a/tests/test_heating_meter.py b/tests/test_heating_meter.py index b16f9823d..156aabdd0 100644 --- a/tests/test_heating_meter.py +++ b/tests/test_heating_meter.py @@ -234,7 +234,7 @@ def test_house( jsondata = jsondata["BUI1"] - heat_consumption_in_kilowatt_hour = jsondata["Heating Meter"]["Total heating energy used in building"].get("value") + heat_consumption_in_kilowatt_hour = jsondata["Heating Meter"]["Total heat consumption from grid"].get("value") heat_consumption_for_space_heating_in_kilowatt_hour = jsondata["Heat Distribution System"][ "Thermal output energy of heat distribution system" @@ -243,10 +243,10 @@ def test_house( # "Residents' total thermal dhw consumption" # ].get("value") - opex_costs_for_heat_in_euro = jsondata["Heating Meter"]["Opex costs of heat consumption in building"].get("value") + opex_costs_for_heat_in_euro = jsondata["Heating Meter"]["Opex costs of heat consumption from grid"].get("value") co2_footprint_due_to_heat_use_in_kg = jsondata["Heating Meter"][ - "CO2 footprint of heat consumption in building" + "CO2 footprint of heat consumption from grid" ].get("value") log.information(