diff --git a/bpfin/tests/test_utilbills/test_bill_lib.py b/bpfin/tests/test_utilbills/test_bill_lib.py index 46a379e3f1851d725a788dd39cca8326ba01bce0..32670f13b0b78953184973037606687076f56430 100644 --- a/bpfin/tests/test_utilbills/test_bill_lib.py +++ b/bpfin/tests/test_utilbills/test_bill_lib.py @@ -8,5 +8,3 @@ def test_add_list(): for i in range(len(result)): assert result[i] == output[i] - - diff --git a/bpfin/tests/test_utilbills/test_bill_normalize.py b/bpfin/tests/test_utilbills/test_bill_normalize.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..2fc53dbf6d7675140710a6884b50b9c955725e65 100644 --- a/bpfin/tests/test_utilbills/test_bill_normalize.py +++ b/bpfin/tests/test_utilbills/test_bill_normalize.py @@ -0,0 +1,88 @@ +from datetime import date +from bpfin.utilbills.bill_normalize import daily_average_use_or_charge + + +def test_daily_average_use_or_charge(): + input_from_date = [date(1995, 10, 1), date(1996, 11, 1), date(1997, 12, 1)] + input_to_date = [date(1996, 10, 1), date(1997, 11, 1), date(1998, 12, 1)] + input_total_utility_use_or_charge = [10, 10, 10] + output = [0.027, 0.027, 0.027] + result = daily_average_use_or_charge(input_from_date, input_to_date, input_total_utility_use_or_charge) + +# def firstmatrix(from_date, to_date): +# """Create 2D matrix, list of lists. + +# Args: +# from_date (list): list of datetimes of "from dates" for bills +# to_date (list): list of datetimes of "end dates" for bills +# Returns: +# list: matrix (list of lists) of # of days in bill periods +# """ +# range_id = 0 +# for date in from_date: +# range_id += 1 +# monthmatrix = [[0 for i in range(12)] for j in range(range_id)] +# for (fromdate, enddate, range_id) in zip(from_date, to_date, range(range_id)): +# date = fromdate + datetime.timedelta(1) +# while date <= enddate: +# for month in range(1, 13): # range(1,13)=[1:12] +# if date.month == month: +# monthmatrix[range_id][month - 1] += 1 +# date = date + datetime.timedelta(1) +# return monthmatrix + + +# def finalmatrix(matrixchoice): +# """Return final normalized matrix. + +# Args: +# matrixchoice (list): list of lists (matrix) +# Returns: +# list: list of lists of normalized # of days in each bill +# """ +# newmatrix = [] +# for i in range(len(matrixchoice[0])): +# bill = [] +# for item in matrixchoice: +# bill.append(item[i]) +# newmatrix.append(bill) +# return newmatrix + + +# def normalize_average(matrix_choice): +# """Provide ratios necessary for bill averages. + +# Args: +# matrix_choice (list): list of lists of normalized # of days in each bill +# Returns: +# list: ratios necessary for normalizing usage/charge per month +# """ +# newlist = [] +# for i in matrix_choice: +# newlist.append((sum(list(i)))) +# divider = [x / y for x, y in zip(newlist, [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31])] +# return divider + + +# def monthly_info(billing_info, matrix, divider): +# """Generate normalized use/charge based on ratios. + +# Args: +# billing_info (list): list of usage or charge +# matrix (list): list of numbers of day +# divider (list): list of ratios +# Returns: +# list: normalized use/charge based on ratios +# """ +# monthly_average = [] +# for month in range(1, 13): +# matrixcolumn = [] +# for range_id in range(len(billing_info)): +# matrixcolumn.append(matrix[range_id][month - 1]) +# value = [daily_avg * (days) for (daily_avg, days) in zip(billing_info, matrixcolumn)] +# total = 0 +# for number in range(len(value)): +# total += value[number] +# monthly_average.append(total) +# monthly_values = [x / y for x, y in zip(monthly_average, divider)] +# return monthly_values diff --git a/bpfin/tests/test_utilbills/test_bill_proj_charge.py b/bpfin/tests/test_utilbills/test_bill_proj_charge.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..b2fbac51ac06a22650cf9e79ce51bd3976859da9 100644 --- a/bpfin/tests/test_utilbills/test_bill_proj_charge.py +++ b/bpfin/tests/test_utilbills/test_bill_proj_charge.py @@ -0,0 +1,86 @@ +from datetime import date +from bpfin.utilbills.bill_proj_charge import price_x_consumption, utility_charge_sum, charge_dictionary +from bpfin.utilbills.bill_proj_charge import hist_oil_price, monthly_price + + +def test_price_x_consumption(): + input_price = [1, 2, 3] + input_con_list = [10, 20, 30] + output = [10, 40, 90] + result = price_x_consumption(input_price, input_con_list) + + for value in output: + for res in result: + value = res + + +def test_utility_charge_sum(): + input_list1 = [1, 2, 3] + input_list2 = [2, 3, 4] + input_list3 = [3, 4, 5] + output = [6, 9, 12] + result = utility_charge_sum(input_list1, input_list2, input_list3) + + for value in output: + for res in result: + value = res + + +def test_charge_dictionary(): + input_billperiod = [date(1995, 10, 1), date(1996, 11, 1), date(1997, 12, 1)] + input_charge_list = [20, 30, 40] + output = [(date(1995, 10, 1), 20), (date(1996, 11, 1), 30), (date(1997, 12, 1), 40)] + result = charge_dictionary(input_billperiod, input_charge_list) + + for value in output: + for res in result: + value = res + + +# def charge_with_inflation(billperiod, bill_dictionary, inf_dictionary): +# """Create dictionary of inflation adjusted bills with date. + +# Args: +# billperiod (list): list of datetimes +# bill_dictionary (dictionary): dictionary of bills (bill, {month, year} +# inf_dictionary (dictionary): dictionary of infs (inflation, {month, year}) +# Returns: +# dictionary: inflation adjusted dictionary of bills (bill, {month, year}) +# """ +# bdmonth = [] +# bdyear = [] +# for i in billperiod: +# bdmonth.append(i.month) +# for i in billperiod: +# bdyear.append(i.year) +# bdzipper = [(x, y) for x, y in zip(bdyear, bdmonth)] +# list_helper = [] +# for first, second in bill_dictionary.items(): +# for third, fourth in inf_dictionary.items(): +# if first == third: +# list_helper.append(second * fourth) +# dict_final = {key: value for key, value in zip(bdzipper, list_helper)} + +# # return dict_final +# return [(x, dict_final[x]) for x in sorted(dict_final)] + +def test_hist_oil_price(): + input_oilcharge = [2, 2, 2] + input_oiluse = [10, 10, 10] + output = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5] + result = hist_oil_price(input_oilcharge, input_oiluse) + + for value in output: + for res in result: + value = res + + +def test_monthly_price(): + input_charge = [10, 4, 2] + input_use = [5, 2, 2] + output = [2, 2, 1] + result = monthly_price(input_charge, input_use) + + for value in output: + for res in result: + value = res diff --git a/bpfin/tests/test_utilbills/test_bill_proj_reg.py b/bpfin/tests/test_utilbills/test_bill_proj_reg.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..7301e9e14ad8728ec0332252996b73f8748647c4 100644 --- a/bpfin/tests/test_utilbills/test_bill_proj_reg.py +++ b/bpfin/tests/test_utilbills/test_bill_proj_reg.py @@ -0,0 +1,13 @@ +from bpfin.utilbills.bill_proj_reg import regression_coefficients, regression_predicting_y + + +def test_regression_coefficients(): + input_x = [15, 30, 45] + input_y = [30, 60, 90] + is_true = True + output = [0, 2] + result = regression_coefficients(input_x, input_y, is_true) + + for number in output: + for coef in result: + number = coef diff --git a/bpfin/utilbills/bill_normalize.py b/bpfin/utilbills/bill_normalize.py index e7d365e4e7a3ff7601519cf12c07d7dcd95fccb0..537f8a7d0c2750b9c45a192d5a58a4d5fea408ae 100644 --- a/bpfin/utilbills/bill_normalize.py +++ b/bpfin/utilbills/bill_normalize.py @@ -2,6 +2,7 @@ import statsmodels.api as sm import datetime import calendar + def daily_average_use_or_charge(from_date, to_date, total_utility_use_or_charge): """Calculate average daily use or charge for a utility.