From de32bdc7ff3982c9dc597129ccbce5bc52af16c2 Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Sat, 30 Aug 2025 13:58:29 +1000 Subject: [PATCH] now have a calc_future_totals func that is used to allow html to show the bills as a simple annualised cost per year --- bills.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bills.py b/bills.py index 2d27512..8cf7291 100644 --- a/bills.py +++ b/bills.py @@ -329,6 +329,7 @@ def process_bill_data(bd, bt, bf): continue add_missing_bills_for_yr( bill_type, bill_info, yr ) derive_ann_growth( bill_type, bill_info ) + return bill_info ################################################################################ # add_missing_bills_for_yr -- wrapper to call right func based on bill freq @@ -444,3 +445,19 @@ def derive_ann_growth( bill_type, bill_info ): else: # failsafe (just in case fill bills failed to add enough bills to average out) print( f"{bill_type}: Unable to calculate growth!" ) + +################################################################################ +# just go through this year to END_YEAR, total any bills for each year up +# so we can display the annual estimated bills onwards... +################################################################################ +def calc_future_totals(bill_info, bill_types): + total={} + now_yr = datetime.date.today().year + for bt in bill_types: + total[bt['id']]={} + for yr in range( now_yr, END_YEAR+1): + total[bt['id']][yr]=0 + if bt['id'] in bill_info and yr in bill_info[bt['id']]['year']: + for b in bill_info[bt['id']]['year'][yr]: + total[bt['id']][yr] += b['amount'] + return total