From ea156c210ed8d2b53640425c82225e1d5dcd8797 Mon Sep 17 00:00:00 2001 From: chenzheng06 Date: Mon, 1 May 2017 11:34:25 -0400 Subject: [PATCH 1/5] create monthly_saving calculation function --- bpfin/financials/monthly_saving.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 bpfin/financials/monthly_saving.py diff --git a/bpfin/financials/monthly_saving.py b/bpfin/financials/monthly_saving.py new file mode 100644 index 0000000..20a43ba --- /dev/null +++ b/bpfin/financials/monthly_saving.py @@ -0,0 +1,25 @@ +import datetime +from bpfin.utilbills.bill_lib import cal_last_day + + +def monthly_saving(commissioning_date, proforma_date, prior_list, post_list): + """ + Calculate monthly saving on usage, or on charge, considering the commissioning date. + Args: + commissioning_date (date): the date that construction work finished, saving starts at NEXT month + proforma_date (list): list of dates, months of pro-forma time period + prior_list (list): list of float, usage or charge without (prior to) savings + post_list (list): list of float, usage or charge with (post to) savings + """ + saving_start_date = datetime.date( + commissioning_date.year, + commissioning_date.month, + cal_last_day(commissioning_date.year, commissioning_date.month)) + saving_dict = {} + for date, prior, post in zip(proforma_date, prior_list, post_list): + if date > saving_start_date: + saving_dict[date] = prior_list - post_list + else: + saving_dict[date] = prior_list + return saving_dict + -- GitLab From afb14f648c6f77e167354c658c6c59edca7aab2e Mon Sep 17 00:00:00 2001 From: chenzheng06 Date: Mon, 1 May 2017 12:09:26 -0400 Subject: [PATCH 2/5] Create test file for monthly_saving calculation. Add exe sample comments for saving calculation in data_generation. --- bpfin/financials/monthly_saving.py | 12 +++---- .../test_financials/test_monthly_saving.py | 25 +++++++++++++++ bpfin/utilbills/data_generation.py | 31 ++++++++++++++++--- 3 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 bpfin/tests/test_financials/test_monthly_saving.py diff --git a/bpfin/financials/monthly_saving.py b/bpfin/financials/monthly_saving.py index 20a43ba..1f17500 100644 --- a/bpfin/financials/monthly_saving.py +++ b/bpfin/financials/monthly_saving.py @@ -10,16 +10,16 @@ def monthly_saving(commissioning_date, proforma_date, prior_list, post_list): proforma_date (list): list of dates, months of pro-forma time period prior_list (list): list of float, usage or charge without (prior to) savings post_list (list): list of float, usage or charge with (post to) savings + Return: + list: list of float, monthly saving values on usage or charge """ saving_start_date = datetime.date( - commissioning_date.year, - commissioning_date.month, + commissioning_date.year, commissioning_date.month, cal_last_day(commissioning_date.year, commissioning_date.month)) saving_dict = {} for date, prior, post in zip(proforma_date, prior_list, post_list): if date > saving_start_date: - saving_dict[date] = prior_list - post_list + saving_dict[date] = prior - post else: - saving_dict[date] = prior_list - return saving_dict - + saving_dict[date] = 0 + return list(saving_dict.values()) diff --git a/bpfin/tests/test_financials/test_monthly_saving.py b/bpfin/tests/test_financials/test_monthly_saving.py new file mode 100644 index 0000000..c9ad367 --- /dev/null +++ b/bpfin/tests/test_financials/test_monthly_saving.py @@ -0,0 +1,25 @@ +import datetime +from bpfin.financials.monthly_saving import monthly_saving + + +def test_monthly_saving(): + input_proforma_date = [ + datetime.date(2017, 1, 31), + datetime.date(2017, 2, 28), + datetime.date(2017, 3, 31), + datetime.date(2017, 4, 30), + datetime.date(2017, 5, 31), + datetime.date(2017, 6, 30), + datetime.date(2017, 7, 31), + datetime.date(2017, 8, 31), + datetime.date(2017, 9, 30), + datetime.date(2017, 10, 31), + datetime.date(2017, 11, 30), + datetime.date(2017, 12, 31), ] + input_commissioning_date = datetime.date(2017, 3, 14) + input_prior_list = [100] * 12 + post_post_list = [100, 90, 80, 70, 60, 50, 40, 30, 40, 50, 60, 70] + + out_put_list = [0, 0, 0, 30, 40, 50, 60, 70, 60, 50, 40, 30] + result_list = monthly_saving(input_commissioning_date, input_proforma_date, input_prior_list, post_post_list) + assert out_put_list == result_list diff --git a/bpfin/utilbills/data_generation.py b/bpfin/utilbills/data_generation.py index d7219d8..8f859fe 100644 --- a/bpfin/utilbills/data_generation.py +++ b/bpfin/utilbills/data_generation.py @@ -1,7 +1,12 @@ -# 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 +import copy +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.lib import other as lib +from bpfin.utilbills import bill_lib as bl +from bpfin.financials import financial_lib as fl +from bpfin.tests.testdata import sample_data as db + + # raw_bill = db.raw_bill @@ -11,3 +16,21 @@ # print(annual_bill_electricity) + +# prior_energy_bill = db.bill_overview_organized +# raw_income_input = db.raw_income_input + +# IS_prior = fl.Income_Statement_Table(raw_income_input, prior_energy_bill) +# IS_prior.project(-2.0, db.analysis_date, prior_energy_bill) + +# post_energy_bill = copy.deepcopy(db.bill_overview_organized) +# post_energy_bill['electricity'] = bl.annualizing_projection( +# db.post_bill_rough['date_to'], db.post_proj_rough_charge) + +# IS_post = fl.Income_Statement_Table(raw_income_input, post_energy_bill) +# IS_post.project(-2.0, db.analysis_date, post_energy_bill) + +# prior_noi = (IS_prior.get_noi_dict().values()) +# post_noi = (IS_post.get_noi_dict().values()) + +# print(lib.sublist(prior_noi, post_noi)) -- GitLab From 64cd327d304934eeb13d09c0004a159e53d51acb Mon Sep 17 00:00:00 2001 From: chenzheng06 Date: Mon, 1 May 2017 12:10:50 -0400 Subject: [PATCH 3/5] Comments in data_generation --- bpfin/utilbills/data_generation.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bpfin/utilbills/data_generation.py b/bpfin/utilbills/data_generation.py index 8f859fe..10ae15d 100644 --- a/bpfin/utilbills/data_generation.py +++ b/bpfin/utilbills/data_generation.py @@ -1,10 +1,10 @@ -import copy -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.lib import other as lib -from bpfin.utilbills import bill_lib as bl -from bpfin.financials import financial_lib as fl -from bpfin.tests.testdata import sample_data as db +# import copy +# 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.lib import other as lib +# from bpfin.utilbills import bill_lib as bl +# from bpfin.financials import financial_lib as fl +# from bpfin.tests.testdata import sample_data as db -- GitLab From e2f115db8a8e3239a8c7e6748572fc50286f5dea Mon Sep 17 00:00:00 2001 From: chenzheng06 Date: Mon, 1 May 2017 16:13:09 -0400 Subject: [PATCH 4/5] Modify monthly_saving function formatting and variable names --- bpfin/financials/monthly_saving.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bpfin/financials/monthly_saving.py b/bpfin/financials/monthly_saving.py index 1f17500..0f2ee41 100644 --- a/bpfin/financials/monthly_saving.py +++ b/bpfin/financials/monthly_saving.py @@ -2,22 +2,23 @@ import datetime from bpfin.utilbills.bill_lib import cal_last_day -def monthly_saving(commissioning_date, proforma_date, prior_list, post_list): +def monthly_saving(commissioning_date, proforma_date, prior_saving_list, post_saving_list): """ Calculate monthly saving on usage, or on charge, considering the commissioning date. Args: commissioning_date (date): the date that construction work finished, saving starts at NEXT month proforma_date (list): list of dates, months of pro-forma time period - prior_list (list): list of float, usage or charge without (prior to) savings - post_list (list): list of float, usage or charge with (post to) savings + prior_saving_list (list): list of float, usage or charge without (prior to) savings + post_saving_list (list): list of float, usage or charge with (post to) savings Return: list: list of float, monthly saving values on usage or charge """ saving_start_date = datetime.date( - commissioning_date.year, commissioning_date.month, + commissioning_date.year, + commissioning_date.month, cal_last_day(commissioning_date.year, commissioning_date.month)) saving_dict = {} - for date, prior, post in zip(proforma_date, prior_list, post_list): + for date, prior, post in zip(proforma_date, prior_saving_list, post_saving_list): if date > saving_start_date: saving_dict[date] = prior - post else: -- GitLab From 2559b2b20e06c3c2215e5a2f157e827963a43e5b Mon Sep 17 00:00:00 2001 From: chenzheng06 Date: Mon, 1 May 2017 17:48:28 -0400 Subject: [PATCH 5/5] Update saving calculation exe sample in data_generation --- bpfin/utilbills/data_generation.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/bpfin/utilbills/data_generation.py b/bpfin/utilbills/data_generation.py index 10ae15d..3f8da74 100644 --- a/bpfin/utilbills/data_generation.py +++ b/bpfin/utilbills/data_generation.py @@ -1,6 +1,8 @@ +# import datetime # import copy # 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.financials.monthly_saving import monthly_saving # from bpfin.lib import other as lib # from bpfin.utilbills import bill_lib as bl # from bpfin.financials import financial_lib as fl @@ -24,8 +26,16 @@ # IS_prior.project(-2.0, db.analysis_date, prior_energy_bill) # post_energy_bill = copy.deepcopy(db.bill_overview_organized) +# saving_list = monthly_saving(datetime.date(2018, 1, 1), db.proforma_date_to, db.prior_proj_rough_charge, db.post_proj_rough_charge) +# # print(saving_list) +# post_saving_e_bill = lib.sublist( +# db.prior_proj_rough_charge, +# saving_list +# ) +# # print(post_saving_e_bill) + # post_energy_bill['electricity'] = bl.annualizing_projection( -# db.post_bill_rough['date_to'], db.post_proj_rough_charge) +# db.post_bill_rough['date_to'], post_saving_e_bill) # IS_post = fl.Income_Statement_Table(raw_income_input, post_energy_bill) # IS_post.project(-2.0, db.analysis_date, post_energy_bill) @@ -33,4 +43,4 @@ # prior_noi = (IS_prior.get_noi_dict().values()) # post_noi = (IS_post.get_noi_dict().values()) -# print(lib.sublist(prior_noi, post_noi)) +# print(lib.sublist(post_noi, prior_noi)) -- GitLab