diff --git a/bpfin/lib/other.py b/bpfin/lib/other.py index ad26948abd7837061d0be011f9b8b203ee3f7f41..793055b640e79de2586dd41d593ee3686c2ec9a3 100644 --- a/bpfin/lib/other.py +++ b/bpfin/lib/other.py @@ -1,13 +1,6 @@ -import bpfin.lib.date -import bpfin.lib.math - import datetime import calendar -# from dateutil.parser import * -import dateutil.parser import numpy as np -import pandas as pd -import xlrd from scipy.optimize import linprog @@ -226,6 +219,14 @@ def sublist(list1, list2): def multiply_list(obj_list, number): + """ + Multiply a number on every element in a list + Args: + obj_list (list): a list of float values + number (float): a float number + Return: + list: list of productions + """ return [x * number for x in obj_list] diff --git a/bpfin/tests/test_utilbills/test_bill_post_proj_rough.py b/bpfin/tests/test_utilbills/test_bill_post_proj_rough.py new file mode 100644 index 0000000000000000000000000000000000000000..cc6abfd200f31a54cf2271a728870b7a5a86a29b --- /dev/null +++ b/bpfin/tests/test_utilbills/test_bill_post_proj_rough.py @@ -0,0 +1,10 @@ +from bpfin.utilbills.bill_post_proj_rough import bill_post_proj_rough +from bpfin.tests.testdata import sample_data as db + + +def test_bill_post_proj_rough(): + input_prior_bill = db.prior_bill_rough + input_saving_percent = 0.25 + output_dict = db.post_bill_rough + result_dict = bill_post_proj_rough(input_prior_bill, input_saving_percent) + assert output_dict == result_dict diff --git a/bpfin/tests/test_utilbills/test_bill_prior_proj_rough.py b/bpfin/tests/test_utilbills/test_bill_prior_proj_rough.py index d03166504cf8240ca668ebb53d106aada7890806..c39870f0618a911368f357ba7052efeaefe76ef9 100644 --- a/bpfin/tests/test_utilbills/test_bill_prior_proj_rough.py +++ b/bpfin/tests/test_utilbills/test_bill_prior_proj_rough.py @@ -7,14 +7,7 @@ def test_bill_prior_proj_rough(): raw_bill = db.raw_bill analysis_date = db.analysis_date inflation_coeff_dict = db.inflation_coeff_dict - - output_dict = { - 'date_from': db.proforma_date_from, - 'date_to': db.proforma_date_to, - 'usage': db.prior_proj_rough_usage, - 'charge': db.prior_proj_rough_charge, - 'price': db.prior_proj_rough_price - } + output_dict = db.prior_bill_rough result_dict = bill_prior_proj_rough(month_norm_bill, raw_bill, analysis_date, inflation_coeff_dict) diff --git a/bpfin/tests/testdata/sample_data.py b/bpfin/tests/testdata/sample_data.py index 38070137dc53a3d0fbb1b8c2ba2b4020dc11f803..b7a8053a466e0858a5970b982fc59c5081c47844 100644 --- a/bpfin/tests/testdata/sample_data.py +++ b/bpfin/tests/testdata/sample_data.py @@ -1,6 +1,6 @@ import datetime import pprint -from bpfin.utilbills import bill_lib as bl +# from bpfin.utilbills import bill_lib as bl # pp = pprint.PrettyPrinter(width=120, indent=4, compact=True) # pp.pprint(inflation_coeff_dict) @@ -204,20 +204,20 @@ income_next = {} income_next[1] = { 'year': 2017, 'revenue': 101000.0, 'utility_expense': 59652.416499097984, 'energy_opex': 37553.27291517199, 'electricity_opex': 34523.27291517199, 'gas_opex': 1520, 'oil_opex': 1510, 'water_opex': 0, - 'other_utility': 22099.143583925994, 'non_utility_expense': 3366.6666666666665, 'net_non_energy_opex': 25465.81025059266, - 'total_opex': 63019.08316576465, 'noi': 37980.91683423535} + 'other_utility': 22099.143583925994, 'non_utility_expense': 3366.6666666666665, + 'net_non_energy_opex': 25465.81025059266, 'total_opex': 63019.08316576465, 'noi': 37980.91683423535} # growth_rate_flag == 0.00 income_next[2] = { 'year': 2017, 'revenue': 100000.0, 'utility_expense': 59433.61309727693, 'energy_opex': 37553.27291517199, 'electricity_opex': 34523.27291517199, 'gas_opex': 1520, 'oil_opex': 1510, 'water_opex': 0, - 'other_utility': 21880.340182104945, 'non_utility_expense': 3333.3333333333335, 'net_non_energy_opex': 25213.673515438277, - 'total_opex': 62766.94643061027, 'noi': 37233.05356938973} + 'other_utility': 21880.340182104945, 'non_utility_expense': 3333.3333333333335, + 'net_non_energy_opex': 25213.673515438277, 'total_opex': 62766.94643061027, 'noi': 37233.05356938973} # growth_rate_flag == -1.0 income_next[3] = { 'year': 2017, 'revenue': 95000.0, 'utility_expense': 58339.59608817169, 'energy_opex': 37553.27291517199, 'electricity_opex': 34523.27291517199, 'gas_opex': 1520, 'oil_opex': 1510, 'water_opex': 0, - 'other_utility': 20786.3231729997, 'non_utility_expense': 3166.6666666666665, 'net_non_energy_opex':23952.989839666367, - 'total_opex': 61506.26275483836, 'noi': 33493.73724516164} + 'other_utility': 20786.3231729997, 'non_utility_expense': 3166.6666666666665, + 'net_non_energy_opex': 23952.989839666367, 'total_opex': 61506.26275483836, 'noi': 33493.73724516164} # growth_rate_flag == -2.0 income_next[4] = { 'year': 2017, 'revenue': 105409.25533894598, 'utility_expense': 60617.176566756985, 'energy_opex': 37553.27291517199, @@ -1276,9 +1276,225 @@ prior_proj_rough_price = [ 42131.00318614885, 40054.83089682108, 40079.848368848034, 40883.798098440246, 40432.470041231565, 40779.34931771414, 41139.21219179594, 40321.43463472525, 43237.085994998866, 48437.35375945405, 51641.29962190506, 48278.23252154697] +prior_bill_rough = { + 'date_from': proforma_date_from, + 'date_to': proforma_date_to, + 'usage': prior_proj_rough_usage, + 'charge': prior_proj_rough_charge, + 'price': prior_proj_rough_price + } + +post_proj_rough_charge = [ + 1859.2014191475037, 1553.0884418312685, 1837.726739684238, + 1867.8044329345366, 1920.5322046853819, 2081.503153111865, + 2423.1894138931943, 2001.432112115146, 1855.0356838309879, + 2295.913209808375, 2290.6325172702263, 2179.3836188506457, + 1897.2053695429759, 1584.028396463902, 1873.3830301048613, + 1903.0750754821224, 1955.8024501137115, 2118.650583902494, + 2465.1792256764056, 2035.0771216276828, 1885.2595473042438, + 2332.1324915727246, 2325.5840844231802, 2211.511384940947, + 1925.4063379912554, 1607.768699530916, 1901.6900895999775, + 1932.0645738338133, 1985.8354380617452, 2151.4445757596272, + 2503.6399874839385, 2067.0777240752723, 1915.1360807258125, + 2369.377521170649, 2363.010468049987, 2247.373901404105, 1954.177336637983, + 1629.7484108216622, 1925.2722962252867, 1953.5722486772652, + 2005.42543146049, 2169.9455961918457, 2522.0052365450965, + 2079.6312412128063, 1924.3523125660456, 2377.7962247832843, + 2368.4348150513797, 2249.710035165335, 1958.4613993578723, + 1635.2021201081548, 1933.9394310833006, 1964.62658019011, + 2019.0956247028275, 2187.2531296731077, 2545.048227737386, + 2101.049076994495, 1946.4097950772614, 2407.820790014731, + 2401.103023695569, 2283.3670790902765, 1989.2284890755493, + 1662.116881118693, 1967.2223585859315, 1999.9128161271326, + 2056.877371212701, 2229.82625030877, 2596.500785182561, 2145.107707338978, + 1988.69257579388, 2461.943010270735, 2456.88650458826, 2338.139936775805, + 2037.2302309654235, 1702.462988420119, 2015.256114353034, + 2049.031034489731, 2107.689102309963, 2285.229651712486, 2661.386576158895, + 2199.0205304604283, 2038.9590808754679, 2524.5241540969605, + 2519.6911264451633, 2398.244122007635, 2089.2338079131673, + 1745.6157670945538, 2065.9759824428297, 2100.233595622051, + 2159.9796478556013, 2341.515320261667, 2726.4601798473045, + 2252.394847846601, 2088.0831819676946, 2584.8947211544837, + 2579.494937951015, 2454.7360811800563, 2138.402572437745, + 1786.660701465149, 2114.5098043224843, 2149.5276787591197, + 2210.630233759071, 2396.37320955687, 2790.2789128143045, + 2305.0693117408364, 2136.8708012684115, 2645.235452991637, + 2639.654951638436, 2511.934396174742, 2187.570465709978, 1827.190231123913, + 2161.82472392719, 2196.9638683359894, 2258.733924218244, 2447.780786364695, + 2849.2777014601907, 2353.099262273337, 2180.7386468237887, + 2698.725959566911, 2692.2210105236272, 2561.184929896785, + 2230.2387016126336, 1862.6433783011532, 2203.550861463148, + 2239.1447311295838, 2301.870979441611, 2494.2792632316446, + 2903.1133008220177, 2397.3205351847946, 2221.4990385553565, + 2748.893711024218, 2741.9941374598316, 2608.2751399788804, + 2271.196305626763, 1896.8102983794947, 2243.9239096479464, + 2280.1219411243637, 2343.946778358422, 2539.8186373071385, + 2956.054767249412, 2440.9869461694225, 2261.915319073278, + 2798.846114672028, 2791.762413996745, 2655.5604808090534, + 2312.434962552544, 1931.3047640614047, 2284.7942545005276, + 2321.71605484783, 2386.771460490539, 2586.293775153096, 3010.2300289204954, + 2485.7916431191616, 2303.497088194489, 2850.377659990733, + 2843.242482944357, 2704.604084755405, 2355.1850725691183, + 1967.0451807298723, 2327.1192136734617, 2364.7685935954364, + 2431.0751884904917, 2634.349665486094, 3066.2196281220586, + 2532.073509587417, 2346.4281708922263, 2903.554702290988, + 2896.339831996922, 2755.1631893567446, 2399.561511281831, + 2004.4000363956013, 2371.657210163833, 2410.3779984482608, + 2478.324190713594, 2685.940354477348, 3126.7231087435553, + 2582.4129633698626, 2393.4252422132704, 2962.1417327066515, + 2955.211436453655, 2811.574454091988, 2448.802458704613, + 2045.6242874517993, 2420.544055656341, 2460.174043314417, + 2529.6381225945593, 2741.676754805816, 3191.750338609582, + 2636.2390384042087, 2443.422478232012, 3024.1556268045347, + 3017.2164355266527, 2870.695302943259, 2500.2347336051453, + 2088.538206404295, 2471.2635639037394, 2511.6633476514958, + 2582.5189388234253, 2798.922600006724, 3258.3150437603713, + 2691.1534924954767, 2494.2602653135145, 3087.001650230099, + 3079.843942873497, 2930.2108126185117, 2551.966420103494, + 2131.665218618088, 2522.19142085119, 2563.319902464907, 2635.5259698033724, + 2856.2556545362063, 3324.923559796346, 2746.0564709979362, + 2545.0432484953585, 3149.725188914619, 3142.2947260017645, + 2989.506316263982, 2603.537309978532, 2174.683657694881, 2573.02127628036, + 2614.9078229438755, 2688.4942768202723, 2913.5812593317755, + 3391.5635927535805, 2801.0186779725327, 2595.9118990466504, + 3212.592842502329, 3204.9272952447486, 3049.010937012849, + 2655.2858283783034, 2217.8467193353745, 2624.01781529638, + 2666.6606427452025, 2741.6275033503853, 2971.0805883794387, + 3458.4000316602906, 2856.1382913335356, 2646.9219842158936, + 3275.6300328841903, 3267.723517860167, 3108.6660417988583, + 2707.236633615283, 2261.238243838534, 2675.3550575329255, + 2718.8312488244483, 2795.2638209525658, 3029.2048316829446, + 3526.05668027097, 2912.0119178718123, 2698.701876676361, + 3339.7077781303956, 3331.645473712671, 3169.4755084040094, + 2760.220156003339, 2305.5152561646014, 2727.767051735187, + 2772.121611275301, 2850.079687305263, 3088.6380257998767, + 3595.2726909206885, 2969.202848352279, 2751.729914624193, + 3405.3639628686547, 3397.175806989155, 3231.8471696144416, + 2814.573814049355, 2350.944762299905, 2781.5521630299786, + 2826.8171198655427, 2906.3501907379195, 3149.658424437323, + 3666.3488431688374, 3027.9403954101745, 2806.200924275911, + 3472.8177995713336, 3464.5113649830287, 3295.947518694034, + 2870.4300291282275, 2397.626866904803, 2836.8164043717843, + 2883.012883609583, 2964.16013209073, 3212.343856951581, 3739.3593555297894, + 3088.272327971977, 2862.146641087377, 3542.09304984374, 3533.660377341144, + 3361.769663092581, 2927.7848832785635, 2445.560038551042, + 2893.5600237460094, 2940.711247814249, 3023.5140746817015, + 3276.701600699972, 3814.3154135651407, 3150.2101254688805, + 2919.579781107512, 3613.2080209916153, 3604.6436717895926, 3429.335856447288] + +post_proj_rough_usage = [ + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125, + 0.06949240848461717, 0.06105530803139983, 0.07219488449948883, + 0.07192852387964511, 0.07477935608678944, 0.080351983430903, + 0.09271726925110635, 0.07812743157595603, 0.06752489706279496, + 0.07459548758454597, 0.06980156770223081, 0.07103275487388125] + + +post_bill_rough = { + 'date_from': proforma_date_from, + 'date_to': proforma_date_to, + 'usage': post_proj_rough_usage, + 'charge': post_proj_rough_charge, + 'price': prior_proj_rough_price} # global variables - # inflation coefficient dictionary. this is NOT inflation rate + inflation_coeff_dict = { datetime.date(1981, 1, 31): 0.3381208260704529, datetime.date(1981, 2, 28): 0.3410451203881943, diff --git a/bpfin/utilbills/bill_post_proj_rough.py b/bpfin/utilbills/bill_post_proj_rough.py new file mode 100644 index 0000000000000000000000000000000000000000..5a975f48c88b6c990e28c27cc8e54a7c8489bf27 --- /dev/null +++ b/bpfin/utilbills/bill_post_proj_rough.py @@ -0,0 +1,34 @@ +import datetime +import bpfin.lib.other as lib + + +def bill_post_proj_rough(prior_bill, saving_percent): + """ + Project energy bill, on a monthly_normalized base, + with daily rough estimation, for years that in the past and future, + for one utility type, with savings + + Args: + prior_bill (dictionary): dictionary of lists + {'date_from': prior_bill_start, 'date_to': prior_bill_end, + 'usage': prior_monthly_usage, 'charge': prior_monthly_charge, + 'price': prior_monthly_price} + saving_percent (float): percentage savings. can be negative value + Return: + dictionary: post_bill: dictionary of lists + {'date_from': post_bill_start, 'date_to': post_bill_end, + 'usage': post_monthly_usage, 'charge': post_monthly_charge, + 'price': post_monthly_price} + """ + post_bill_start = prior_bill['date_from'] + post_bill_end = prior_bill['date_to'] + post_monthly_price = prior_bill['price'] + post_monthly_usage = lib.multiply_list(prior_bill['usage'], (1-saving_percent)) + post_monthly_charge = lib.product2list(post_monthly_usage, post_monthly_price) + + return { + 'date_from': post_bill_start, + 'date_to': post_bill_end, + 'usage': post_monthly_usage, + 'charge': post_monthly_charge, + 'price': post_monthly_price} diff --git a/bpfin/utilbills/bill_prior_proj_rough.py b/bpfin/utilbills/bill_prior_proj_rough.py index 95317208ac4b2f3326ecd0c519e472ce5a1c0a09..363bc9fc7013f04c052ca1724c303667f145b727 100644 --- a/bpfin/utilbills/bill_prior_proj_rough.py +++ b/bpfin/utilbills/bill_prior_proj_rough.py @@ -4,8 +4,10 @@ import bpfin.lib.other as lib def bill_prior_proj_rough(month_norm_bill, raw_bill, analysis_date, inflation_coeff_dict): - """ project energy bill, on a monthly_normalized base, - with daily rough estimation, for years that in the past and future + """ + Project energy bill, on a monthly_normalized base, + with daily rough estimation, for years that in the past and future, + for one utility type, without savings Args: month_norm_bill (dictionary): {'monthly_usage':[list of float],