Compare commits
3 Commits
3b3c42caab
...
94f4108a3e
| Author | SHA1 | Date | |
|---|---|---|---|
| 94f4108a3e | |||
| 8d2809fdd9 | |||
| 2d1dcfffd9 |
46
calc.py
46
calc.py
@@ -1,9 +1,11 @@
|
||||
# calc.py
|
||||
from datetime import datetime, timedelta
|
||||
from defines import END_YEAR
|
||||
from db import get_historical_data
|
||||
|
||||
# GLOBAL CONSTANTS
|
||||
LEASE = 0
|
||||
ANNOT_LIMIT = 1000
|
||||
|
||||
# Dates that don't change
|
||||
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
|
||||
if b['bill_date'] == day_str:
|
||||
amt += b['amount']
|
||||
if b['amount'] > 1000:
|
||||
if b['amount'] > ANNOT_LIMIT:
|
||||
n=bt_id_name[ b['bill_type'] ]
|
||||
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}" )
|
||||
@@ -31,7 +33,6 @@ def bill_amount_today(finance, day, bill_data, bt_id_name, total ):
|
||||
return amt
|
||||
|
||||
def add_annotation(finance, dt, total, delta, text):
|
||||
# dont add an annotation for small changes (jic)
|
||||
tm = dt.timestamp() * 1000
|
||||
if delta > 0:
|
||||
text += f": ${int(abs(delta))}"
|
||||
@@ -315,3 +316,44 @@ def calc_key_dates( finance ):
|
||||
|
||||
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
|
||||
|
||||
3
main.py
3
main.py
@@ -1,6 +1,6 @@
|
||||
# main.py
|
||||
from flask import Flask, render_template, request, redirect, url_for, Response, jsonify
|
||||
from calc import calculate_savings_depletion, calc_key_dates
|
||||
from calc import calculate_savings_depletion, calc_key_dates, add_historical_annotations
|
||||
from db import init_db, get_historical_data, get_finance_data, update_finance, get_budget_data
|
||||
from db import insert_cset, get_comp_set_data, get_comp_set_options, delete_cset
|
||||
from db import get_bill_freqs, get_bill_growth_types
|
||||
@@ -32,6 +32,7 @@ def index():
|
||||
bill_data = get_bill_data("order_by_date_only")
|
||||
bill_types = get_bill_types()
|
||||
depletion_date, savings_per_fortnight, final_savings = calculate_savings_depletion(finance_data, bill_data, bill_types)
|
||||
add_historical_annotations( finance_data )
|
||||
BUDGET=get_budget_data(finance_data)
|
||||
|
||||
if depletion_date:
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
<style>
|
||||
.col-form-label { width:140px; }
|
||||
html { font-size: 75% !important; }
|
||||
@media (max-width: 2000px) { html { font-size: 70% !important; } }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -340,6 +341,7 @@
|
||||
xAxis: {
|
||||
type: 'datetime',
|
||||
title: { text: 'Date' },
|
||||
min: Date.UTC(2024, 6, 1),
|
||||
plotBands: plotBands // Alternating background for years
|
||||
},
|
||||
yAxis: { title: { text: 'Amount ($)' } },
|
||||
|
||||
Reference in New Issue
Block a user