Compare commits

...

8 Commits

Author SHA1 Message Date
e373dd0009 Change approach with Qtr bills, all are simple based on last qtr - when we have normal Qtr bills (freq 'Quarterly') we just use last qtrs data for growth much easier. For GAS, we have the 'Quaterly (forced)' freq. which uses the forced/calc. amount per qtr for growth, its good enough for Gas bills - which dont always have 4 bills a year 2025-08-31 16:32:18 +10:00
3a5b77f12d Change approach with Qtr bills, all are simple based on last qtr - when we have normal Qtr bills (freq 'Quarterly') we just use last qtrs data for growth much easier. For GAS, we have the 'Quaterly (forced)' freq. which uses the forced/calc. amount per qtr for growth, its good enough for Gas bills - which dont always have 4 bills a year 2025-08-31 16:32:00 +10:00
c74383f89e added a commented out simple debug of totals to help understand bills for now - prob will make this into real table somehow in future 2025-08-31 16:29:29 +10:00
4a7080787b new item 2025-08-31 16:28:36 +10:00
07f2a321ec added support for Quarterly (seasonal) and Quarterly (fixed), also updated live DB to match 2025-08-31 11:07:08 +10:00
f67ca61cc7 working through future bills, we need to do quarterly future estimates differently for seasonal/fixed bills 2025-08-31 11:06:29 +10:00
9ad5089ac5 updated README, todo & bugs are now in own files 2025-08-31 11:05:57 +10:00
17f2534056 bug fixed where we had a bill deleted it then growth was still trying to be calc when it no longer could 2025-08-31 10:39:58 +10:00
5 changed files with 64 additions and 26 deletions

12
README
View File

@@ -1,18 +1,8 @@
TODO:
* fix BUGs
* convert code over to use bill_type instead of name in bills.html
CONSIDER in code:
* when we time the payment of GMHBA / HCF (and at what cadence) and include it in calcs better
- it kicks in after pay stops, and could be paid monthly say, but it is higher than if we pay yearly (I think)
* could make bills be paid quarterly rather than as 'daily' living expenses
- also could be more painful with bill increases, they seem to go up more than CPI
CONSIDER in real-world:
* moving > $250k into say ING, then rabo-bank -- 4 months interest higher in each -- maybe to another provider after that
while the balance is > $250k it offsets individual bank risk
* maybe buying shares in something like berkshire-hathaway, or vanguard ETFs?
* pay out car if the diff is negligible to reduce the exposure to > $250k in bank
To run the code:

7
TODO
View File

@@ -1,7 +1,14 @@
UI:
For bills:
* might need to be able to mark a specific bill as an outlier - so we ignore the data somehow (think Gas is messing with my bills)
* estimate future bills/growth:
[DONE] - calculate pragmatic min/avg/max/simple
- need to handle future only bills (like health insurance which only kicks in when I quit)
- might all work - validate why future seems to jump in 2026, but not 27+
- seems specifically 27->28 is way too small compare to growth in
other years, does not seem likely, but maybe qtr timing? (by then they should all be est. though)
- remove bills from Living_Expenses (carefully - but by hand)
- fold future bills into calc so they are taken out in a more time and growth appropriate way
- inflation can then be put to a more realistic quarterly figure

View File

