cost performance improvements

This commit is contained in:
Guille Gutierrez 2023-08-10 12:36:31 -04:00
parent d8c0644709
commit 62ae152ba7
3 changed files with 32 additions and 13 deletions

View File

@ -5,6 +5,8 @@ Copyright © 2023 Project Coder Guille Gutierrez guillermo.gutierrezmorote@conco
Code contributor Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca Code contributor Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
Code contributor Oriol Gavalda Torrellas oriol.gavalda@concordia.ca Code contributor Oriol Gavalda Torrellas oriol.gavalda@concordia.ca
""" """
import datetime
import pandas as pd import pandas as pd
import numpy_financial as npf import numpy_financial as npf
from hub.city_model_structure.building import Building from hub.city_model_structure.building import Building
@ -72,12 +74,22 @@ class Cost:
:return: DataFrame :return: DataFrame
""" """
results = pd.DataFrame() results = pd.DataFrame()
start = datetime.datetime.now()
global_capital_costs, global_capital_incomes = CapitalCosts(self._building, self._configuration).calculate() global_capital_costs, global_capital_incomes = CapitalCosts(self._building, self._configuration).calculate()
print(f'CapitalCosts: {datetime.datetime.now()-start}')
start = datetime.datetime.now()
global_end_of_life_costs = EndOfLifeCosts(self._building, self._configuration).calculate() global_end_of_life_costs = EndOfLifeCosts(self._building, self._configuration).calculate()
print(f'EndOfLifeCosts: {datetime.datetime.now() - start}')
start = datetime.datetime.now()
global_operational_costs = TotalOperationalCosts(self._building, self._configuration).calculate() global_operational_costs = TotalOperationalCosts(self._building, self._configuration).calculate()
print(f'TotalOperationalCosts: {datetime.datetime.now() - start}')
start = datetime.datetime.now()
global_maintenance_costs = TotalMaintenanceCosts(self._building, self._configuration).calculate() global_maintenance_costs = TotalMaintenanceCosts(self._building, self._configuration).calculate()
print(f'TotalMaintenanceCosts: {datetime.datetime.now() - start}')
start = datetime.datetime.now()
global_operational_incomes = TotalOperationalIncomes(self._building, self._configuration).calculate() global_operational_incomes = TotalOperationalIncomes(self._building, self._configuration).calculate()
print(f'OperationalIncomes: {datetime.datetime.now() - start}')
start = datetime.datetime.now()
df_capital_costs_skin = ( df_capital_costs_skin = (
global_capital_costs['B2010_opaque_walls'] + global_capital_costs['B2010_opaque_walls'] +
global_capital_costs['B2020_transparent'] + global_capital_costs['B2020_transparent'] +
@ -151,5 +163,5 @@ class Cost:
'global_maintenance_costs', 'global_maintenance_costs',
'global_operational_incomes' 'global_operational_incomes'
] ]
print(f'Dataframes: {datetime.datetime.now()-start}')
return results return results

View File

