diff --git a/bpfin/financials/scenario.py b/bpfin/financials/scenario.py index c606285b081660a6db2d696bcada46cbd584d331..92a301966d3be4e76b7ee458fdbe7409607c7b60 100644 --- a/bpfin/financials/scenario.py +++ b/bpfin/financials/scenario.py @@ -8,15 +8,9 @@ from bpfin.utilbills.bill_lib import form_bill_year, annualizing_projection class Scenario(): - def __init__(self, - analysis_date, - commission_date, - construction_cost, - bill_overview, - prior_annual_bill_table, - other_debt_service, - prior_income_statement_table, - prior_balance_sheet_table, + def __init__(self, analysis_date, commission_date, construction_cost, + bill_overview, prior_annual_bill_table, other_debt_service, + prior_income_statement_table, prior_balance_sheet_table, loan_input_list): """ other_debt_service (dict): dictionary of debt service values per year @@ -28,8 +22,10 @@ class Scenario(): self.prior_annual_bill_table = copy.deepcopy(prior_annual_bill_table) self.other_debt_service = copy.deepcopy(other_debt_service) - self.prior_income_statement_table = copy.deepcopy(prior_income_statement_table) - self.prior_balance_sheet_table = copy.deepcopy(prior_balance_sheet_table) + self.prior_income_statement_table = copy.deepcopy( + prior_income_statement_table) + self.prior_balance_sheet_table = copy.deepcopy( + prior_balance_sheet_table) self.post_income_statement_table = None self.post_balance_sheet_table = None @@ -38,16 +34,11 @@ class Scenario(): bill_overview=copy.deepcopy(bill_overview), prior_annual_bill_table=copy.deepcopy(prior_annual_bill_table), analysis_date=copy.deepcopy(analysis_date), - commissioning_date=copy.deepcopy(commission_date) - ) + commissioning_date=copy.deepcopy(commission_date)) self.scheduled_loan_list = None - def prelim_anlaysis(self, - prior_month_bill, - percent_saving_dict, - full_saving_dict, - growth_rate_flag, - req_dscr, + def prelim_anlaysis(self, prior_month_bill, percent_saving_dict, + full_saving_dict, growth_rate_flag, req_dscr, customer_preference): """ growth_rate_flag (float): indicating assumed growth rate, -2.0 == cagr, -1.0 == historical average @@ -61,22 +52,32 @@ class Scenario(): full_saving_dict=full_saving_dict) # generate post_saving income_statement_table object - post_annual_bill_table = copy.deepcopy(self.saving_overview.get_post_annual_bill_table()) - post_income_statement_table = copy.deepcopy(self.prior_income_statement_table) - post_income_statement_table.project(growth_rate_flag, self.analysis_date, post_annual_bill_table) + post_annual_bill_table = copy.deepcopy( + self.saving_overview.get_post_annual_bill_table()) + post_income_statement_table = copy.deepcopy( + self.prior_income_statement_table) + post_income_statement_table.project( + growth_rate_flag, self.analysis_date, post_annual_bill_table) self.post_income_statement_table = post_income_statement_table # generate post_saving balance_sheet_table object - post_saving_noi_dict = copy.deepcopy(self.post_income_statement_table.get_noi_dict()) - post_balance_sheet_table = copy.deepcopy(self.prior_balance_sheet_table) + post_saving_noi_dict = copy.deepcopy( + self.post_income_statement_table.get_noi_dict()) + post_balance_sheet_table = copy.deepcopy( + self.prior_balance_sheet_table) post_balance_sheet_table.project_balance_sheet( self.analysis_date, self.other_debt_service, post_saving_noi_dict) self.post_balance_sheet_table = post_balance_sheet_table # allocate loan and get loan schedules - first_year_saving = copy.deepcopy(self.saving_overview.get_total_first_year_saving()) - first_year_noi = copy.deepcopy(self.post_income_statement_table.get_first_year_noi(self.commission_date)) - first_year_cash = copy.deepcopy(self.post_balance_sheet_table.get_first_year_cash(self.commission_date)) + first_year_saving = copy.deepcopy( + self.saving_overview.get_total_first_year_saving()) + first_year_noi = copy.deepcopy( + self.post_income_statement_table.get_first_year_noi( + self.commission_date)) + first_year_cash = copy.deepcopy( + self.post_balance_sheet_table.get_first_year_cash( + self.commission_date)) # print('first year =', first_year_saving, first_year_noi, first_year_cash) # print(self.loan_list.loan_list[0].institute) @@ -93,14 +94,16 @@ class Scenario(): def get_post_energy_bill(self): proforma_year = form_bill_year(self.analysis_date['proforma_start'], self.analysis_date['proforma_duration']) - post_annual_bill_table = copy.deepcopy(self.saving_overview.get_post_annual_bill_table()) + post_annual_bill_table = copy.deepcopy( + self.saving_overview.get_post_annual_bill_table()) utility_type_list = ['electricity', 'gas', 'oil', 'water'] post_energy_bill = {} for year in proforma_year: current_total_energy_bill = 0 for utility_type in utility_type_list: - current_total_energy_bill += post_annual_bill_table[utility_type][year] + current_total_energy_bill += post_annual_bill_table[ + utility_type][year] post_energy_bill[year] = current_total_energy_bill return post_energy_bill @@ -133,17 +136,51 @@ class Scenario(): graph_dict = {} proforma_bill = self.get_post_energy_bill() annual_debt_service = self.get_annual_debt_service() - prior_annual_bill = self.prior_income_statement_table.get_total_energy_dict() + prior_annual_bill = self.prior_income_statement_table.get_total_energy_dict( + ) net_saving_dict = {} print(prior_annual_bill) for year in prior_annual_bill: - net_saving_dict[year] = prior_annual_bill[year] - proforma_bill[year] - annual_debt_service[year] + net_saving_dict[ + year] = prior_annual_bill[year] - proforma_bill[year] - annual_debt_service[year] graph_dict = { 'energy_expenses': proforma_bill, 'total_loan': annual_debt_service, - 'net_savings': net_saving_dict} + 'net_savings': net_saving_dict + } return graph_dict + def get_dscr(self, analysis_date, noi_dict, cash_dict, savings_dict, + debt_dict): + + pro_forma_years = form_bill_year(analysis_date['proforma_start'], + analysis_date['proforma_duration']) + + dscr_dict = {'noi_dict': {}, 'cash_dict': {}, 'savings_dict': {}} + + for year in pro_forma_years: + noi_temp_dict = {} + cash_temp_dict = {} + savings_temp_dict = {} + if year in debt_dict and debt_dict[year] != 0: + if year in noi_dict: + noi_temp_dict[year] = noi_dict[year] / debt_dict[ + year] + noi_temp_dict[year] = -1 + if year in cash_dict: + cash_temp_dict[year] = cash_dict[year] / debt_dict[ + year] + noi_temp_dict[year] = -1 + if year in savings_dict: + savings_temp_dict[year] = savings_dict[ + year] / debt_dict[year] + noi_temp_dict[year] = -1 + dscr_dict['noi_dict'] = noi_temp_dict + dscr_dict['cash_dict'] = cash_temp_dict + dscr_dict['savings_dict'] = savings_temp_dict + + return dscr_dict + # ***** ugly test that can be a guide for front end dev ***** # growth_toggle = 0.01