diff --git a/bpfin/back_end_call/back_end_prelim.py b/bpfin/back_end_call/back_end_prelim.py index a22d149184aaa85389dea89c4104da921fb2264e..0d22179d0f6d69d98702e547de1716cd6a003851 100644 --- a/bpfin/back_end_call/back_end_prelim.py +++ b/bpfin/back_end_call/back_end_prelim.py @@ -5,13 +5,15 @@ from bpfin.financials.financial_balance import Balance_Sheet_Table from bpfin.financials.scenario import Scenario from bpfin.back_end_call.back_end_inputs import monthly_bill, annual_bill +# delete following imports when online +# from bpfin.tests.testdata import feature_data as db +# import pprint -def prelim_scenario(raw_bill_table, raw_annual_bill_table, - raw_income_input, growth_rate_flag, - raw_liability_input, raw_cash_balance, - raw_loan_input_list, - analysis_date, commission_date, construction_cost, - percent_saving_dict, full_saving_dict, + +def prelim_scenario(raw_bill_table, raw_annual_bill_table, raw_income_input, + growth_rate_flag, raw_liability_input, raw_cash_balance, + raw_loan_input_list, analysis_date, commission_date, + construction_cost, percent_saving_dict, full_saving_dict, req_dscr, customer_preference): """ Conduct Preliminary Financial Analysis @@ -113,7 +115,9 @@ def prelim_scenario(raw_bill_table, raw_annual_bill_table, raw_bill_table, raw_annual_bill_table, analysis_date ) - prior_income_table = Income_Statement_Table(raw_income_input, prior_annual_bill_table, analysis_date) + prior_income_table = Income_Statement_Table( + raw_income_input, prior_annual_bill_table, analysis_date + ) cash_balance_dict = cash_balance(analysis_date, raw_cash_balance) liability_dict = final_liability_dict(analysis_date, raw_liability_input) @@ -127,9 +131,17 @@ def prelim_scenario(raw_bill_table, raw_annual_bill_table, prior_income_table.project(growth_rate_flag, prior_annual_bill_table) - prior_bs = Balance_Sheet_Table(cash_balance_dict, liability_dict, prior_income_table.get_noi_dict()) + prior_bs = Balance_Sheet_Table( + cash_balance_dict, + liability_dict, + prior_income_table.get_noi_dict() + ) - prior_bs.project_balance_sheet(analysis_date, liability_dict, prior_income_table.get_noi_dict()) + prior_bs.project_balance_sheet( + analysis_date, + liability_dict, + prior_income_table.get_noi_dict() + ) scenario_ob = Scenario( analysis_date=analysis_date, @@ -153,7 +165,6 @@ def prelim_scenario(raw_bill_table, raw_annual_bill_table, # Define raw_annual_bill_table as a "get" of prior_bill # Define raw_bill_table as a "get" of prior_bill # Delete prior_annual_bill_table - # the following is front-end formatting building: loan_showcase_list = [ 'Lender', @@ -184,6 +195,10 @@ def prelim_scenario(raw_bill_table, raw_annual_bill_table, return ( scenario_ob.get_economics(), scenario_ob.get_graph_dict(), + scenario_ob.get_prior_income_statement(), + scenario_ob.get_prior_balance_sheet_statement(), + scenario_ob.get_post_income_statement(), + scenario_ob.get_post_balance_sheet_statement(), budget_plot, loan_summary, downpayment @@ -194,7 +209,8 @@ def prelim_scenario(raw_bill_table, raw_annual_bill_table, # from bpfin.tests.testdata import feature_data as db # import pprint -# print(prelim_scenario( +# print( +# prelim_scenario( # raw_bill_table=db.raw_bill_table, # raw_annual_bill_table=db.raw_annual_bill_table, # raw_income_input=db.raw_income_input, @@ -209,7 +225,8 @@ def prelim_scenario(raw_bill_table, raw_annual_bill_table, # full_saving_dict=db.full_saving_dict, # req_dscr=db.req_dscr, # customer_preference=db.customer_preference -# )) +# ) +# ) # pp = pprint.PrettyPrinter(width=120, indent=4, compact=True) # pp.pprint(prior_income_statement_result) diff --git a/bpfin/financials/financial_balance.py b/bpfin/financials/financial_balance.py index ca3fad21c74137e8d619a53748dca757d92a0089..c7ab5e720890811471f3cbcabbdf02738b0e1972 100644 --- a/bpfin/financials/financial_balance.py +++ b/bpfin/financials/financial_balance.py @@ -183,9 +183,26 @@ class Balance_Sheet_Table(): dictionary: cash for each year in balance sheet table. Key is year """ cash_dict = {} + if self.bs_table: + for current_balance_sheet in self.bs_table: + cash_dict[current_balance_sheet.year] = { + 'Balance': current_balance_sheet.cash, + } + return cash_dict + # else: + # return {} + + def get_simple_cash_dict(self): + """ + HACK: Implemented two of these functions will combine into one once standard formatting is decided. + Get a dictionary of cash. + Return: + dictionary: cash for each year in balance sheet table. Key is year + """ + cash_dict = {} if self.bs_table: for current_balance_sheet in self.bs_table: cash_dict[current_balance_sheet.year] = current_balance_sheet.cash return cash_dict - else: - return {} + # else: + # return {} diff --git a/bpfin/financials/scenario.py b/bpfin/financials/scenario.py index b9f6d3817890ec7642c403c643ba4b18295fbf3a..ecc7f5777ac39c53e903854b26d47be569b638a8 100644 --- a/bpfin/financials/scenario.py +++ b/bpfin/financials/scenario.py @@ -244,7 +244,7 @@ class Scenario(): noi_dscr = {2017: 1.17, 2018: 1.98, ...} """ noi_dict = copy.deepcopy(self.post_income_statement_table.get_noi_dict()) - cash_dict = copy.deepcopy(self.post_balance_sheet_table.get_cash_dict()) + cash_dict = copy.deepcopy(self.post_balance_sheet_table.get_simple_cash_dict()) debt_dict = set_dict_starting_year( copy.deepcopy(self.get_annual_debt_service()), self.commission_date.year + 1) @@ -287,6 +287,45 @@ class Scenario(): economics_overview['min_cash_dscr'] = min_none_list(dscr_dict['cash_dscr'].values()) return economics_overview + def get_statement(self, full_statement): + """This will get the income OR balance sheet statement in the required format.""" + result = [] + row = [] + row.append('Year') + for year in full_statement: + row.append(year) + result.append(row) + + analysis_year = result[0][1] + + for field in full_statement[analysis_year]: + if field.lower() != 'year': + row = [] + row.append(field) + for year in result[0]: + if year != 'Year': + row.append(full_statement[year][field]) + result.append(row) + return result + + def get_prior_income_statement(self): + """Fetch full income statement table prior to retrofit.""" + prior_full_income_statement = self.prior_income_statement_table.get_full_income_table() + return self.get_statement(prior_full_income_statement) + + def get_post_income_statement(self): + """Fetch full income statement table post to retrofit.""" + post_full_income_statement = self.post_income_statement_table.get_full_income_table() + return self.get_statement(post_full_income_statement) + + def get_prior_balance_sheet_statement(self): + prior_full_balance_statement = self.prior_balance_sheet_table.get_cash_dict() + return self.get_statement(prior_full_balance_statement) + + def get_post_balance_sheet_statement(self): + post_full_balance_statement = self.post_balance_sheet_table.get_cash_dict() + return self.get_statement(post_full_balance_statement) + def get_financing_plan(self): """ Get Financing Plan for the scenario, showcase amount borrowed from each lender including self-finance diff --git a/bpfin/tests/test_financials/test_scenario.py b/bpfin/tests/test_financials/test_scenario.py new file mode 100644 index 0000000000000000000000000000000000000000..e9cf330417981f7c0b04aa617fcf40204187530c --- /dev/null +++ b/bpfin/tests/test_financials/test_scenario.py @@ -0,0 +1,47 @@ +from bpfin.financials.scenario import Scenario +from bpfin.tests.testdata import feature_data as db +from bpfin.tests.testdata import sample_data as sd +# from bpfin.lib.back_end_call import monthly_bill +from bpfin.financials.liability import final_liability_dict +from bpfin.financials.balance_sheet_projection import balance_sheet_projection +from bpfin.financials.cash_balance import cash_balance +from bpfin.financials.financial_income import Income_Statement_Table +from bpfin.financials.financial_balance import Balance_Sheet_Table + +growth_toggle = -2.0 + +cash_balance_test = cash_balance(db.analysis_date, db.raw_cash_balance) +liability_test = final_liability_dict(db.analysis_date, db.raw_liability_input) + +prior_IS_table = Income_Statement_Table(db.raw_income_input, + db.prior_annual_bill, db.analysis_date) +prior_IS_table.project(growth_toggle, db.prior_annual_bill) +prior_BS_table = Balance_Sheet_Table(cash_balance_test, liability_test, + prior_IS_table.get_noi_dict()) +prior_BS_table.project_balance_sheet(db.analysis_date, db.liability_dictionary, + prior_IS_table.get_noi_dict()) + + +def test_scenario_object(): + """TODO: Test must be implemented correctly. Test cases must be added later. + """ + + scenario_object_test = Scenario( + analysis_date=db.analysis_date, + commission_date=db.commission_date, + construction_cost=db.cost_estimation, + manual_input_dict=db.manual_input_dict, + prior_annual_bill_table=db.prior_annual_bill, + prior_income_statement_table=prior_IS_table, + other_debt_service=db.liability_dictionary, + growth_rate_flag=growth_toggle, + prior_balance_sheet_table=prior_BS_table, + loan_input_list=db.raw_loan_input_list) + + scenario_object_test.prelim_analysis( + sd.prior_month_bill, db.percent_saving_dict, db.full_saving_dict, + db.req_dscr, db.customer_preference) + + print(scenario_object_test.get_post_balance_sheet_statement()) + + assert 1 == 1 diff --git a/bpfin/tests/testdata/sample_data.py b/bpfin/tests/testdata/sample_data.py index 8f15a0e75bf0d1a9e5ac114657b8243f99c82f9f..434f969a4cb1bc260068ac7e85f0409607b0654b 100644 --- a/bpfin/tests/testdata/sample_data.py +++ b/bpfin/tests/testdata/sample_data.py @@ -1800,9 +1800,9 @@ post_bill_rough = { prior_month_bill = { 'electricity': prior_bill_rough, - 'gas': None, - 'oil': None, - 'water': None, + 'gas': prior_bill_rough, + 'oil': prior_bill_rough, + 'water': prior_bill_rough, } percent_saving_dict = {