Compare commits
3 Commits
3d95cd1d2e
...
19cba866de
| Author | SHA1 | Date | |
|---|---|---|---|
| 19cba866de | |||
| cd7eca0c6e | |||
| c469f6d281 |
14
TODO
14
TODO
@@ -1,6 +1,6 @@
|
|||||||
For bills:
|
For bills:
|
||||||
* using frequency and known bills fill in missing gaps
|
* using frequency and known bills fill in missing gaps
|
||||||
-- need to add to DB whether the bill was added manually or auto-flled in (so if we want, we can re-calc. based on growth calc change as we add more real bills over time?)
|
[DONE] -- need to add to DB whether the bill was added manually or auto-flled in (so if we want, we can re-calc. based on growth calc change as we add more real bills over time?)
|
||||||
* need to work out 'first bill' and 'last bill' to auto-fill missing bills based on
|
* need to work out 'first bill' and 'last bill' to auto-fill missing bills based on
|
||||||
-- all missing bills follow varying growth models & its by choice -- therefore I need this in DB
|
-- all missing bills follow varying growth models & its by choice -- therefore I need this in DB
|
||||||
- ANN: flat, min, avg, max, manual
|
- ANN: flat, min, avg, max, manual
|
||||||
@@ -14,11 +14,15 @@ For bills:
|
|||||||
-- ANN: future only, so add ann_growth (based on drop-down) for each future year
|
-- ANN: future only, so add ann_growth (based on drop-down) for each future year
|
||||||
-- QTR: add growth (based on drop-down) for each future year
|
-- QTR: add growth (based on drop-down) for each future year
|
||||||
-- MON: add growth (based on drop-down) for each future year
|
-- MON: add growth (based on drop-down) for each future year
|
||||||
|
-- Pragmatical growth before I bonkers:
|
||||||
|
[DONE] - monthly, prob. just flat by default (simple 1 or 12 bills for the year each year and I can get a growth rate from that)
|
||||||
|
[DONE] - and apply monthly growth - annually 12 + months from last bill each year
|
||||||
|
[DONE]- qty - manual only
|
||||||
|
[DONE]- annual easy
|
||||||
* once auto-filled bills exist:
|
* once auto-filled bills exist:
|
||||||
- calc growth [DONE]
|
[DONE]- calc growth
|
||||||
-- WARNING: could be chicken/egg here, if not enough bills to calc growth - maybe only offer flat/manual until there are enough??
|
- project out to I am 60 (A/Q/M) - A/Q done, M to go
|
||||||
- project out to I am 60
|
[DONE] - probably need to allow a toggle to: allow show manual, show auto-filled past, show auto-filled future, show all
|
||||||
- probably need to allow a toggle to: allow show manual, show auto-filled past, show auto-filled future, show all
|
|
||||||
- remove bills from Living_Expenses (carefully - but by hand)
|
- 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
|
- 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
|
- inflation can then be put to a more realistic quarterly figure
|
||||||
|
|||||||
46
bills.py
46
bills.py
@@ -35,11 +35,13 @@ def add_missing_monthly_bills_in_yr( bill_type, bill_info, yr ):
|
|||||||
# really perfectly the same each month, but its only for an estimate so should be ok
|
# really perfectly the same each month, but its only for an estimate so should be ok
|
||||||
dd = bill_info[bill_type]['first_bill']['bill_date'][8:]
|
dd = bill_info[bill_type]['first_bill']['bill_date'][8:]
|
||||||
mm = bill_info[bill_type]['first_bill']['bill_date'][5:7]
|
mm = bill_info[bill_type]['first_bill']['bill_date'][5:7]
|
||||||
|
lb_mm = bill_info[bill_type]['last_bill']['bill_date'][5:7]
|
||||||
|
|
||||||
# choose last bill from last amount to grow from as its most relevant
|
# choose last bill from last amount to grow from as its most relevant
|
||||||
amt = bill_info[bill_type]['last_bill']['amount']
|
if not 'last_bill_amount' in bill_info[bill_type]:
|
||||||
|
bill_info[bill_type]['last_bill_amount']=bill_info[bill_type]['last_bill']['amount']
|
||||||
|
amt = bill_info[bill_type]['last_bill_amount']
|
||||||
|
|
||||||
growth=0
|
|
||||||
#okay add monthly bills for the rest of this year if its the first year
|
#okay add monthly bills for the rest of this year if its the first year
|
||||||
if bill_info[bill_type]['first_bill_year'] == yr:
|
if bill_info[bill_type]['first_bill_year'] == yr:
|
||||||
start_m=int(mm)
|
start_m=int(mm)
|
||||||
@@ -59,7 +61,12 @@ def add_missing_monthly_bills_in_yr( bill_type, bill_info, yr ):
|
|||||||
bill_found=True
|
bill_found=True
|
||||||
break
|
break
|
||||||
if not bill_found:
|
if not bill_found:
|
||||||
amt += amt * growth/100
|
# if this month is the same as the last bill month and as per above
|
||||||
|
# we don't have a bill for this date, then add annual grotwh
|
||||||
|
if i == int(lb_mm):
|
||||||
|
print(f"its month: {i} - time to add growth: {bill_info[bill_type]['growth']}" )
|
||||||
|
amt += amt * bill_info[bill_type]['growth']/100
|
||||||
|
bill_info[bill_type]['last_bill_amount']=amt
|
||||||
# last param is estimated (and this is an estimate for a future bill / not real)
|
# last param is estimated (and this is an estimate for a future bill / not real)
|
||||||
new_bill( bill_type, amt, new_date, 1 )
|
new_bill( bill_type, amt, new_date, 1 )
|
||||||
return
|
return
|
||||||
@@ -94,6 +101,9 @@ def process_bill_data(bd, bt, bf):
|
|||||||
# due to sql sorting, this first instance is the last bill
|
# due to sql sorting, this first instance is the last bill
|
||||||
bill_info[bill_type]['last_bill']=bill
|
bill_info[bill_type]['last_bill']=bill
|
||||||
bill_info[bill_type]['last_bill_year']=int(bill['bill_date'][:4])
|
bill_info[bill_type]['last_bill_year']=int(bill['bill_date'][:4])
|
||||||
|
if not bill['estimated']:
|
||||||
|
print( f"this bill is real, its the first so consider it the last bill paid - date is: {int(bill['bill_date'][:4])}" )
|
||||||
|
bill_info[bill_type]['last_real_bill_year']=int(bill['bill_date'][:4])
|
||||||
bill_info[bill_type]['year']={}
|
bill_info[bill_type]['year']={}
|
||||||
bill_info[bill_type]['year_real']={}
|
bill_info[bill_type]['year_real']={}
|
||||||
if not yr in bill_info[bill_type]['year']:
|
if not yr in bill_info[bill_type]['year']:
|
||||||
@@ -103,6 +113,9 @@ def process_bill_data(bd, bt, bf):
|
|||||||
# keep updating last to this matching bill
|
# keep updating last to this matching bill
|
||||||
bill_info[bill_type]['first_bill']=bill
|
bill_info[bill_type]['first_bill']=bill
|
||||||
bill_info[bill_type]['first_bill_year']=int(bill['bill_date'][:4])
|
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']:
|
||||||
|
print( f"{bill_type}: seems we dont have a last_real_bill_year, set it to: {int(bill['bill_date'][:4])} ")
|
||||||
|
bill_info[bill_type]['last_real_bill_year']=int(bill['bill_date'][:4])
|
||||||
# add this bill to list for this year
|
# add this bill to list for this year
|
||||||
bill_info[bill_type]['year'][yr].append(bill)
|
bill_info[bill_type]['year'][yr].append(bill)
|
||||||
if not bill['estimated']:
|
if not bill['estimated']:
|
||||||
@@ -142,11 +155,20 @@ def add_missing_bills_for_yr( bill_type, bill_info, yr ):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def derive_ann_growth( bill_type, bill_info ):
|
def derive_ann_growth( bill_type, bill_info ):
|
||||||
print(f"{bill_type}: Derive annual growth on bill_type: {bill_type} " )
|
print(f"{bill_type}: Derive annual growth on bill_type: {bill_type} - fby={bill_info[bill_type]['first_bill_year']}, lby={bill_info[bill_type]['last_real_bill_year']} " )
|
||||||
|
|
||||||
total={}
|
total={}
|
||||||
for yr in range( bill_info[bill_type]['first_bill_year'], bill_info[bill_type]['last_bill_year']+1):
|
for yr in range( bill_info[bill_type]['first_bill_year'], bill_info[bill_type]['last_real_bill_year']+1):
|
||||||
if len(bill_info[bill_type]['year_real'][yr]) != bill_info[bill_type]['num_ann_bills']:
|
# for monthly bills, 1 or 12 bills is enough to work with
|
||||||
|
if bill_info[bill_type]['num_ann_bills'] == 12:
|
||||||
|
if len(bill_info[bill_type]['year_real'][yr]) != 1 and len(bill_info[bill_type]['year_real'][yr]) != 12:
|
||||||
|
continue;
|
||||||
|
# okay annual or quarterly bills, only total them if we have all of them for the year
|
||||||
|
elif len(bill_info[bill_type]['year_real'][yr]) != bill_info[bill_type]['num_ann_bills']:
|
||||||
|
continue;
|
||||||
|
|
||||||
|
# for monthlys add totals regardless (we only process total if there is 12 or 1 further below). Other bill_types, only total if there is all bills for year
|
||||||
|
if bill_info[bill_type]['num_ann_bills'] != 12 and len(bill_info[bill_type]['year_real'][yr]) != bill_info[bill_type]['num_ann_bills']:
|
||||||
continue
|
continue
|
||||||
total[yr] = 0
|
total[yr] = 0
|
||||||
for b in bill_info[bill_type]['year'][yr]:
|
for b in bill_info[bill_type]['year'][yr]:
|
||||||
@@ -161,15 +183,9 @@ def derive_ann_growth( bill_type, bill_info ):
|
|||||||
avg_growth = 0
|
avg_growth = 0
|
||||||
max_growth = 0
|
max_growth = 0
|
||||||
count = 0
|
count = 0
|
||||||
for yr in range( bill_info[bill_type]['first_bill_year'], bill_info[bill_type]['last_bill_year']+1):
|
# start from year after first bill, so we can see annual growth from the following year onwards
|
||||||
# less than {num_ann_bills} bills in yr: {yr-1}, so can't use data
|
for yr in range( bill_info[bill_type]['first_bill_year']+1, bill_info[bill_type]['last_bill_year']+1):
|
||||||
if yr-1 in bill_info[bill_type]['year'] and len(bill_info[bill_type]['year'][yr-1]) != bill_info[bill_type]['num_ann_bills']:
|
# if full data sets for consecutive years, work out annual growth stats
|
||||||
continue
|
|
||||||
# less than {num_ann_bills} bills in yr: {yr-1}, so can't use data
|
|
||||||
if yr in bill_info[bill_type]['year'] and len(bill_info[bill_type]['year'][yr]) != bill_info[bill_type]['num_ann_bills']:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# we full data sets for consecutive years, work out annual growth stats
|
|
||||||
if yr-1 in total and yr in total:
|
if yr-1 in total and yr in total:
|
||||||
growth = (total[yr] - total[yr-1]) / total[yr-1] * 100
|
growth = (total[yr] - total[yr-1]) / total[yr-1] * 100
|
||||||
avg_growth += growth
|
avg_growth += growth
|
||||||
|
|||||||
2
db.py
2
db.py
@@ -290,7 +290,7 @@ def get_bill_freqs():
|
|||||||
def new_bill( bill_type, amount, bill_date, estimated ):
|
def new_bill( bill_type, amount, bill_date, estimated ):
|
||||||
conn = connect_db(False)
|
conn = connect_db(False)
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
cur.execute( f"insert into bill_data ( 'bill_type', 'amount', 'bill_date', 'estimated' ) values ( '{bill_type}', '{amount}', '{bill_date}', {estimated} )" )
|
cur.execute( f"insert into bill_data ( 'bill_type', 'amount', 'bill_date', 'estimated' ) values ( '{bill_type}', '{amount:.2f}', '{bill_date}', {estimated} )" )
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user