remove num we now use - bill_info[bill_type][num_ann_bills], fix bug where we were re-adding first year bills
This commit is contained in:
50
bills.py
50
bills.py
@@ -9,7 +9,7 @@ def qtr(d):
|
||||
# missing annual bill, find date based on MM-DD and add new year - given we start with first_bill anyway, will only be used for future bill predictions
|
||||
# future only, so add ann_growth (based on drop-down) for each future year
|
||||
# NOTE: only ever called when there is a need to add a new bill
|
||||
def add_missing_annual_bill_in_yr( bill_type, bill_info, num, yr ):
|
||||
def add_missing_annual_bill_in_yr( bill_type, bill_info, yr ):
|
||||
mm_dd = bill_info[bill_type]['last_bill']['bill_date'][5:]
|
||||
amt = bill_info[bill_type]['last_bill']['amount']
|
||||
# okay the missing bill is before the first bill...
|
||||
@@ -22,14 +22,14 @@ def add_missing_annual_bill_in_yr( bill_type, bill_info, num, yr ):
|
||||
|
||||
# missing quarterly bill, find date based on MM-DD and ??? - can have missing bilsl in first year
|
||||
# add growth (based on drop-down) for each future year
|
||||
def add_missing_quarter_bills_in_yr( bill_type, bill_info, num, yr ):
|
||||
print( f"*** add_missing_quarter_bills_in_yr( {bill_type}, bill_info, {num}, {yr} ): NOT YET" )
|
||||
def add_missing_quarter_bills_in_yr( bill_type, bill_info, yr ):
|
||||
print( f"*** add_missing_quarter_bills_in_yr( {bill_type}, bill_info, {yr} ): NOT YET" )
|
||||
return
|
||||
|
||||
# missing monthly bills, find date based on DD and put in each missing month
|
||||
# add growth (based on drop-down) for each future year
|
||||
# NOTE: ALWAYS called for first year - don't always add bills/see below
|
||||
def add_missing_monthly_bills_in_yr( bill_type, bill_info, num, yr ):
|
||||
def add_missing_monthly_bills_in_yr( bill_type, bill_info, yr ):
|
||||
|
||||
# start date arithmetic from first bill (this is possibly an issue if monthly is not
|
||||
# really perfectly the same each month, but its only for an estimate so should be ok
|
||||
@@ -48,19 +48,20 @@ def add_missing_monthly_bills_in_yr( bill_type, bill_info, num, yr ):
|
||||
|
||||
# fill in rest of this year
|
||||
for i in range( start_m+1, 13 ):
|
||||
bill_found=False
|
||||
new_date = f'{yr}-{i:02d}-{dd}'
|
||||
if yr in bill_info[bill_type]['year']:
|
||||
for b in bill_info[bill_type]['year'][yr]:
|
||||
# this bill exists, skip adding it (this occurs when called to
|
||||
# add bilsl as there are < 12 bills in first_year, BUT, we
|
||||
# add bills as there are < 12 bills in first_year, BUT, we
|
||||
# don't fill before first_bill so the < 12 ALWAYS triggers
|
||||
if b['bill_date'] == new_date:
|
||||
continue
|
||||
# grow if we are really adding one
|
||||
amt += amt * growth/100
|
||||
# last param is estimated (and this is an estimate for a future bill / not real)
|
||||
new_bill( bill_type, amt, new_date, 1 )
|
||||
|
||||
if str(b['bill_date']) == new_date:
|
||||
bill_found=True
|
||||
break
|
||||
if not bill_found:
|
||||
amt += amt * growth/100
|
||||
# last param is estimated (and this is an estimate for a future bill / not real)
|
||||
new_bill( bill_type, amt, new_date, 1 )
|
||||
return
|
||||
|
||||
|
||||
@@ -123,23 +124,24 @@ def process_bill_data(bd, bt, bf):
|
||||
# we have all the bills needed for yr
|
||||
if yr in bill_info[bill_type]['year'] and len(bill_info[bill_type]['year'][yr]) == bill_info[bill_type]['num_ann_bills']:
|
||||
continue
|
||||
add_missing_bills_for_yr( bill_type, bill_info, num, yr )
|
||||
derive_ann_growth( bill_type, bill_info, num )
|
||||
add_missing_bills_for_yr( bill_type, bill_info, yr )
|
||||
derive_ann_growth( bill_type, bill_info )
|
||||
|
||||
################################################################################
|
||||
# add_missing_bills_for_yr -- wrapper to call right func based on bill freq
|
||||
################################################################################
|
||||
def add_missing_bills_for_yr( bill_type, bill_info, num, yr ):
|
||||
print(f"{bill_type}: add_missing_bills_for_yr( {bill_type}, bill_info, {num}, {yr} )")
|
||||
def add_missing_bills_for_yr( bill_type, bill_info, yr ):
|
||||
print(f"{bill_type}: add_missing_bills_for_yr( {bill_type}, bill_info, {yr} )")
|
||||
num = bill_info[bill_type]['num_ann_bills']
|
||||
if num == 1:
|
||||
add_missing_annual_bill_in_yr( bill_type, bill_info, num, yr )
|
||||
add_missing_annual_bill_in_yr( bill_type, bill_info, yr )
|
||||
elif num == 4:
|
||||
add_missing_quarter_bills_in_yr( bill_type, bill_info, num, yr )
|
||||
add_missing_quarter_bills_in_yr( bill_type, bill_info, yr )
|
||||
elif num == 12:
|
||||
add_missing_monthly_bills_in_yr( bill_type, bill_info, num, yr )
|
||||
add_missing_monthly_bills_in_yr( bill_type, bill_info, yr )
|
||||
return
|
||||
|
||||
def derive_ann_growth( bill_type, bill_info, num ):
|
||||
def derive_ann_growth( bill_type, bill_info ):
|
||||
print(f"{bill_type}: Derive annual growth on bill_type: {bill_type} " )
|
||||
|
||||
total={}
|
||||
@@ -160,11 +162,11 @@ def derive_ann_growth( bill_type, bill_info, num ):
|
||||
max_growth = 0
|
||||
count = 0
|
||||
for yr in range( bill_info[bill_type]['first_bill_year'], bill_info[bill_type]['last_bill_year']+1):
|
||||
# less than {num} bills in yr: {yr-1}, so can't use data
|
||||
if yr-1 in bill_info[bill_type]['year'] and len(bill_info[bill_type]['year'][yr-1]) != num:
|
||||
# less than {num_ann_bills} bills in yr: {yr-1}, so can't use data
|
||||
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']:
|
||||
continue
|
||||
# less than {num} 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]) != num:
|
||||
# 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
|
||||
|
||||
Reference in New Issue
Block a user