@ -28,22 +28,25 @@ class PeakLoad:
heating = 0 heating = 0
cooling = 0 cooling = 0
for system in self._building.energy_systems: for system in self._building.energy_systems:
for demand_type in system.demand_types: if cte.HEATING in system.demand_types:
if demand_type == cte.HEATING:
heating = 1 heating = 1
if demand_type == cte.COOLING: if cte.COOLING in system.demand_types:
cooling = 1 cooling = 1
if cte.MONTH in self._building.heating_peak_load.keys() and cte.MONTH in self._building.cooling_peak_load.keys(): if cte.MONTH in self._building.heating_peak_load.keys() and cte.MONTH in self._building.cooling_peak_load.keys():
peak_lighting = self._building.lighting_peak_load[cte.YEAR][0] peak_lighting = self._building.lighting_peak_load[cte.YEAR][0]
peak_appliances = self._building.appliances_peak_load[cte.YEAR][0] peak_appliances = self._building.appliances_peak_load[cte.YEAR][0]
monthly_electricity_peak = [0.9 * peak_lighting + 0.7 * peak_appliances] * 12 monthly_electricity_peak = [0.9 * peak_lighting + 0.7 * peak_appliances] * 12
conditioning_peak = [] conditioning_peak = max(self._building.heating_peak_load[cte.MONTH], self._building.cooling_peak_load[cte.MONTH])
for i, value in enumerate(self._building.heating_peak_load[cte.MONTH]): for i in range(len(conditioning_peak)):
if cooling * self._building.cooling_peak_load[cte.MONTH][i] > heating * value: if cooling == 1 and heating == 1:
conditioning_peak.append(cooling * self._building.cooling_peak_load[cte.MONTH][i]) conditioning_peak[i] = conditioning_peak[i]
continue
elif cooling == 0:
conditioning_peak[i] = self._building.heating_peak_load[cte.MONTH][i] * heating
else: else:
conditioning_peak.append(heating * value) conditioning_peak[i] = self._building.cooling_peak_load[cte.MONTH][i] * cooling
monthly_electricity_peak[i] += 0.8 * conditioning_peak[i] monthly_electricity_peak[i] += 0.8 * conditioning_peak[i]
electricity_peak_load_results = pd.DataFrame( electricity_peak_load_results = pd.DataFrame(
monthly_electricity_peak, monthly_electricity_peak,
columns=[f'electricity peak load W'] columns=[f'electricity peak load W']

View File

@ -42,14 +42,16 @@ class Initialize:
sra_file = str((output_path / f'{city.name}_sra.xml').resolve()) sra_file = str((output_path / f'{city.name}_sra.xml').resolve())
subprocess.run(['sra', sra_file], stdout=subprocess.DEVNULL) subprocess.run(['sra', sra_file], stdout=subprocess.DEVNULL)
ResultFactory('sra', city, output_path).enrich() ResultFactory('sra', city, output_path).enrich()
print(f'sra completed {datetime.datetime.now() - start}')
for building in city.buildings: for building in city.buildings:
building.energy_systems_archetype_name = 'system 1 gas pv' building.energy_systems_archetype_name = 'system 1 gas pv'
EnergySystemsFactory('montreal_custom', city).enrich() EnergySystemsFactory('montreal_custom', city).enrich()
print(f'energy systems completed {datetime.datetime.now() - start}')
EnergyBuildingsExportsFactory('insel_monthly_energy_balance', city, output_path).export() EnergyBuildingsExportsFactory('insel_monthly_energy_balance', city, output_path).export()
_insel_files = glob.glob(f'{output_path}/*.insel') _insel_files = glob.glob(f'{output_path}/*.insel')
for insel_file in _insel_files: for insel_file in _insel_files:
subprocess.run(['insel', str(insel_file)], stdout=subprocess.DEVNULL) subprocess.run(['insel', str(insel_file)], stdout=subprocess.DEVNULL)
print(f'insel completed {datetime.datetime.now() - start}')
ResultFactory('insel_monthly_energy_balance', city, output_path).enrich() ResultFactory('insel_monthly_energy_balance', city, output_path).enrich()
self._city = city self._city = city
print(f'init completed {datetime.datetime.now() - start}') print(f'init completed {datetime.datetime.now() - start}')
@ -61,7 +63,9 @@ class UnitTests(unittest.TestCase):
def test_current_status(self): def test_current_status(self):
for building in self.init.city.buildings: for building in self.init.city.buildings:
start = datetime.datetime.now()
result = Cost(building).life_cycle result = Cost(building).life_cycle
print(f'Cost calculation for building {building.name}: {datetime.datetime.now()-start}')
self.assertIsNotNone(result) self.assertIsNotNone(result)
self.assertEqual(0, result.values[0]) self.assertEqual(0, result.values[0])