From 349d89b81e78820d085d59bc299be44cd9c4ed68 Mon Sep 17 00:00:00 2001 From: chenzheng06 Date: Mon, 17 Apr 2017 14:00:41 -0400 Subject: [PATCH 1/4] improve test file for month_norm_rough --- bpfin/tests/test_financials/__init__.py | 0 bpfin/tests/test_utilbills/test_bill_lib.py | 8 +- .../test_month_normalize_rough.py | 118 ++++++++++++------ 3 files changed, 86 insertions(+), 40 deletions(-) create mode 100644 bpfin/tests/test_financials/__init__.py diff --git a/bpfin/tests/test_financials/__init__.py b/bpfin/tests/test_financials/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bpfin/tests/test_utilbills/test_bill_lib.py b/bpfin/tests/test_utilbills/test_bill_lib.py index a5c6aec..46a379e 100644 --- a/bpfin/tests/test_utilbills/test_bill_lib.py +++ b/bpfin/tests/test_utilbills/test_bill_lib.py @@ -1,12 +1,12 @@ -from bpfin.utilbills.0bill_lib import add_list +from bpfin.utilbills.bill_lib import add_list def test_add_list(): - input = [1, 2] + input_list = [1, 2] output = [3, 4] - result = add_list(input, 2) + result = add_list(input_list, 2) - for i in result: + for i in range(len(result)): assert result[i] == output[i] diff --git a/bpfin/tests/test_utilbills/test_month_normalize_rough.py b/bpfin/tests/test_utilbills/test_month_normalize_rough.py index 63d7ee1..43e8347 100644 --- a/bpfin/tests/test_utilbills/test_month_normalize_rough.py +++ b/bpfin/tests/test_utilbills/test_month_normalize_rough.py @@ -1,39 +1,85 @@ -import bpfin.utilbills.bill_month_normalize_rough as ub +from bpfin.utilbills.bill_month_normalize_rough import bill_month_normalize_rough import datetime -test_raw_bill = {} - -test_raw_bill['date_from'] = [ - datetime.date(2014, 4, 17), datetime.date(2014, 5, 16), datetime.date(2014, 6, 17), - datetime.date(2014, 7, 17), datetime.date(2014, 8, 15), datetime.date(2014, 9, 16), - datetime.date(2014, 10, 16), datetime.date(2014, 11, 14), datetime.date(2014, 12, 17), - datetime.date(2015, 1, 16), datetime.date(2015, 2, 18), datetime.date(2015, 3, 19), - datetime.date(2015, 4, 17), datetime.date(2015, 5, 18), datetime.date(2015, 6, 17), - datetime.date(2015, 7, 17), datetime.date(2015, 8, 17), datetime.date(2015, 9, 16), - datetime.date(2015, 10, 16), datetime.date(2015, 11, 16), datetime.date(2015, 12, 17), - datetime.date(2016, 1, 19), datetime.date(2016, 2, 18), datetime.date(2016, 3, 18)] - -test_raw_bill['date_to'] = [ - datetime.date(2014, 5, 16), datetime.date(2014, 6, 17), datetime.date(2014, 7, 17), - datetime.date(2014, 8, 15), datetime.date(2014, 9, 16), datetime.date(2014, 10, 16), - datetime.date(2014, 11, 14), datetime.date(2014, 12, 17), datetime.date(2015, 1, 16), - datetime.date(2015, 2, 18), datetime.date(2015, 3, 19), datetime.date(2015, 4, 17), - datetime.date(2015, 5, 18), datetime.date(2015, 6, 17), datetime.date(2015, 7, 17), - datetime.date(2015, 8, 17), datetime.date(2015, 9, 16), datetime.date(2015, 10, 16), - datetime.date(2015, 11, 16), datetime.date(2015, 12, 17), datetime.date(2016, 1, 19), - datetime.date(2016, 2, 18), datetime.date(2016, 3, 18), datetime.date(2016, 4, 18)] - -test_raw_bill['charge'] = [ - 2601.6289696969693, 2642.1740261508003, 3437.551946607342, 2930.5070588449826, - 2514.1242835094554, 2804.4448749999997, 3237.7359972191325, 3289.4155027808674, - 2796.5700000000002, 2463.5113047830923, 2370.0007392051775, 2479.081440860215] - -test_raw_bill['usage'] = [ - 0.094265231101663627, 0.10175446346513953, 0.12248981352003527, 0.11229655777596657, - 0.092170964664193167, 0.094173672324921492, 0.095187070309577237, 0.097177529967719486, - 0.095676831493476874, 0.091583582602530869, 0.089122740090923164, 0.091516956021057888] - -test_raw_bill['utility_type'] = 'electricity' - -print(ub.bill_month_normalize_rough(test_raw_bill)) +def test_month_normalization_rough(): + test_raw_bill = {} + test_raw_bill['utility_type'] = 'electricity' + test_raw_bill['date_from'] = [ + datetime.date(2014, 4, 17), datetime.date(2014, 5, 16), datetime.date(2014, 6, 17), + datetime.date(2014, 7, 17), datetime.date(2014, 8, 15), datetime.date(2014, 9, 16), + datetime.date(2014, 10, 16), datetime.date(2014, 11, 14), datetime.date(2014, 12, 17), + datetime.date(2015, 1, 16), datetime.date(2015, 2, 18), datetime.date(2015, 3, 19), + datetime.date(2015, 4, 17), datetime.date(2015, 5, 18), datetime.date(2015, 6, 17), + datetime.date(2015, 7, 17), datetime.date(2015, 8, 17), datetime.date(2015, 9, 16), + datetime.date(2015, 10, 16), datetime.date(2015, 11, 16), datetime.date(2015, 12, 17), + datetime.date(2016, 1, 19), datetime.date(2016, 2, 18), datetime.date(2016, 3, 18)] + test_raw_bill['date_to'] = [ + datetime.date(2014, 5, 16), datetime.date(2014, 6, 17), datetime.date(2014, 7, 17), + datetime.date(2014, 8, 15), datetime.date(2014, 9, 16), datetime.date(2014, 10, 16), + datetime.date(2014, 11, 14), datetime.date(2014, 12, 17), datetime.date(2015, 1, 16), + datetime.date(2015, 2, 18), datetime.date(2015, 3, 19), datetime.date(2015, 4, 17), + datetime.date(2015, 5, 18), datetime.date(2015, 6, 17), datetime.date(2015, 7, 17), + datetime.date(2015, 8, 17), datetime.date(2015, 9, 16), datetime.date(2015, 10, 16), + datetime.date(2015, 11, 16), datetime.date(2015, 12, 17), datetime.date(2016, 1, 19), + datetime.date(2016, 2, 18), datetime.date(2016, 3, 18), datetime.date(2016, 4, 18)] + test_raw_bill['charge'] = [ + 2601.6289696969693, 2642.1740261508003, 3437.551946607342, 2930.5070588449826, + 2514.1242835094554, 2804.4448749999997, 3237.7359972191325, 3289.4155027808674, + 2796.5700000000002, 2463.5113047830923, 2370.0007392051775, 2479.081440860215] + test_raw_bill['usage'] = [ + 0.094265231101663627, 0.10175446346513953, 0.12248981352003527, 0.11229655777596657, + 0.092170964664193167, 0.094173672324921492, 0.095187070309577237, 0.097177529967719486, + 0.095676831493476874, 0.091583582602530869, 0.089122740090923164, 0.091516956021057888] + + input_dict = test_raw_bill + output_dict = { + 'monthly_usage': [ + 0.092656544646156233, 0.081407077375199768, 0.096259845999318444, 0.095904698506193486, + 0.09970580811571926, 0.10713597790787066, 0.12362302566814179, 0.10416990876794137, + 0.090033196083726619, 0.099460650112727964, 0.093068756936307756, 0.094710339831841669], + 'monthly_charge': [ + 2611.2818658104966, 2180.2694934775395, 2578.5859081110675, 2619.5021069201466, + 2673.9005752806534, 2893.2607949224612, 3362.6736487267954, 2772.8416549504082, + 2565.8030834213941, 3170.3949663777121, 3157.9130867351737, 2999.6133802204467], + 'monthly_price': [ + 28182.379083772827, 26782.308906986349, 26787.762657851385, 27313.595138938686, + 26817.901843564676, 27005.501339712977, 27201.030152373722, 26618.451410257541, + 28498.41164180508, 31875.872144254135, 33930.968787907128, 31671.445647289031]} + result = bill_month_normalize_rough(input_dict) + + for i in range(len(result)): + assert result[i] == output[i] + + +# test_raw_bill = {} + +# test_raw_bill['utility_type'] = 'electricity' +# test_raw_bill['date_from'] = [ +# datetime.date(2014, 4, 17), datetime.date(2014, 5, 16), datetime.date(2014, 6, 17), +# datetime.date(2014, 7, 17), datetime.date(2014, 8, 15), datetime.date(2014, 9, 16), +# datetime.date(2014, 10, 16), datetime.date(2014, 11, 14), datetime.date(2014, 12, 17), +# datetime.date(2015, 1, 16), datetime.date(2015, 2, 18), datetime.date(2015, 3, 19), +# datetime.date(2015, 4, 17), datetime.date(2015, 5, 18), datetime.date(2015, 6, 17), +# datetime.date(2015, 7, 17), datetime.date(2015, 8, 17), datetime.date(2015, 9, 16), +# datetime.date(2015, 10, 16), datetime.date(2015, 11, 16), datetime.date(2015, 12, 17), +# datetime.date(2016, 1, 19), datetime.date(2016, 2, 18), datetime.date(2016, 3, 18)] +# test_raw_bill['date_to'] = [ +# datetime.date(2014, 5, 16), datetime.date(2014, 6, 17), datetime.date(2014, 7, 17), +# datetime.date(2014, 8, 15), datetime.date(2014, 9, 16), datetime.date(2014, 10, 16), +# datetime.date(2014, 11, 14), datetime.date(2014, 12, 17), datetime.date(2015, 1, 16), +# datetime.date(2015, 2, 18), datetime.date(2015, 3, 19), datetime.date(2015, 4, 17), +# datetime.date(2015, 5, 18), datetime.date(2015, 6, 17), datetime.date(2015, 7, 17), +# datetime.date(2015, 8, 17), datetime.date(2015, 9, 16), datetime.date(2015, 10, 16), +# datetime.date(2015, 11, 16), datetime.date(2015, 12, 17), datetime.date(2016, 1, 19), +# datetime.date(2016, 2, 18), datetime.date(2016, 3, 18), datetime.date(2016, 4, 18)] +# test_raw_bill['charge'] = [ +# 2601.6289696969693, 2642.1740261508003, 3437.551946607342, 2930.5070588449826, +# 2514.1242835094554, 2804.4448749999997, 3237.7359972191325, 3289.4155027808674, +# 2796.5700000000002, 2463.5113047830923, 2370.0007392051775, 2479.081440860215] +# test_raw_bill['usage'] = [ +# 0.094265231101663627, 0.10175446346513953, 0.12248981352003527, 0.11229655777596657, +# 0.092170964664193167, 0.094173672324921492, 0.095187070309577237, 0.097177529967719486, +# 0.095676831493476874, 0.091583582602530869, 0.089122740090923164, 0.091516956021057888] + +# print(bill_month_normalize_rough(test_raw_bill)) -- GitLab From c2d5a54230106afe7e051691e94cb88353d11c15 Mon Sep 17 00:00:00 2001 From: chenzheng06 Date: Mon, 17 Apr 2017 14:08:55 -0400 Subject: [PATCH 2/4] updated test file, and cleaned bill_month_norm_rough py file. The oil calculation is still missing --- .../test_month_normalize_rough.py | 38 +------------- bpfin/utilbills/bill_month_normalize_rough.py | 51 +------------------ 2 files changed, 3 insertions(+), 86 deletions(-) diff --git a/bpfin/tests/test_utilbills/test_month_normalize_rough.py b/bpfin/tests/test_utilbills/test_month_normalize_rough.py index 43e8347..6cb619c 100644 --- a/bpfin/tests/test_utilbills/test_month_normalize_rough.py +++ b/bpfin/tests/test_utilbills/test_month_normalize_rough.py @@ -46,40 +46,6 @@ def test_month_normalization_rough(): 28182.379083772827, 26782.308906986349, 26787.762657851385, 27313.595138938686, 26817.901843564676, 27005.501339712977, 27201.030152373722, 26618.451410257541, 28498.41164180508, 31875.872144254135, 33930.968787907128, 31671.445647289031]} - result = bill_month_normalize_rough(input_dict) + result_dict = bill_month_normalize_rough(input_dict) - for i in range(len(result)): - assert result[i] == output[i] - - -# test_raw_bill = {} - -# test_raw_bill['utility_type'] = 'electricity' -# test_raw_bill['date_from'] = [ -# datetime.date(2014, 4, 17), datetime.date(2014, 5, 16), datetime.date(2014, 6, 17), -# datetime.date(2014, 7, 17), datetime.date(2014, 8, 15), datetime.date(2014, 9, 16), -# datetime.date(2014, 10, 16), datetime.date(2014, 11, 14), datetime.date(2014, 12, 17), -# datetime.date(2015, 1, 16), datetime.date(2015, 2, 18), datetime.date(2015, 3, 19), -# datetime.date(2015, 4, 17), datetime.date(2015, 5, 18), datetime.date(2015, 6, 17), -# datetime.date(2015, 7, 17), datetime.date(2015, 8, 17), datetime.date(2015, 9, 16), -# datetime.date(2015, 10, 16), datetime.date(2015, 11, 16), datetime.date(2015, 12, 17), -# datetime.date(2016, 1, 19), datetime.date(2016, 2, 18), datetime.date(2016, 3, 18)] -# test_raw_bill['date_to'] = [ -# datetime.date(2014, 5, 16), datetime.date(2014, 6, 17), datetime.date(2014, 7, 17), -# datetime.date(2014, 8, 15), datetime.date(2014, 9, 16), datetime.date(2014, 10, 16), -# datetime.date(2014, 11, 14), datetime.date(2014, 12, 17), datetime.date(2015, 1, 16), -# datetime.date(2015, 2, 18), datetime.date(2015, 3, 19), datetime.date(2015, 4, 17), -# datetime.date(2015, 5, 18), datetime.date(2015, 6, 17), datetime.date(2015, 7, 17), -# datetime.date(2015, 8, 17), datetime.date(2015, 9, 16), datetime.date(2015, 10, 16), -# datetime.date(2015, 11, 16), datetime.date(2015, 12, 17), datetime.date(2016, 1, 19), -# datetime.date(2016, 2, 18), datetime.date(2016, 3, 18), datetime.date(2016, 4, 18)] -# test_raw_bill['charge'] = [ -# 2601.6289696969693, 2642.1740261508003, 3437.551946607342, 2930.5070588449826, -# 2514.1242835094554, 2804.4448749999997, 3237.7359972191325, 3289.4155027808674, -# 2796.5700000000002, 2463.5113047830923, 2370.0007392051775, 2479.081440860215] -# test_raw_bill['usage'] = [ -# 0.094265231101663627, 0.10175446346513953, 0.12248981352003527, 0.11229655777596657, -# 0.092170964664193167, 0.094173672324921492, 0.095187070309577237, 0.097177529967719486, -# 0.095676831493476874, 0.091583582602530869, 0.089122740090923164, 0.091516956021057888] - -# print(bill_month_normalize_rough(test_raw_bill)) + assert result_dict == output_dict diff --git a/bpfin/utilbills/bill_month_normalize_rough.py b/bpfin/utilbills/bill_month_normalize_rough.py index 07d0772..65f5af3 100644 --- a/bpfin/utilbills/bill_month_normalize_rough.py +++ b/bpfin/utilbills/bill_month_normalize_rough.py @@ -2,61 +2,13 @@ import datetime # import sys import bpfin.lib.other as lib -# sys.path.append('C:/Users/zheng/Documents/BlocPower_Work_File/7. Python/') - - -# class Bill(): -# def __init__(self, raw_bill): -# self.billstart = lib.convert_timestamp_date(raw_bill['date_from']) -# self.billend = lib.convert_timestamp_date(raw_bill['date_to']) -# self.usage = raw_bill['usage'] -# self.charge = raw_bill['charge'] -# self.utility_type = raw_bill['utility_type'] - -# def normalize_rough(self): -# if self.billstart != []: -# monthmatrix = lib.form_month_matrix(self.billstart, self.billend) -# # self.hist_daily_usage = lib.division(self.usage, lib.date_diff(self.billstart, self.billend)) -# # self.hist_daily_charge = lib.division(self.charge, lib.date_diff(self.billstart, self.billend)) -# # self.hist_monthly_usage = lib.monthly_average(self.hist_daily_usage, monthmatrix) -# # self.hist_monthly_charge = lib.monthly_average(self.hist_daily_charge, monthmatrix) -# # self.hist_monthly_price = lib.division(self.hist_monthly_charge, self.hist_monthly_usage) - -# daily_usage = lib.division(self.usage, lib.date_diff(self.billstart, self.billend)) -# daily_charge = lib.division(self.charge, lib.date_diff(self.billstart, self.billend)) -# month_norm_usage = lib.monthly_average(daily_usage, monthmatrix) -# month_norm_charge = lib.monthly_average(daily_charge, monthmatrix) -# month_norm_price = lib.division(month_norm_charge, month_norm_usage) -# else: -# month_norm_usage = [0] * 12 -# month_norm_charge = [0] * 12 -# month_norm_price = [0] * 12 - -# result_dict = { -# 'monthly_usage': month_norm_usage, -# 'monthly_charge': month_norm_charge, -# 'monthly_price': month_norm_price} -# return result_dict - - # def prior(self, FinancialDict): - # [self.prior_billstart, self.prior_billend] = form_bill_calendar(FinancialDict['ProForma_Start'], - # FinancialDict['ProForma_Duration']) - # self.prior_monthly_usage = duplicate2terms(self.hist_monthly_usage, self.prior_billend) - # self.prior_monthly_price = form_inflated_item(self.hist_monthly_price, self.prior_billend, - # FinancialDict['inflation_coeff_dict'], - # FinancialDict['present_date']) - # self.prior_monthly_charge = product2list(self.prior_monthly_usage, self.prior_monthly_price) - def bill_month_normalize_rough(raw_bill): - print('\n let the normalization starts') - print(raw_bill) - billstart = lib.convert_timestamp_date(raw_bill['date_from']) billend = lib.convert_timestamp_date(raw_bill['date_to']) usage = raw_bill['usage'] charge = raw_bill['charge'] - utility_type = raw_bill['utility_type'] + # utility_type = raw_bill['utility_type'] if billstart != []: monthmatrix = lib.form_month_matrix(billstart, billend) @@ -71,7 +23,6 @@ def bill_month_normalize_rough(raw_bill): month_norm_charge = [0] * 12 month_norm_price = [0] * 12 - print("\n It goes ok") return {'monthly_usage': month_norm_usage, 'monthly_charge': month_norm_charge, 'monthly_price': month_norm_price} -- GitLab From 5f1004d9482a8bdb709161c018a6da7cb34c0282 Mon Sep 17 00:00:00 2001 From: chenzheng06 Date: Mon, 17 Apr 2017 14:23:15 -0400 Subject: [PATCH 3/4] added description for bill_month_norm_rough --- bpfin/utilbills/bill_month_normalize_rough.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/bpfin/utilbills/bill_month_normalize_rough.py b/bpfin/utilbills/bill_month_normalize_rough.py index 65f5af3..211b2e5 100644 --- a/bpfin/utilbills/bill_month_normalize_rough.py +++ b/bpfin/utilbills/bill_month_normalize_rough.py @@ -4,6 +4,26 @@ import bpfin.lib.other as lib def bill_month_normalize_rough(raw_bill): + """ take raw bill as input, normalize the date from random dates to beg/end of a month + math calculation is rough, by determining daily usage, daily price to calculate monthly usage and average price + NOT using reggression neither BlocPower's disaggeration method + inputs are at least 12 months of bills + outcome are 12 months of values. If the raw bill covers more than 12 months, then an average will be taken + + Args: + raw_bill (dictionary): dictionary of lists. Elements are + 'date_from: list of datetime, + 'date_to', list of datetime, + 'usage', list of float values, + 'charge', list of float, + 'utility_type', a char indicating utility type + Returns: + dictionary: dictionary of lists. Elements are + 'monthly_usage': a list of 12 float values, month normalized average energy usage + 'monthly_charge': a list of 12 float values, month normalized average energy charge + 'monthly_price': a list of 12 float values, month normalized average energy price + """ + billstart = lib.convert_timestamp_date(raw_bill['date_from']) billend = lib.convert_timestamp_date(raw_bill['date_to']) usage = raw_bill['usage'] -- GitLab From 2ddbd395961fb81d0201b1085347e11548a17442 Mon Sep 17 00:00:00 2001 From: chenzheng06 Date: Tue, 18 Apr 2017 09:24:46 -0400 Subject: [PATCH 4/4] changed variable names according to adarsh suggestion --- bpfin/utilbills/bill_month_normalize_rough.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/bpfin/utilbills/bill_month_normalize_rough.py b/bpfin/utilbills/bill_month_normalize_rough.py index 211b2e5..ccf9d9b 100644 --- a/bpfin/utilbills/bill_month_normalize_rough.py +++ b/bpfin/utilbills/bill_month_normalize_rough.py @@ -24,19 +24,19 @@ def bill_month_normalize_rough(raw_bill): 'monthly_price': a list of 12 float values, month normalized average energy price """ - billstart = lib.convert_timestamp_date(raw_bill['date_from']) - billend = lib.convert_timestamp_date(raw_bill['date_to']) + bill_start = lib.convert_timestamp_date(raw_bill['date_from']) + bill_end = lib.convert_timestamp_date(raw_bill['date_to']) usage = raw_bill['usage'] charge = raw_bill['charge'] # utility_type = raw_bill['utility_type'] - if billstart != []: - monthmatrix = lib.form_month_matrix(billstart, billend) - daily_usage = lib.division(usage, lib.date_diff(billstart, billend)) - daily_charge = lib.division(charge, lib.date_diff(billstart, billend)) + if bill_start != []: + month_matrix = lib.form_month_matrix(bill_start, bill_end) + daily_usage = lib.division(usage, lib.date_diff(bill_start, bill_end)) + daily_charge = lib.division(charge, lib.date_diff(bill_start, bill_end)) - month_norm_usage = lib.monthly_average(daily_usage, monthmatrix) - month_norm_charge = lib.monthly_average(daily_charge, monthmatrix) + month_norm_usage = lib.monthly_average(daily_usage, month_matrix) + month_norm_charge = lib.monthly_average(daily_charge, month_matrix) month_norm_price = lib.division(month_norm_charge, month_norm_usage) else: month_norm_usage = [0] * 12 -- GitLab