@@ -140,7 +140,7 @@ def new_estimated_bill( bill_info, yr, bill_type, amt, new_date ):
bill['bill_date']=new_date
bill['amount']=amt
bill['estimated']=1
# need this for find_previous_bill to work but only need the above 3 fields
# need to insert(0,) to add this "newest" bill to start of the data for {yr} so that find_previous_bill can work - only need the above 3 fields
bill_info[bill_type]['year'][yr].insert(0,bill)
if bill_info[bill_type]['num_ann_bills'] == 4:
@@ -190,16 +190,35 @@ def add_missing_quarter_bills_in_yr( bill_type, bill_info, yr ):
else:
r=range(1,5)
for q in r:
# amt is total of last year's qtr bill proportion
amt = bill_info[bill_type]['qtr'][yr-1][q]*(1+bill_info[bill_type]['growth']/100)
# just make new bills first of last month of a qtr (good as any date for GAS, they move anyway)
new_date = f'{yr}-{q*3:02d}-01'
# SANITY CHECK: we might be adding a bill estimate we already have (due to stupid gas bills /qtrly code)
if yr in bill_info[bill_type]['year']:
for b in bill_info[bill_type]['year'][yr]:
if b['bill_date'] == new_date:
return
new_estimated_bill( bill_info, yr, bill_type, amt, new_date )
if 'forced' in bill_info[bill_type]['freq']:
actually_add_estimated_new_quarter_bill_forced(bill_type, bill_info, yr, q)
else:
actually_add_estimated_new_quarter_bill(bill_type, bill_info, yr, q)
return
################################################################################
# func take a qtr in a year, finds equiv from previous year, calcs new based on
# it (same 'day' with amt * growth)
################################################################################
def actually_add_estimated_new_quarter_bill( bill_type, bill_info, yr, q ):
# amt is total of last year's qtr bill (NOTE: use 4-q, bills are in desc order)
last_yrs_bill_in_this_q = bill_info[bill_type]['year'][yr-1][4-q]
amt = last_yrs_bill_in_this_q['amount']*(1+bill_info[bill_type]['growth']/100)
# make new qtr bill same 'day' (mm-dd) as last year, just chg (yr)
mmdd=last_yrs_bill_in_this_q['bill_date'][5:]
new_date = f'{yr}-{mmdd}'
new_estimated_bill( bill_info, yr, bill_type, amt, new_date )
return
def actually_add_estimated_new_quarter_bill_forced( bill_type, bill_info, yr, q ):
print( f"Being asked to add a FORCED qtr bill for {yr}-q{q} - likely a GAS bill, as its the only one, *sigh*" )
last_yrs_qtr_amount = bill_info[bill_type]['qtr'][yr-1][q]
print( f"amt is based on forced qtr amount for last year: {last_yrs_qtr_amount}" )
amt=last_yrs_qtr_amount*(1+bill_info[bill_type]['growth']/100)
new_date = f'{yr}-{q*3:02d}-01'
new_estimated_bill( bill_info, yr, bill_type, amt, new_date )
return
# missing monthly bills, find date based on DD and put in each missing month
@@ -281,6 +300,8 @@ def process_bill_data(bd, bt, bf):
# this maps freq to bills per annum (e.g. id=2 to 4 bills per annum)
bf_id_num = {row["id"]: row["num_bills_per_annum"] for row in bf}
# and allows me a way to see if the bill is quarterly but also fixed or seasonal
bf_id_name = {row["id"]: row["name"] for row in bf}
# want to proces all bill data into easier to maniuplate structure, so make
# a bill_info[bill_id] with first_bill, last_bill, [yr] with matching bills to process
@@ -292,6 +313,7 @@ def process_bill_data(bd, bt, bf):
# new bill type
if not bill_type in bill_info:
bill_info[bill_type]={}
bill_info[bill_type]['freq'] = bf_id_name[bt_id_freq[bill_type]]
bill_info[bill_type]['growth'] = get_growth_value( bt, bill_type )
bill_info[bill_type]['num_ann_bills'] = bf_id_num[bt_id_freq[bill_type]]
bill_info[bill_type]['first_bill']={}
@@ -310,7 +332,7 @@ def process_bill_data(bd, bt, bf):
bill_info[bill_type]['first_bill_year']=int(bill['bill_date'][:4])
if not 'last_real_bill_year' in bill_info[bill_type] and not bill['estimated']:
bill_info[bill_type]['last_real_bill_year']=int(bill['bill_date'][:4])
# add this bill to list for this year
# append this bill to list for this year
bill_info[bill_type]['year'][yr].append(bill)
# now process the bill_info from yr of first bill to yr of last bill
@@ -447,7 +469,7 @@ def derive_ann_growth( bill_type, bill_info ):
else:
# okay use last - first / years to get a simple_growth, just need bills from different years
# if there are totals for them (may not be set with monthly and < 12 bills in 1st year)
if bill_info[bill_type]['first_bill_year'] != bill_info[bill_type]['last_real_bill_year'] and bill_info[bill_type]['first_bill_year'] in total and bill_info[bill_type]['last_real_bill_year'] in total:
if 'last_real_bill_year' in bill_info[bill_type] and bill_info[bill_type]['first_bill_year'] != bill_info[bill_type]['last_real_bill_year'] and bill_info[bill_type]['first_bill_year'] in total and bill_info[bill_type]['last_real_bill_year'] in total:
simple_growth=( ((total[bill_info[bill_type]['last_real_bill_year']]-total[bill_info[bill_type]['first_bill_year']])/(bill_info[bill_type]['last_real_bill_year']-bill_info[bill_type]['first_bill_year'])) / total[bill_info[bill_type]['first_bill_year']] )*100.0
set_bill_type_growth( bill_type, 0, 0, 0, simple_growth )
else:
@@ -464,8 +486,10 @@ def calc_future_totals(bill_info, bill_types):
for bt in bill_types:
total[bt['id']]={}
for yr in range( now_yr, END_YEAR+1):
total[bt['id']][yr]=0
total[bt['id']][yr]=0.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']
# had to round to 2 decimal here to get sensible totals
total[bt['id']][yr] = round( total[bt['id']][yr], 2 )
return total

3
db.py
View File

@@ -134,7 +134,8 @@ def init_db():
(4762.29, 10, 24000, 620, 2412, 45824.68, 83738.74, 80000, 424875.26, 4.75, 2.4, 10000, 50000, 10000, 76.85, 1000, 750, 1111, 4.52, 163.32, '2025-06-01', '2025-09-01', '2025-02-20', 4, 0, 0))
cur.execute( "INSERT INTO bill_freq values ( 1, 'Annual', 1 )" )
cur.execute( "INSERT INTO bill_freq values ( 2, 'Quarterly', 4 )" )
cur.execute( "INSERT INTO bill_freq values ( 3, 'Monthly', 12 )" )
cur.execute( "INSERT INTO bill_freq values ( 3, 'Quarterly (forced)', 4 )" )
cur.execute( "INSERT INTO bill_freq values ( 4, 'Monthly', 12 )" )
# start with no specific Tab/bill_type to show, and dont show_estimated
cur.execute( "INSERT INTO bill_ui values ( 1, null, 0 )" )
conn.commit()

View File

@@ -21,6 +21,22 @@
<div class="pt-2 containerfluid row">
<h3 align="center">Bill Details (go to <a href="/">Finance Tracker</a>)</h3>
{# DEBUG totals if needed
<table>
{% for bt in total %}
<tr><td></td><td>&nbsp;{{bt}}:</td>
{% for yr in range( 2025, 2032 ) %}
{% if yr in total[bt] %}
<td>
{{total[bt][yr]}}
</td>
{% endif %}
{% endfor %}
</tr>
{% endfor %}
</table>
#}
<div class="mt-4 col-7">
<div class="row align-items-center">
<button id="new-bill-type-button" class="mb-3 px-0 offset-4 col-2 btn btn-success bg-success-subtle text-success" onCLick="StartNewBillType()"><span class="bi bi-plus-lg"> New Bill Type</span></button>