77 lines
3.4 KiB
Python
77 lines
3.4 KiB
Python
"""
|
|
Costs Workflow
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
Copyright © 2022 Project Author Pilar Monsalvete Álvarez de Uribarri pilar.monsalvete@concordia.ca
|
|
"""
|
|
|
|
import glob
|
|
import os
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
from hub.imports.construction_factory import ConstructionFactory
|
|
from hub.helpers.dictionaries import Dictionaries
|
|
from hub.hub_logger import logger
|
|
from hub.imports.geometry_factory import GeometryFactory
|
|
from hub.catalog_factories.costs_catalog_factory import CostCatalogFactory
|
|
|
|
from life_cycle_costs import LifeCycleCosts
|
|
|
|
|
|
def _search_archetype(costs_catalog, building_function):
|
|
costs_archetypes = costs_catalog.entries('archetypes').archetypes
|
|
for building_archetype in costs_archetypes:
|
|
if str(building_function) == str(building_archetype.function):
|
|
return building_archetype
|
|
raise KeyError('archetype not found')
|
|
|
|
|
|
file_path = (Path(__file__).parent.parent / 'costs_workflow' / 'input_files' / 'selected_building_2864.geojson')
|
|
out_path = (Path(__file__).parent.parent / 'costs_workflow' / 'out_files')
|
|
files = glob.glob(f'{out_path}/*')
|
|
for file in files:
|
|
if file != '.gitignore':
|
|
os.remove(file)
|
|
|
|
print('[simulation start]')
|
|
city = GeometryFactory('geojson',
|
|
path=file_path,
|
|
height_field='heightmax',
|
|
year_of_construction_field='ANNEE_CONS',
|
|
name_field='OBJECTID_12',
|
|
function_field='CODE_UTILI',
|
|
function_to_hub=Dictionaries().montreal_function_to_hub_function).city
|
|
print(f'city created from {file_path}')
|
|
ConstructionFactory('nrcan', city).enrich()
|
|
print('enrich constructions... done')
|
|
number_of_years = 30
|
|
consumer_price_index = 0.04
|
|
discount_rate = 0.03
|
|
retrofitting_scenarios = [0, 1, 2, 3]
|
|
catalog = CostCatalogFactory('montreal_custom').catalog
|
|
|
|
for building in city.buildings:
|
|
try:
|
|
function = Dictionaries().hub_function_to_montreal_custom_costs_function[building.function]
|
|
archetype = _search_archetype(catalog, function)
|
|
except KeyError:
|
|
logger.error(f'Building {building.name} has unknown costs archetype for building function: '
|
|
f'{building.function}\n')
|
|
sys.stderr.write(f'Building {building.name} has unknown costs archetype for building function: '
|
|
f'{building.function}\n')
|
|
continue
|
|
|
|
for retrofitting_scenario in retrofitting_scenarios:
|
|
lcc = LifeCycleCosts(building, archetype, number_of_years, consumer_price_index,
|
|
discount_rate, retrofitting_scenario)
|
|
total_capital_costs = lcc.calculate_capital_costs()
|
|
print(f'total capital costs scenario {retrofitting_scenario} are {total_capital_costs}')
|
|
end_of_life_costs = lcc.calculate_end_of_life_costs()
|
|
print(f'end_of_life_costs scenario {retrofitting_scenario} are {end_of_life_costs}')
|
|
total_operational_costs = lcc.calculate_total_operational_costs()
|
|
print(f'total_operational_costs scenario {retrofitting_scenario} are {total_operational_costs}')
|
|
total_maintenance_costs = lcc.calculate_total_maintenance_costs()
|
|
print(f'total_maintenance_costs scenario {retrofitting_scenario} are {total_maintenance_costs}')
|
|
life_cycle_costs = total_capital_costs + end_of_life_costs + total_operational_costs + total_maintenance_costs
|
|
print(f'life_cycle_costs scenario {retrofitting_scenario} are {life_cycle_costs}')
|