2023-03-23 13:31:36 -04:00
|
|
|
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'
|
2023-05-02 12:39:51 -04:00
|
|
|
array = [None] * 12
|
2023-03-23 13:31:36 -04:00
|
|
|
for building in self._city.buildings:
|
2023-03-24 11:47:09 -04:00
|
|
|
if cte.MONTH in building.heating.keys():
|
|
|
|
heating_results = building.heating[cte.MONTH].rename(columns={cte.INSEL_MEB: f'{building.name} heating Wh'})
|
2023-05-02 12:39:51 -04:00
|
|
|
else:
|
2023-05-18 11:33:14 -04:00
|
|
|
heating_results = pd.DataFrame(array, columns=[f'{building.name} heating demand Wh'])
|
2023-05-02 12:39:51 -04:00
|
|
|
if cte.MONTH in building.cooling.keys():
|
2023-03-24 11:47:09 -04:00
|
|
|
cooling_results = building.cooling[cte.MONTH].rename(columns={cte.INSEL_MEB: f'{building.name} cooling Wh'})
|
2023-05-02 12:39:51 -04:00
|
|
|
else:
|
2023-05-18 11:33:14 -04:00
|
|
|
cooling_results = pd.DataFrame(array, columns=[f'{building.name} cooling demand Wh'])
|
2023-05-02 12:39:51 -04:00
|
|
|
if cte.MONTH in building.lighting_electrical_demand.keys():
|
2023-03-24 11:47:09 -04:00
|
|
|
lighting_results = building.lighting_electrical_demand[cte.MONTH]\
|
|
|
|
.rename(columns={cte.INSEL_MEB: f'{building.name} lighting electrical demand Wh'})
|
2023-05-02 12:39:51 -04:00
|
|
|
else:
|
|
|
|
lighting_results = pd.DataFrame(array, columns=[f'{building.name} lighting electrical demand Wh'])
|
|
|
|
if cte.MONTH in building.appliances_electrical_demand.keys():
|
2023-05-18 11:36:45 -04:00
|
|
|
appliances_results = building.appliances_electrical_demand[cte.MONTH]\
|
2023-03-24 11:47:09 -04:00
|
|
|
.rename(columns={cte.INSEL_MEB: f'{building.name} appliances electrical demand Wh'})
|
2023-05-02 12:39:51 -04:00
|
|
|
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():
|
2023-03-24 11:47:09 -04:00
|
|
|
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'])
|
2023-05-18 11:33:14 -04:00
|
|
|
|
|
|
|
if cte.MONTH in building.heating_consumption.keys():
|
2023-05-18 11:36:45 -04:00
|
|
|
heating_consumption_results = pd.DataFrame(building.heating_consumption[cte.MONTH],
|
|
|
|
columns=[f'{building.name} heating consumption Wh'])
|
2023-05-18 11:33:14 -04:00
|
|
|
else:
|
|
|
|
heating_consumption_results = pd.DataFrame(array, columns=[f'{building.name} heating consumption Wh'])
|
|
|
|
if cte.MONTH in building.cooling_consumption.keys():
|
2023-05-18 11:36:45 -04:00
|
|
|
cooling_consumption_results = pd.DataFrame(building.cooling_consumption[cte.MONTH],
|
|
|
|
columns=[f'{building.name} cooling consumption Wh'])
|
2023-05-18 11:33:14 -04:00
|
|
|
else:
|
|
|
|
cooling_consumption_results = pd.DataFrame(array, columns=[f'{building.name} cooling consumption Wh'])
|
|
|
|
if cte.MONTH in building.domestic_hot_water_consumption.keys():
|
2023-05-18 11:36:45 -04:00
|
|
|
dhw_consumption_results = pd.DataFrame(building.domestic_hot_water_consumption[cte.MONTH],
|
|
|
|
columns=[f'{building.name} domestic hot water consumption Wh'])
|
2023-05-18 11:33:14 -04:00
|
|
|
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 = building.heating_peak_load[cte.MONTH]
|
|
|
|
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 = building.cooling_peak_load[cte.MONTH]
|
|
|
|
else:
|
|
|
|
cooling_peak_load_results = pd.DataFrame(array, columns=[f'{building.name} cooling peak load W'])
|
|
|
|
|
2023-03-23 13:31:36 -04:00
|
|
|
if print_results is None:
|
|
|
|
print_results = heating_results
|
|
|
|
else:
|
|
|
|
print_results = pd.concat([print_results, heating_results], axis='columns')
|
2023-03-23 13:49:41 -04:00
|
|
|
print_results = pd.concat([print_results,
|
|
|
|
cooling_results,
|
|
|
|
lighting_results,
|
|
|
|
appliances_results,
|
2023-05-18 11:33:14 -04:00
|
|
|
dhw_results,
|
|
|
|
heating_consumption_results,
|
|
|
|
cooling_consumption_results,
|
|
|
|
dhw_consumption_results,
|
|
|
|
heating_peak_load_results,
|
|
|
|
cooling_peak_load_results], axis='columns')
|
2023-03-23 13:31:36 -04:00
|
|
|
file += '\n'
|
2023-03-24 11:47:09 -04:00
|
|
|
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'heated_volume: {0.85 * building.volume}\n'
|
|
|
|
file += f'volume: {building.volume}\n'
|
2023-03-23 13:31:36 -04:00
|
|
|
|
|
|
|
full_path_results = Path(self._path / 'demand.csv').resolve()
|
2023-03-24 11:47:09 -04:00
|
|
|
print_results.to_csv(full_path_results, na_rep='null')
|
2023-03-23 13:31:36 -04:00
|
|
|
full_path_metadata = Path(self._path / 'metadata.csv').resolve()
|
|
|
|
with open(full_path_metadata, 'w') as metadata_file:
|
|
|
|
metadata_file.write(file)
|