From 3db717691bd7a65e70a7a7610f817e39bc9e892b Mon Sep 17 00:00:00 2001 From: chenzheng06 Date: Fri, 21 Apr 2017 14:23:26 -0400 Subject: [PATCH 1/2] Fix cal_oil_price in bill_month_norm_rough Create associated test file and test data Merge from master --- bpfin/tests/test_utilbills/test_bill_lib.py | 8 ++++++++ .../test_month_normalize_rough.py | 7 +++++++ bpfin/tests/testdata/sample_data.py | 20 +++++++++++++++++++ bpfin/utilbills/bill_lib.py | 1 + 4 files changed, 36 insertions(+) diff --git a/bpfin/tests/test_utilbills/test_bill_lib.py b/bpfin/tests/test_utilbills/test_bill_lib.py index 13c927b..bbc0a97 100644 --- a/bpfin/tests/test_utilbills/test_bill_lib.py +++ b/bpfin/tests/test_utilbills/test_bill_lib.py @@ -21,3 +21,11 @@ def test_annualizing_projection(): result = annualizing_projection(input_dates, input_values) assert output_dictionary == result + + +def test_cal_oil_price(): + input_oiluse = [1, 2, 3, 4, 5, 6] + input_oilcharge = [12, 10, 8, 6, 4, 2] + output_list = [2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0] + result_list = bl.cal_oil_price(input_oilcharge, input_oiluse) + assert output_list == result_list diff --git a/bpfin/tests/test_utilbills/test_month_normalize_rough.py b/bpfin/tests/test_utilbills/test_month_normalize_rough.py index 29f21d5..04a6cbc 100644 --- a/bpfin/tests/test_utilbills/test_month_normalize_rough.py +++ b/bpfin/tests/test_utilbills/test_month_normalize_rough.py @@ -10,3 +10,10 @@ def test_month_normalization_rough(): result_dict = bill_month_normalize_rough(input_dict) assert result_dict == output_dict + + +def test_month_normalization_rough_oil(): + input_dict = db.raw_bill_oil + output_dict = db.monthly_normalized_bill_oil + result_dict = bill_month_normalize_rough(input_dict) + assert result_dict == output_dict diff --git a/bpfin/tests/testdata/sample_data.py b/bpfin/tests/testdata/sample_data.py index a99a49c..5af2852 100644 --- a/bpfin/tests/testdata/sample_data.py +++ b/bpfin/tests/testdata/sample_data.py @@ -55,6 +55,26 @@ monthly_normalized_bill = { 26817.901843564676, 27005.501339712977, 27201.030152373722, 26618.451410257541, 28498.41164180508, 31875.872144254135, 33930.968787907128, 31671.445647289031]} +raw_bill_oil = {} +raw_bill_oil['utility_type'] = 'oil' +raw_bill_oil['date_from'] = raw_bill['date_from'] +raw_bill_oil['date_to'] = raw_bill['date_to'] +raw_bill_oil['charge'] = raw_bill['charge'] +raw_bill_oil['usage'] = raw_bill['usage'] +monthly_normalized_bill_oil = { + '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': [ + 2641.5304891952883, 2320.8212408964555, 2744.2564263914742, 2734.1315837823149, + 2842.4968046599106, 3054.3223170489046, 3524.3489028868621, 2969.7631302574569, + 2566.7418680794467, 2835.5076346876781, 2653.282182900407, 2700.0818049417217], + 'monthly_price': [ + 28508.83873646447, 28508.83873646447, 28508.83873646447, 28508.83873646447, + 28508.83873646447, 28508.83873646447, 28508.83873646447, 28508.83873646447, + 28508.83873646447, 28508.83873646447, 28508.83873646447, 28508.83873646447]} + # pro-forma projection analysis_date = { 'proforma_start': datetime.date(2012, 1, 15), diff --git a/bpfin/utilbills/bill_lib.py b/bpfin/utilbills/bill_lib.py index 3f2536a..cd810f9 100644 --- a/bpfin/utilbills/bill_lib.py +++ b/bpfin/utilbills/bill_lib.py @@ -1,6 +1,7 @@ import statsmodels.api as sm import datetime import calendar +import pandas as pd def add_list(obj_list, number): -- GitLab From 85967193c606acade1096efb91c818079e18090e Mon Sep 17 00:00:00 2001 From: chenzheng06 Date: Fri, 21 Apr 2017 14:27:11 -0400 Subject: [PATCH 2/2] Fix import head in test_bill_lib --- bpfin/tests/test_utilbills/test_bill_lib.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bpfin/tests/test_utilbills/test_bill_lib.py b/bpfin/tests/test_utilbills/test_bill_lib.py index bbc0a97..f1a011f 100644 --- a/bpfin/tests/test_utilbills/test_bill_lib.py +++ b/bpfin/tests/test_utilbills/test_bill_lib.py @@ -1,5 +1,6 @@ from bpfin.utilbills.bill_lib import add_list, annualizing_projection -from datetime import date, datetime.date +from datetime import date +from bpfin.utilbills import bill_lib as bl def test_add_list(): -- GitLab