diff --git a/bpfin/tests/test_utilbills/test_bill_lib.py b/bpfin/tests/test_utilbills/test_bill_lib.py index fa288f25f8071dfb2d5285b8c3331401f4cd5ad9..321befb3e68814d0fabc9d4241059b49d2194718 100644 --- a/bpfin/tests/test_utilbills/test_bill_lib.py +++ b/bpfin/tests/test_utilbills/test_bill_lib.py @@ -1,4 +1,5 @@ -from bpfin.utilbills.bill_lib import add_list +from bpfin.utilbills.bill_lib import add_list, annualizing_projection +from datetime import date, datetime def test_add_list(): @@ -10,3 +11,13 @@ def test_add_list(): assert result_list[i] == output_list[i] +def test_annualizing_projection(): + input_dates = [ + date(2011, 10, 1), date(2011, 4, 4), date(2012, 12, 4), date( + 2014, 9, 5), date(2014, 8, 8), date(2014, 10, 4) + ] + input_values = [100, 200, 300, 400, 500, 600] + output_dictionary = {2011: 300, 2012: 300, 2014: 1500} + result = annualizing_projection(input_dates, input_values) + + assert output_dictionary == result diff --git a/bpfin/utilbills/bill_lib.py b/bpfin/utilbills/bill_lib.py index 272eb160d87fe919ebb665dca5b081aa33843816..c452d273e76c22f71ba3cbaff00785c87ae06346 100644 --- a/bpfin/utilbills/bill_lib.py +++ b/bpfin/utilbills/bill_lib.py @@ -199,3 +199,32 @@ def occupancy_final_list(occupancy_rate_list): for occ in occupancy_rate_list: occupancy_list.append(occ * 24) return occupancy_list + + +def annualizing_projection(dates, values): + """Return annualized values of monthly projections. + Args: + dates (list): list of dates + values (list): list of values + Return: + dictionary: dictionary of annualized values + """ + matching_cal_dict = {} + for i in range(0, len(dates)): + matching_cal_dict[dates[i]] = values[i] + + cal_year = {} + for date, value in matching_cal_dict.items(): + if date.year not in cal_year: + cal_year[date.year] = [] + + for year in cal_year: + for date, value in matching_cal_dict.items(): + if year == date.year: + cal_year[date.year].append(value) + + final_dict = {} + for year, value in cal_year.items(): + final_dict[year] = sum(value) + + return final_dict