first pass of trying to work through deriving annual growth on bills, what info I need, etc. definitely not even close to finished
This commit is contained in:
41
bills.py
Normal file
41
bills.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from db import get_bill_data, get_bill_types, set_bill_type_growth
|
||||
|
||||
def derive_bill_data():
|
||||
bd=get_bill_data()
|
||||
bt=get_bill_types()
|
||||
water_id = None
|
||||
for t in bt:
|
||||
if t['name'] == "Water":
|
||||
water_id = t['id']
|
||||
|
||||
if not water_id:
|
||||
return
|
||||
total={}
|
||||
total[water_id]={}
|
||||
for yr in [2022, 2023, 2024]:
|
||||
print( f"water_id={water_id}")
|
||||
total[water_id][yr] = 0
|
||||
for b in bd:
|
||||
if b['bill_type_id'] == water_id and str(yr) in b['bill_date']:
|
||||
total[water_id][yr] += b['amount']
|
||||
print( f"{yr} => {b['bill_date']} -- {b['amount']}" )
|
||||
print( f"total for water in {yr} is {total[water_id][yr]}" )
|
||||
|
||||
# once we have all yr totals:
|
||||
growth = {}
|
||||
growth[water_id] = {}
|
||||
max_growth = {}
|
||||
avg_growth = {}
|
||||
max_growth[water_id] = 0
|
||||
avg_growth[water_id] = 0
|
||||
count = 0
|
||||
for yr in [2023, 2024]:
|
||||
growth[water_id][yr] = (total[water_id][yr] - total[water_id][yr-1]) / total[water_id][yr-1] * 100
|
||||
avg_growth[water_id] += growth[water_id][yr]
|
||||
count += 1
|
||||
if growth[water_id][yr] > max_growth[water_id]:
|
||||
max_growth[water_id] = growth[water_id][yr]
|
||||
print( f"growth from {yr} to {yr-1} = {growth}%")
|
||||
print( f"Max growth was: {max_growth[water_id]}" )
|
||||
print( f"Avg growth is: {avg_growth[water_id]/count}" )
|
||||
set_bill_type_growth( water_id, avg_growth[water_id]/count )
|
||||
Reference in New Issue
Block a user