From a0da78d353759b0ea6b11d26a5d6add19c1065c0 Mon Sep 17 00:00:00 2001 From: chenzheng06 Date: Mon, 24 Apr 2017 16:10:51 -0400 Subject: [PATCH 1/4] Create bill_backend_call file to store temperary functions call for backend --- bpfin/utilbills/bill_backend_call.py | 13 +++++++++++++ bpfin/utilbills/data_generation.py | 18 +++++++++--------- 2 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 bpfin/utilbills/bill_backend_call.py diff --git a/bpfin/utilbills/bill_backend_call.py b/bpfin/utilbills/bill_backend_call.py new file mode 100644 index 0000000..fb3f4b8 --- /dev/null +++ b/bpfin/utilbills/bill_backend_call.py @@ -0,0 +1,13 @@ +from bpfin.utilbills.bill_month_normalize_rough import bill_month_normalize_rough +from bpfin.utilbills.bill_prior_proj_rough import bill_prior_proj_rough +from bpfin.utilbills import bill_lib as bl +from bpfin.tests.testdata import sample_data as db + + +def bill_prior_proj_rough_annual(raw_bill, analysis_date, inflation_coeff_dict): + norm_bill = bill_month_normalize_rough(raw_bill) + prior_bill_electricity = bill_prior_proj_rough(norm_bill, raw_bill, analysis_date, inflation_coeff_dict) + annual_bill_electricity = bl.annualizing_projection( + prior_bill_electricity['date_to'], + prior_bill_electricity['charge']) + return annual_bill_electricity diff --git a/bpfin/utilbills/data_generation.py b/bpfin/utilbills/data_generation.py index a4acc79..d7219d8 100644 --- a/bpfin/utilbills/data_generation.py +++ b/bpfin/utilbills/data_generation.py @@ -1,13 +1,13 @@ -from bpfin.utilbills.bill_month_normalize_rough import bill_month_normalize_rough -from bpfin.utilbills.bill_prior_proj_rough import bill_prior_proj_rough -from bpfin.utilbills import bill_lib as bl -from bpfin.tests.testdata import sample_data as db +# from bpfin.utilbills.bill_month_normalize_rough import bill_month_normalize_rough +# from bpfin.utilbills.bill_prior_proj_rough import bill_prior_proj_rough +# from bpfin.utilbills import bill_lib as bl +# from bpfin.tests.testdata import sample_data as db -raw_bill = db.raw_bill -norm_bill = bill_month_normalize_rough(raw_bill) -prior_bill_electricity = bill_prior_proj_rough(norm_bill, raw_bill, db.analysis_date, db.inflation_coeff_dict) -annual_bill_electricity = bl.annualizing_projection(prior_bill_electricity['date_to'], prior_bill_electricity['charge']) +# raw_bill = db.raw_bill +# norm_bill = bill_month_normalize_rough(raw_bill) +# prior_bill_electricity = bill_prior_proj_rough(norm_bill, raw_bill, db.analysis_date, db.inflation_coeff_dict) +# annual_bill_electricity = bl.annualizing_projection(prior_bill_electricity['date_to'], prior_bill_electricity['charge']) -print(annual_bill_electricity) +# print(annual_bill_electricity) -- GitLab From ac09b746c6334e5a7e488406706b2ffcbea8f8a5 Mon Sep 17 00:00:00 2001 From: chenzheng06 Date: Mon, 24 Apr 2017 16:14:02 -0400 Subject: [PATCH 2/4] Replace ''' in comments with """ --- bpfin/financials/financial_lib.py | 8 ++++---- bpfin/financials/income_statement_form_hist.py | 8 ++++---- bpfin/financials/income_statement_next.py | 8 ++++---- bpfin/lib/other.py | 8 ++++---- bpfin/utilbills/bill_lib.py | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/bpfin/financials/financial_lib.py b/bpfin/financials/financial_lib.py index a72c3c1..dcf1358 100644 --- a/bpfin/financials/financial_lib.py +++ b/bpfin/financials/financial_lib.py @@ -7,7 +7,7 @@ from bpfin.tests.testdata import sample_data as db def income_statement_single_year(year, income_input, bill_overview): - '''calculate income statement for one single year, with inputs from UI and energy bill overview + """calculate income statement for one single year, with inputs from UI and energy bill overview Args: year (int): the year of this income statement @@ -19,7 +19,7 @@ def income_statement_single_year(year, income_input, bill_overview): Description Sample: income_input = {revenue': 100000, 'utility_expense': 60000,'non_utility_expense': 3000} bill_overview = {'electricity': electricity_bill, 'oil': oil_bill, 'gas': gas_bill, 'water': water_bill} - ''' + """ revenue = income_input['revenue'] utility_expense = income_input['utility_expense'] non_utility_expense = income_input['non_utility_expense'] @@ -60,7 +60,7 @@ def income_statement_single_year(year, income_input, bill_overview): def organize_bill_overview(bill_overview, analysis_date): - '''take bill_overview as inputs, fill in the blank annual bill with average numbers + """take bill_overview as inputs, fill in the blank annual bill with average numbers Args: bill_overview (dictionary): bill_overview from UI, with blank cells, for 4 utility_types @@ -70,7 +70,7 @@ def organize_bill_overview(bill_overview, analysis_date): Description: analysis_date: {'proforma_start': datetime.date, 'proforma_duration': int} - ''' + """ proforma_year = bl.form_bill_year(analysis_date['proforma_start'], analysis_date['proforma_duration']) bill_dict = {} diff --git a/bpfin/financials/income_statement_form_hist.py b/bpfin/financials/income_statement_form_hist.py index 019ecc5..401d66b 100644 --- a/bpfin/financials/income_statement_form_hist.py +++ b/bpfin/financials/income_statement_form_hist.py @@ -3,7 +3,7 @@ from bpfin.lib import other as lib def income_statement_character(income_statement_hist): - '''Determine annual growth rate, other_utility_percentage, non_utility_expense_percentage + """Determine annual growth rate, other_utility_percentage, non_utility_expense_percentage Args: income_statement_hist (dictionary): full income statement, with all items filled, for available years Return: @@ -12,7 +12,7 @@ def income_statement_character(income_statement_hist): Description: income_statement_hist = {2014:{'revenue': 100000, ... ,'noi':37000}, 2015:{}, 2016:{}} output = {'cagr': 2.45, 'other_utility_percentage': 20.4%, 'non_utility_expense_percentage': 43.5%, ..} - ''' + """ sorted_income_hist_year = sorted(income_statement_hist) start_year = sorted_income_hist_year[0] end_year = sorted_income_hist_year[-1] @@ -41,7 +41,7 @@ def income_statement_character(income_statement_hist): def form_income_statement_hist(raw_income_input, bill_overview_organized, analysis_date): - ''' form income statement table with raw inputs from UI, and organized bill_overview. NO projection + """ 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 @@ -53,7 +53,7 @@ def form_income_statement_hist(raw_income_input, bill_overview_organized, analys raw_income_input = {2014: {'revenue': 90000, 'utility_expense': 55000, 'non_utility_expense': 3500}, 2015:{},} bill_overview_organized = {'electricity':{2012: 100, 2013: 120, ...}, 'gas':{2012:100,2013:130...},...} Output = {2014: {'year': 2014, 'revenue': ...}, 2015:{...}, 2016:{...}} - ''' + """ income_statement_full = {} for year in sorted(raw_income_input): income_statement_full[year] = fl.income_statement_single_year( diff --git a/bpfin/financials/income_statement_next.py b/bpfin/financials/income_statement_next.py index 60b42bc..d46c4ab 100644 --- a/bpfin/financials/income_statement_next.py +++ b/bpfin/financials/income_statement_next.py @@ -6,7 +6,7 @@ from bpfin.financials.income_statement_form_hist import income_statement_charact def income_statement_next(income_statement_hist, bill_overview_organized, growth_rate_flag): - '''Project income statement for UI input. inputs are whatever bill and financial statements are available + """Project income statement for UI input. inputs are whatever bill and financial statements are available Args: income_statement_hist (dictionary): historical income statement, with all items filled, for available years bill_overview_organized (dictionary): annual bills for 4 utility types, with blank cells filled @@ -14,7 +14,7 @@ def income_statement_next(income_statement_hist, bill_overview_organized, growth growth_rate_flag (float): indicating assumed growth rate, -2.0 == cagr, -1.0 == historical average Returns: dictionary: 1 year full income statement, with itmes calculated. - ''' + """ characters = income_statement_character(income_statement_hist) income_next = fl.Income_Statement() @@ -36,7 +36,7 @@ def income_statement_next(income_statement_hist, bill_overview_organized, growth return result_dict # def income_statement_proj_input(income_statement_full, bill_overview_organized, growth_rate_flag): -# '''Project income statement for UI input. inputs are whatever bill and financial statements are available +# """Project income statement for UI input. inputs are whatever bill and financial statements are available # Args: # income_statement_full (dictionary) # bill_overview_organized (dictionary): bill_overview from UI, with blank cells, for 4 utility_types @@ -44,7 +44,7 @@ def income_statement_next(income_statement_hist, bill_overview_organized, growth # growth_rate_flag (float) # Returns: # dictionary: -# ''' +# """ # # proforma_year = bl.form_bill_year(analysis_date['proforma_start'], analysis_date['proforma_duration']) # characters = income_statement_character(income_statement_full) # cagr = characters['cagr'] diff --git a/bpfin/lib/other.py b/bpfin/lib/other.py index 846a522..415d57e 100644 --- a/bpfin/lib/other.py +++ b/bpfin/lib/other.py @@ -317,14 +317,14 @@ def average(list1): def cal_cagr(start_value, end_value, n): - ''' Calculate compound anual growth rate + """ Calculate compound anual growth rate Args: start_value (float): first year value nd_value (float): last year value n (int): first year - last year Return: float: anual growth rate - ''' + """ if start_value != 0: cagr = (end_value / start_value) ** (1 / n) - 1 else: @@ -362,13 +362,13 @@ def monthly_average(daily, matrix): # # oil price calculation # def cal_oil_price(oilcharge, oiluse): -# '''calculate oil price +# """calculate oil price # Args: # oilcharge (list): list of charges, float values, from raw bill # oiluse (list): list of usage, float values, from raw bill # Return: # list: 12 elements, average price for oil -# ''' +# """ # if sum(oilcharge) == 0 or pd.isnull(sum(oilcharge)) == 1: # overall_price = 0 # else: diff --git a/bpfin/utilbills/bill_lib.py b/bpfin/utilbills/bill_lib.py index 9411a12..7268b7b 100644 --- a/bpfin/utilbills/bill_lib.py +++ b/bpfin/utilbills/bill_lib.py @@ -227,13 +227,13 @@ def occupancy_final_list(occupancy_rate_list): # oil price calculation def cal_oil_price(oilcharge, oiluse): - '''calculate oil price + """calculate oil price Args: oilcharge (list): list of charges, float values, from raw bill oiluse (list): list of usage, float values, from raw bill Return: list: 12 elements, average price for oil - ''' + """ if sum(oilcharge) == 0 or pd.isnull(sum(oilcharge)) == 1: overall_price = 0 else: -- GitLab From b3dc2a32532edc799c4de2a85ff1933bcbd1ef56 Mon Sep 17 00:00:00 2001 From: chenzheng06 Date: Mon, 24 Apr 2017 17:18:16 -0400 Subject: [PATCH 3/4] Update bill_backend_call --- bpfin/utilbills/bill_backend_call.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bpfin/utilbills/bill_backend_call.py b/bpfin/utilbills/bill_backend_call.py index fb3f4b8..b2fc1dc 100644 --- a/bpfin/utilbills/bill_backend_call.py +++ b/bpfin/utilbills/bill_backend_call.py @@ -4,9 +4,9 @@ from bpfin.utilbills import bill_lib as bl from bpfin.tests.testdata import sample_data as db -def bill_prior_proj_rough_annual(raw_bill, analysis_date, inflation_coeff_dict): +def bill_prior_proj_rough_annual(raw_bill, analysis_date): norm_bill = bill_month_normalize_rough(raw_bill) - prior_bill_electricity = bill_prior_proj_rough(norm_bill, raw_bill, analysis_date, inflation_coeff_dict) + prior_bill_electricity = bill_prior_proj_rough(norm_bill, raw_bill, analysis_date, db.inflation_coeff_dict) annual_bill_electricity = bl.annualizing_projection( prior_bill_electricity['date_to'], prior_bill_electricity['charge']) -- GitLab From 273cb616e1e571cd00bf969d8cf5fc06a778c05a Mon Sep 17 00:00:00 2001 From: chenzheng06 Date: Mon, 24 Apr 2017 17:20:15 -0400 Subject: [PATCH 4/4] Fix --- bpfin/utilbills/bill_backend_call.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bpfin/utilbills/bill_backend_call.py b/bpfin/utilbills/bill_backend_call.py index b2fc1dc..2a4d19c 100644 --- a/bpfin/utilbills/bill_backend_call.py +++ b/bpfin/utilbills/bill_backend_call.py @@ -6,8 +6,8 @@ from bpfin.tests.testdata import sample_data as db def bill_prior_proj_rough_annual(raw_bill, analysis_date): norm_bill = bill_month_normalize_rough(raw_bill) - prior_bill_electricity = bill_prior_proj_rough(norm_bill, raw_bill, analysis_date, db.inflation_coeff_dict) - annual_bill_electricity = bl.annualizing_projection( - prior_bill_electricity['date_to'], - prior_bill_electricity['charge']) - return annual_bill_electricity + prior_bill_rough = bill_prior_proj_rough(norm_bill, raw_bill, analysis_date, db.inflation_coeff_dict) + annual_bill_rough = bl.annualizing_projection( + prior_bill_rough['date_to'], + prior_bill_rough['charge']) + return annual_bill_rough -- GitLab