costs_workflow/costs/cost.py

144 lines
5.8 KiB
Python
Raw Normal View History

2023-06-01 14:07:41 -04:00
"""
Cost module
"""
2023-07-17 15:18:32 -04:00
import hub.helpers.dictionaries
2023-06-01 14:07:41 -04:00
import pandas as pd
2023-07-14 16:18:33 -04:00
import numpy_financial as npf
from hub.city_model_structure.building import Building
2023-06-01 14:07:41 -04:00
2023-07-17 14:35:12 -04:00
from costs.configuration import Configuration
2023-07-14 16:18:33 -04:00
from costs import CapitalCosts, EndOfLifeCosts, TotalMaintenanceCosts, TotalOperationalCosts, TotalOperationalIncomes
2023-07-17 14:35:12 -04:00
from costs.constants import CURRENT_STATUS
2023-06-01 14:07:41 -04:00
class Cost:
"""
Cost class
"""
def __init__(self,
2023-07-14 16:18:33 -04:00
building: Building,
2023-06-01 14:07:41 -04:00
number_of_years=31,
percentage_credit=0,
interest_rate=0.04,
credit_years=15,
consumer_price_index=0.04,
electricity_peak_index=0.05,
electricity_price_index=0.05,
gas_price_index=0.05,
discount_rate=0.03,
retrofitting_year_construction=2020,
2023-07-14 16:18:33 -04:00
factories_handler='montreal_custom',
2023-07-17 15:18:32 -04:00
retrofit_scenario=CURRENT_STATUS,
dictionary=hub.helpers.dictionaries.Dictionaries().hub_function_to_montreal_custom_costs_function):
2023-07-14 16:18:33 -04:00
self._building = building
fuel_type = 0
if "gas" in building.energy_systems_archetype_name:
fuel_type = 1
2023-06-01 14:07:41 -04:00
self._configuration = Configuration(number_of_years,
percentage_credit,
interest_rate, credit_years,
consumer_price_index,
electricity_peak_index,
electricity_price_index,
gas_price_index,
discount_rate,
retrofitting_year_construction,
2023-07-14 16:18:33 -04:00
factories_handler,
retrofit_scenario,
2023-07-17 15:18:32 -04:00
fuel_type,
dictionary)
2023-07-14 16:18:33 -04:00
2023-07-14 16:39:47 -04:00
@property
def building(self) -> Building:
"""
Get current building.
"""
return self._building
@building.setter
def building(self, value: Building):
"""
Set current building.
"""
self._building = value
2023-07-14 16:18:33 -04:00
def _npv_from_list(self, list_cashflow):
return npf.npv(self._configuration.discount_rate, list_cashflow)
2023-06-01 14:07:41 -04:00
@property
def life_cycle(self) -> pd.DataFrame:
"""
Get complete life cycle costs
:return: DataFrame
"""
results = pd.DataFrame()
2023-07-14 16:18:33 -04:00
global_capital_costs, global_capital_incomes = CapitalCosts(self._building, self._configuration).calculate()
global_end_of_life_costs = EndOfLifeCosts(self._building, self._configuration).calculate()
global_operational_costs = TotalOperationalCosts(self._building, self._configuration).calculate()
global_maintenance_costs = TotalMaintenanceCosts(self._building, self._configuration).calculate()
global_operational_incomes = TotalOperationalIncomes(self._building, self._configuration).calculate()
df_capital_costs_skin = (
global_capital_costs['B2010_opaque_walls'] +
global_capital_costs['B2020_transparent'] +
global_capital_costs['B3010_opaque_roof'] +
global_capital_costs['B10_superstructure']
)
df_capital_costs_systems = (
global_capital_costs['D3020_heat_generating_systems'] +
global_capital_costs['D3030_cooling_generation_systems'] +
global_capital_costs['D3080_other_hvac_ahu'] +
global_capital_costs['D5020_lighting_and_branch_wiring'] +
global_capital_costs['D301010_photovoltaic_system']
)
df_end_of_life_costs = global_end_of_life_costs['End_of_life_costs']
df_operational_costs = (
global_operational_costs['Fixed_costs_electricity_peak'] +
global_operational_costs['Fixed_costs_electricity_monthly'] +
global_operational_costs['Fixed_costs_electricity_peak'] +
global_operational_costs['Fixed_costs_electricity_monthly'] +
global_operational_costs['Variable_costs_electricity'] +
global_operational_costs['Fixed_costs_gas'] +
global_operational_costs['Variable_costs_gas']
)
df_maintenance_costs = (
global_maintenance_costs['Heating_maintenance'] +
global_maintenance_costs['Cooling_maintenance'] +
global_maintenance_costs['PV_maintenance']
)
df_operational_incomes = global_operational_incomes['Incomes electricity']
df_capital_incomes = (
global_capital_incomes['Subsidies construction'] +
global_capital_incomes['Subsidies HVAC'] +
global_capital_incomes['Subsidies PV']
)
2023-07-17 16:36:39 -04:00
life_cycle_costs_capital_skin = self._npv_from_list(df_capital_costs_skin.values.tolist())
2023-07-14 16:18:33 -04:00
life_cycle_costs_capital_systems = self._npv_from_list(df_capital_costs_systems.values.tolist())
life_cycle_costs_end_of_life_costs = self._npv_from_list(df_end_of_life_costs.values.tolist())
life_cycle_operational_costs = self._npv_from_list(df_operational_costs.values.tolist())
life_cycle_maintenance_costs = self._npv_from_list(df_maintenance_costs.values.tolist())
life_cycle_operational_incomes = self._npv_from_list(df_operational_incomes.values.tolist())
life_cycle_capital_incomes = self._npv_from_list(df_capital_incomes.values.tolist())
results[f'Scenario {self._configuration.retrofit_scenario}'] = [
life_cycle_costs_capital_skin,
life_cycle_costs_capital_systems,
life_cycle_costs_end_of_life_costs,
life_cycle_operational_costs,
life_cycle_maintenance_costs,
life_cycle_operational_incomes,
life_cycle_capital_incomes
]
results.index = ['total_capital_costs_skin',
'total_capital_costs_systems',
'end_of_life_costs',
'total_operational_costs',
'total_maintenance_costs',
'operational_incomes',
'capital_incomes']
2023-06-01 14:07:41 -04:00
return results