monthly_energy_balance_work.../results.py

281 lines
16 KiB
Python

from pathlib import Path
import pandas as pd
import hub.helpers.constants as cte
class Results:
def __init__(self, city, path):
self._city = city
self._path = path
def print(self):
print_results = None
file = 'city name: ' + self._city.name + '\n'
array = [None] * 12
for building in self._city.buildings:
if cte.MONTH in building.heating_demand.keys():
heating_results = building.heating_demand[cte.MONTH].rename(columns={cte.INSEL_MEB: f'{building.name} heating Wh'})
else:
heating_results = pd.DataFrame(array, columns=[f'{building.name} heating demand Wh'])
if cte.MONTH in building.cooling_demand.keys():
cooling_results = building.cooling_demand[cte.MONTH].rename(columns={cte.INSEL_MEB: f'{building.name} cooling Wh'})
else:
cooling_results = pd.DataFrame(array, columns=[f'{building.name} cooling demand Wh'])
if cte.MONTH in building.lighting_electrical_demand.keys():
lighting_results = building.lighting_electrical_demand[cte.MONTH]\
.rename(columns={cte.INSEL_MEB: f'{building.name} lighting electrical demand Wh'})
else:
lighting_results = pd.DataFrame(array, columns=[f'{building.name} lighting electrical demand Wh'])
if cte.MONTH in building.appliances_electrical_demand.keys():
appliances_results = building.appliances_electrical_demand[cte.MONTH]\
.rename(columns={cte.INSEL_MEB: f'{building.name} appliances electrical demand Wh'})
else:
appliances_results = pd.DataFrame(array, columns=[f'{building.name} appliances electrical demand Wh'])
if cte.MONTH in building.domestic_hot_water_heat_demand.keys():
dhw_results = building.domestic_hot_water_heat_demand[cte.MONTH]\
.rename(columns={cte.INSEL_MEB: f'{building.name} domestic hot water demand Wh'})
else:
dhw_results = pd.DataFrame(array, columns=[f'{building.name} domestic hot water demand Wh'])
if cte.MONTH in building.heating_consumption.keys():
heating_consumption_results = pd.DataFrame(building.heating_consumption[cte.MONTH],
columns=[f'{building.name} heating consumption Wh'])
else:
heating_consumption_results = pd.DataFrame(array, columns=[f'{building.name} heating consumption Wh'])
if cte.MONTH in building.cooling_consumption.keys():
cooling_consumption_results = pd.DataFrame(building.cooling_consumption[cte.MONTH],
columns=[f'{building.name} cooling consumption Wh'])
else:
cooling_consumption_results = pd.DataFrame(array, columns=[f'{building.name} cooling consumption Wh'])
if cte.MONTH in building.domestic_hot_water_consumption.keys():
dhw_consumption_results = pd.DataFrame(building.domestic_hot_water_consumption[cte.MONTH],
columns=[f'{building.name} domestic hot water consumption Wh'])
else:
dhw_consumption_results = pd.DataFrame(array, columns=[f'{building.name} domestic hot water consumption Wh'])
if cte.MONTH in building.heating_peak_load.keys():
heating_peak_load_results = pd.DataFrame(building.heating_peak_load[cte.MONTH],
columns=[f'{building.name} heating peak load W'])
else:
heating_peak_load_results = pd.DataFrame(array, columns=[f'{building.name} heating peak load W'])
if cte.MONTH in building.cooling_peak_load.keys():
cooling_peak_load_results = pd.DataFrame(building.cooling_peak_load[cte.MONTH],
columns=[f'{building.name} cooling peak load W'])
else:
cooling_peak_load_results = pd.DataFrame(array, columns=[f'{building.name} cooling peak load W'])
if cte.MONTH in building.onsite_electrical_production.keys():
monthly_onsite_electrical_production = building.onsite_electrical_production[cte.MONTH]
onsite_electrical_production = pd.DataFrame(monthly_onsite_electrical_production,
columns=[f'{building.name} onsite electrical production Wh'])
else:
onsite_electrical_production = pd.DataFrame(array, columns=[f'{building.name} onsite electrical production Wh'])
heating = 0
cooling = 0
for system in building.energy_systems:
for demand_type in system.demand_types:
if demand_type == cte.HEATING:
heating = 1
if demand_type == cte.COOLING:
cooling = 1
if cte.MONTH in building.heating_peak_load.keys() and cte.MONTH in building.cooling_peak_load.keys():
peak_lighting = 0
peak_appliances = 0
for thermal_zone in building.internal_zones[0].thermal_zones:
lighting = thermal_zone.lighting
for schedule in lighting.schedules:
for value in schedule.values:
if value * lighting.density * thermal_zone.total_floor_area > peak_lighting:
peak_lighting = value * lighting.density * thermal_zone.total_floor_area
appliances = thermal_zone.appliances
for schedule in appliances.schedules:
for value in schedule.values:
if value * appliances.density * thermal_zone.total_floor_area > peak_appliances:
peak_appliances = value * appliances.density * thermal_zone.total_floor_area
monthly_electricity_peak = [0.9 * peak_lighting + 0.7 * peak_appliances] * 12
conditioning_peak = []
for i, value in enumerate(building.heating_peak_load[cte.MONTH]):
if cooling * building.cooling_peak_load[cte.MONTH][i] > heating * value:
conditioning_peak.append(cooling * building.cooling_peak_load[cte.MONTH][i])
else:
conditioning_peak.append(heating * value)
monthly_electricity_peak[i] += 0.8 * conditioning_peak[i]
electricity_peak_load_results = pd.DataFrame(monthly_electricity_peak
, columns=[f'{building.name} electricity peak load W'])
else:
electricity_peak_load_results = pd.DataFrame(array, columns=[f'{building.name} electricity peak load W'])
if cte.MONTH in building.distribution_systems_electrical_consumption.keys():
extra_electrical_consumption = pd.DataFrame(building.distribution_systems_electrical_consumption[cte.MONTH],
columns=[
f'{building.name} electrical consumption for distribution Wh'])
else:
extra_electrical_consumption = pd.DataFrame(array,
columns=[
f'{building.name} electrical consumption for distribution Wh'])
if print_results is None:
print_results = heating_results
else:
print_results = pd.concat([print_results, heating_results], axis='columns')
print_results = pd.concat([print_results,
cooling_results,
lighting_results,
appliances_results,
dhw_results,
heating_consumption_results,
cooling_consumption_results,
dhw_consumption_results,
heating_peak_load_results,
cooling_peak_load_results,
electricity_peak_load_results,
onsite_electrical_production,
extra_electrical_consumption], axis='columns')
file += '\n'
file += f'name: {building.name}\n'
file += f'year of construction: {building.year_of_construction}\n'
file += f'function: {building.function}\n'
file += f'floor area: {building.floor_area}\n'
if building.average_storey_height is not None and building.eave_height is not None:
file += f'storeys: {int(building.eave_height / building.average_storey_height)}\n'
else:
file += f'storeys: n/a\n'
file += f'volume: {building.volume}\n'
full_path_results = Path(self._path / 'demand.csv').resolve()
print_results.to_csv(full_path_results, na_rep='null')
full_path_metadata = Path(self._path / 'metadata.csv').resolve()
with open(full_path_metadata, 'w') as metadata_file:
metadata_file.write(file)
def outputsforgraph(self):
outputs_energy =pd.DataFrame()
array = [None] * 12
for building in self._city.buildings:
if cte.MONTH in building.heating_demand.keys():
heating_results = building.heating_demand[cte.MONTH].rename(
columns={cte.INSEL_MEB: f'{building.name} heating Wh'})
else:
heating_results = pd.DataFrame(array, columns=[f'{building.name} heating demand Wh'])
if cte.MONTH in building.cooling_demand.keys():
cooling_results = building.cooling_demand[cte.MONTH].rename(
columns={cte.INSEL_MEB: f'{building.name} cooling Wh'})
else:
cooling_results = pd.DataFrame(array, columns=[f'{building.name} cooling demand Wh'])
if cte.MONTH in building.lighting_electrical_demand.keys():
lighting_results = building.lighting_electrical_demand[cte.MONTH] \
.rename(columns={cte.INSEL_MEB: f'{building.name} lighting electrical demand Wh'})
else:
lighting_results = pd.DataFrame(array, columns=[f'{building.name} lighting electrical demand Wh'])
if cte.MONTH in building.appliances_electrical_demand.keys():
appliances_results = building.appliances_electrical_demand[cte.MONTH] \
.rename(columns={cte.INSEL_MEB: f'{building.name} appliances electrical demand Wh'})
else:
appliances_results = pd.DataFrame(array, columns=[f'{building.name} appliances electrical demand Wh'])
if cte.MONTH in building.domestic_hot_water_heat_demand.keys():
dhw_results = building.domestic_hot_water_heat_demand[cte.MONTH] \
.rename(columns={cte.INSEL_MEB: f'{building.name} domestic hot water demand Wh'})
else:
dhw_results = pd.DataFrame(array, columns=[f'{building.name} domestic hot water demand Wh'])
if cte.MONTH in building.heating_consumption.keys():
heating_consumption_results = pd.DataFrame(building.heating_consumption[cte.MONTH],
columns=[f'{building.name} heating consumption Wh'])
else:
heating_consumption_results = pd.DataFrame(array, columns=[f'{building.name} heating consumption Wh'])
if cte.MONTH in building.cooling_consumption.keys():
cooling_consumption_results = pd.DataFrame(building.cooling_consumption[cte.MONTH],
columns=[f'{building.name} cooling consumption Wh'])
else:
cooling_consumption_results = pd.DataFrame(array, columns=[f'{building.name} cooling consumption Wh'])
if cte.MONTH in building.domestic_hot_water_consumption.keys():
dhw_consumption_results = pd.DataFrame(building.domestic_hot_water_consumption[cte.MONTH],
columns=[f'{building.name} domestic hot water consumption Wh'])
else:
dhw_consumption_results = pd.DataFrame(array, columns=[f'{building.name} domestic hot water consumption Wh'])
if cte.MONTH in building.heating_peak_load.keys():
heating_peak_load_results = pd.DataFrame(building.heating_peak_load[cte.MONTH],
columns=[f'{building.name} heating peak load W'])
else:
heating_peak_load_results = pd.DataFrame(array, columns=[f'{building.name} heating peak load W'])
if cte.MONTH in building.cooling_peak_load.keys():
cooling_peak_load_results = pd.DataFrame(building.cooling_peak_load[cte.MONTH],
columns=[f'{building.name} cooling peak load W'])
else:
cooling_peak_load_results = pd.DataFrame(array, columns=[f'{building.name} cooling peak load W'])
if cte.MONTH in building.onsite_electrical_production.keys():
monthly_onsite_electrical_production = building.onsite_electrical_production[cte.MONTH]
onsite_electrical_production = pd.DataFrame(monthly_onsite_electrical_production,
columns=[f'{building.name} onsite electrical production Wh'])
else:
onsite_electrical_production = pd.DataFrame(array,
columns=[f'{building.name} onsite electrical production Wh'])
heating = 0
cooling = 0
for system in building.energy_systems:
for demand_type in system.demand_types:
if demand_type == cte.HEATING:
heating = 1
if demand_type == cte.COOLING:
cooling = 1
if cte.MONTH in building.heating_peak_load.keys() and cte.MONTH in building.cooling_peak_load.keys():
peak_lighting = 0
peak_appliances = 0
for thermal_zone in building.internal_zones[0].thermal_zones:
lighting = thermal_zone.lighting
for schedule in lighting.schedules:
for value in schedule.values:
if value * lighting.density * thermal_zone.total_floor_area > peak_lighting:
peak_lighting = value * lighting.density * thermal_zone.total_floor_area
appliances = thermal_zone.appliances
for schedule in appliances.schedules:
for value in schedule.values:
if value * appliances.density * thermal_zone.total_floor_area > peak_appliances:
peak_appliances = value * appliances.density * thermal_zone.total_floor_area
monthly_electricity_peak = [0.9 * peak_lighting + 0.7 * peak_appliances] * 12
conditioning_peak = []
for i, value in enumerate(building.heating_peak_load[cte.MONTH]):
if cooling * building.cooling_peak_load[cte.MONTH][i] > heating * value:
conditioning_peak.append(cooling * building.cooling_peak_load[cte.MONTH][i])
else:
conditioning_peak.append(heating * value)
monthly_electricity_peak[i] += 0.8 * conditioning_peak[i]
electricity_peak_load_results = pd.DataFrame(monthly_electricity_peak
, columns=[f'{building.name} electricity peak load W'])
else:
electricity_peak_load_results = pd.DataFrame(array, columns=[f'{building.name} electricity peak load W'])
if cte.MONTH in building.distribution_systems_electrical_consumption.keys():
extra_electrical_consumption = pd.DataFrame(building.distribution_systems_electrical_consumption[cte.MONTH],
columns=[
f'{building.name} electrical consumption for distribution Wh'])
else:
extra_electrical_consumption = pd.DataFrame(array,
columns=[
f'{building.name} electrical consumption for distribution Wh'])
listgraph = [lighting_results.values.sum(),appliances_results.values.sum(),
heating_consumption_results.values.sum(),
cooling_consumption_results.values.sum(),
dhw_consumption_results.values.sum(),
extra_electrical_consumption.values.sum()
]
outputs_energy[f'building {building.name}'] = listgraph
outputs_energy.index = ['Lighting consumption', 'Appliances consumption', 'Heating consumption',
'Cooling consumption', 'DHW consumption', 'Extra electrical consumption']
total_final_energy = (lighting_results.values.sum() + appliances_results.values.sum() + \
heating_consumption_results.values.sum() + cooling_consumption_results.values.sum() + \
dhw_consumption_results.values.sum() + extra_electrical_consumption.values.sum())/1000
return outputs_energy, total_final_energy