diff --git a/bpfin/financials/financial_lib.py b/bpfin/financials/financial_lib.py index dcf1358f0a3c44ae22126431c0aeda00689ab205..d3ee319a9d6cabdb0351ecbfef13f04157a3f299 100644 --- a/bpfin/financials/financial_lib.py +++ b/bpfin/financials/financial_lib.py @@ -82,9 +82,17 @@ def organize_bill_overview(bill_overview, analysis_date): for i in range(4): if bill_dict[i + 1][1] is False: - average_bill_dict[i + 1] = float( - sum(bill_dict[i + 1][0][year] for year in bill_dict[i + 1][ - 0])) / len(bill_dict[i + 1][0]) + sum_bill = 0 + year_number = 0 + for year in bill_dict[i + 1][0]: + if bill_dict[i + 1][0][year] != 0: + sum_bill += bill_dict[i + 1][0][year] + year_number += 1 + if year_number != 0: + average_bill_dict[i + 1] = float(sum_bill) / year_number + else: + average_bill_dict[i + 1] = 0 + # average_bill_dict[i + 1] = float(sum(bill_dict[i + 1][0][year] for year in bill_dict[i + 1][0])) / len(bill_dict[i + 1][0]) for year in proforma_year: for i in range(4): @@ -92,6 +100,8 @@ def organize_bill_overview(bill_overview, analysis_date): pass else: bill_dict[i + 1][0][year] = average_bill_dict[i + 1] + if bill_dict[i + 1][0][year] == 0: + bill_dict[i + 1][0][year] = average_bill_dict[i + 1] bill_overview_organized = { 'electricity': bill_dict[1][0], 'gas': bill_dict[2][0], diff --git a/bpfin/financials/income_statement_form_hist.py b/bpfin/financials/income_statement_form_hist.py index 65ba995d5bca40702883dba1b5d4a53cedaba6f5..2cfa502dc5cba3b8ef4c8926708600e7c51bd475 100644 --- a/bpfin/financials/income_statement_form_hist.py +++ b/bpfin/financials/income_statement_form_hist.py @@ -41,12 +41,11 @@ def income_statement_character(income_statement_hist): return result_dict -def form_income_statement_hist(raw_income_input, bill_overview_organized, analysis_date): +def form_income_statement_hist(raw_income_input, bill_overview_organized): """ form income statement table with raw inputs from UI, and organized bill_overview. NO projection Args: raw_income_input (dictionary): dictionary of dictionary. raw inputs for income statement for available years bill_overview_organized (dictionary): dict of dict, 4 utility types, with blank charge filled with average - analysis_date (dictionary): proforma's starting date and the years of proforma Returns: Dictionary: dict of dict, full income statement for available years diff --git a/bpfin/financials/income_statement_next.py b/bpfin/financials/income_statement_next.py index d46c4ab597d2e33ac61936f4a18b92cb466225a5..7b153491eb7c8a740c6609e9c1a629abd2358f57 100644 --- a/bpfin/financials/income_statement_next.py +++ b/bpfin/financials/income_statement_next.py @@ -32,7 +32,6 @@ def income_statement_next(income_statement_hist, bill_overview_organized, growth income_next.assign_next(characters, bill_overview_organized) result_dict = fl.convert_income_statement_class(income_next) - print(result_dict) return result_dict # def income_statement_proj_input(income_statement_full, bill_overview_organized, growth_rate_flag): diff --git a/bpfin/tests/test_financials/test_income_statement_form_hist.py b/bpfin/tests/test_financials/test_income_statement_form_hist.py index 9114f18d001440f59571e01f043750bb624973ad..56803254f6c9cb2524531199f6765979b5a40878 100644 --- a/bpfin/tests/test_financials/test_income_statement_form_hist.py +++ b/bpfin/tests/test_financials/test_income_statement_form_hist.py @@ -19,10 +19,8 @@ def test_income_statement_character(): def test_form_income_statement_hist(): input_raw_income_input = db.raw_income_input input_bill_overview_organized = db.bill_overview_organized - input_analysis_date = db.analysis_date output_dict = db.income_statement_full result_dict = form_income_statement_hist( input_raw_income_input, - input_bill_overview_organized, - input_analysis_date) + input_bill_overview_organized) assert output_dict == result_dict diff --git a/bpfin/tests/testdata/sample_data.py b/bpfin/tests/testdata/sample_data.py index b7a8053a466e0858a5970b982fc59c5081c47844..a9650cb47d31081ecee73d4dd9c47cd9fc6ae0ba 100644 --- a/bpfin/tests/testdata/sample_data.py +++ b/bpfin/tests/testdata/sample_data.py @@ -90,7 +90,7 @@ annual_bill_electricity = { 2028: 43325.235463581725, 2029: 44211.298795796341, 2030: 45097.667796776521, 2031: 45986.665329650692, 2032: 46886.305428683903, 2033: 47806.578908870637, 2034: 48751.551094031129, 2035: 49722.255450564422, 2036: 50718.832984188753} -annual_bill_gas = {2015: 1020, 2016: 1220, 2017: 1520} +annual_bill_gas = {2014: 0, 2015: 1020, 2016: 1220, 2017: 1520} annual_bill_oil = {2015: 1010, 2016: 1210, 2017: 1510} annual_bill_water = {2015: 0, 2016: 0, 2017: 0}