some minor clean-ups and make ANNOT_LIMIT constant, and then adding in historical annotations

This commit is contained in:
2026-01-17 22:52:37 +11:00
parent 2d1dcfffd9
commit 8d2809fdd9

46
calc.py
View File

@@ -1,9 +1,11 @@
# calc.py # calc.py
from datetime import datetime, timedelta from datetime import datetime, timedelta
from defines import END_YEAR from defines import END_YEAR
from db import get_historical_data
# GLOBAL CONSTANTS # GLOBAL CONSTANTS
LEASE = 0 LEASE = 0
ANNOT_LIMIT = 1000
# Dates that don't change # Dates that don't change
first_pay_date = datetime(2026,1,8) first_pay_date = datetime(2026,1,8)
@@ -20,7 +22,7 @@ def bill_amount_today(finance, day, bill_data, bt_id_name, total ):
# there may be more than one bill on this day, keep add amount and keep going in loop # there may be more than one bill on this day, keep add amount and keep going in loop
if b['bill_date'] == day_str: if b['bill_date'] == day_str:
amt += b['amount'] amt += b['amount']
if b['amount'] > 1000: if b['amount'] > ANNOT_LIMIT:
n=bt_id_name[ b['bill_type'] ] n=bt_id_name[ b['bill_type'] ]
print( f"bill_amt_today {n} for {day_str} has amt={b['amount']}" ) print( f"bill_amt_today {n} for {day_str} has amt={b['amount']}" )
add_annotation(finance, day, total-b['amount'], -b['amount'], f"Pay {n}" ) add_annotation(finance, day, total-b['amount'], -b['amount'], f"Pay {n}" )
@@ -31,7 +33,6 @@ def bill_amount_today(finance, day, bill_data, bt_id_name, total ):
return amt return amt
def add_annotation(finance, dt, total, delta, text): def add_annotation(finance, dt, total, delta, text):
# dont add an annotation for small changes (jic)
tm = dt.timestamp() * 1000 tm = dt.timestamp() * 1000
if delta > 0: if delta > 0:
text += f": ${int(abs(delta))}" text += f": ${int(abs(delta))}"
@@ -315,3 +316,44 @@ def calc_key_dates( finance ):
return key_dates return key_dates
################################################################################
# go through finance_history table, find big items to make annoations from
################################################################################
def add_historical_annotations( finance ):
added={}
hist=get_historical_data()
day=hist[0]['M_payout_date'];
amt=hist[0]['M_payout'];
dt = datetime.strptime(day, "%Y-%m-%d")
# cover Mandys resignation
add_annotation(finance, dt, hist[0]['Savings']+amt, amt, "M Resigned" )
# cover O/S trip
for h in hist:
if 'Overseas_trip' in h and h['Overseas_trip']:
last_mpd=h['Overseas_trip_date']
last_mpd_savings=h['Savings']
snap_dt=datetime.strptime(h['snapshot_date'], "%Y-%m-%d")
# keep every savings value until we find the last one before the school fees are paid
if snap_dt < school_fees_date:
savings_b4_sfd = h['Savings']
dt = datetime.strptime(last_mpd, "%Y-%m-%d")
# HARDCODING this, based on post-analysis of CC charges (AND this dt is post most of the spend, so dont adjust)
amt = 33405.01
print( f"last_mpd_savings={last_mpd_savings}" )
add_annotation(finance, dt, last_mpd_savings, -amt, "O/S trip" )
print( f"should have added o/s trip (-{amt}) - lpd {last_mpd} == {dt}, savings = {last_mpd_savings}" )
# cover School Fees for 2025
amt = hist[0]['School_Fees']
print( f"savings_b4_sfd ={savings_b4_sfd}")
add_annotation(finance, school_fees_date, savings_b4_sfd-amt, -amt, "Pay school fees" )
# go through bills from oldest historical date until 'today' and add any > AMT_LIMIT
return