add annotations properly now
This commit is contained in:
24
calc.py
24
calc.py
@@ -1,9 +1,9 @@
|
||||
# calc.py
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
# this somehow needs to connect the annotation, so maybe store it via date in an annotations array?
|
||||
# not sure I need amount, etc.
|
||||
def add_annotation(label,amount):
|
||||
def add_annotation(finance, dt, amt, text):
|
||||
tm = dt.timestamp() * 1000
|
||||
finance['annotations'].append( { 'label': text, 'x': tm, 'y': amt } )
|
||||
return
|
||||
|
||||
def calculate_savings_depletion(finance):
|
||||
@@ -74,6 +74,10 @@ def calculate_savings_depletion(finance):
|
||||
fortnight_income = 0
|
||||
monthly_interest = 0
|
||||
|
||||
# Create an empty dict to store annotations to display in the GUI
|
||||
# (key is date, text is for larger spend items by hand)
|
||||
finance['annotations']=[]
|
||||
|
||||
while current_date <= end_date:
|
||||
#paid on 8th or 22nd of Jan (so 8th day of fortnight)
|
||||
is_fortnight = (days_count % 14 == 7)
|
||||
@@ -121,28 +125,28 @@ def calculate_savings_depletion(finance):
|
||||
|
||||
if current_date.date() == school_fees_date.date():
|
||||
current_savings -= School_Fees
|
||||
print(f"school fees={current_date} - {School_Fees}")
|
||||
add_annotation(finance, current_date, current_savings, f"Pay School Fees: ${School_Fees}")
|
||||
|
||||
if current_date.date() == car_balloon_date.date():
|
||||
current_savings -= Car_balloon
|
||||
print(f"car balloon paid={current_date} - {Car_balloon}")
|
||||
add_annotation(finance, current_date, current_savings, f"car balloon paid: ${Car_balloon}" )
|
||||
|
||||
# Anniversary of Car balloon so pay insurance/rego
|
||||
if current_date.year >= car_balloon_date.year and current_date.month == car_balloon_date.month and current_date.day == car_balloon_date.day:
|
||||
print(f"time to pay IONIQ 6 insurance/rego of: {post_lease_car_costs}" )
|
||||
current_savings -= post_lease_car_costs
|
||||
add_annotation(finance, current_date, current_savings, f"IONIQ 6 ins/rego: ${post_lease_car_costs}" )
|
||||
|
||||
if current_date.date() == overseas_trip_date.date():
|
||||
current_savings -= Overseas_trip
|
||||
print(f"overseas_trip={current_date} - {Overseas_trip}")
|
||||
add_annotation(finance, current_date, current_savings, f"Overseas trip: ${Overseas_trip}")
|
||||
|
||||
if current_date.date() == mich_present_date.date():
|
||||
current_savings -= Mich_present
|
||||
print(f"Mich_present={current_date} - {Mich_present}")
|
||||
add_annotation(finance, current_date, current_savings, f"Michelle's present: ${Mich_present}")
|
||||
|
||||
if current_date.date() == mark_reno_date.date():
|
||||
current_savings -= Mark_reno
|
||||
print(f"Mark/reno costs={current_date} - {Mark_reno}")
|
||||
add_annotation(finance, current_date, current_savings, f"Mark/reno costs: ${Mark_reno}")
|
||||
|
||||
if current_savings < 0:
|
||||
depletion_date = current_date
|
||||
@@ -172,8 +176,8 @@ def calculate_savings_depletion(finance):
|
||||
D_CBA_shares -= 1
|
||||
Sell_shares -= 1
|
||||
|
||||
print( f"SELLING SHARES {current_date}: D_TLS={D_TLS_shares}, D_CBA={D_CBA_shares}" )
|
||||
current_savings += actual_sell
|
||||
add_annotation(finance, current_date, current_savings, f"Selling shares: ${int(actual_sell)}" )
|
||||
|
||||
|
||||
current_date += timedelta(days=1)
|
||||
|
||||
@@ -190,24 +190,22 @@
|
||||
|
||||
// Add annotations for changes greater than 5000
|
||||
const annotations = [];
|
||||
for (let i = 1; i < chartData.length; i++) {
|
||||
const previousAmount = chartData[i - 1][1];
|
||||
const currentAmount = chartData[i][1];
|
||||
const difference = Math.abs(currentAmount - previousAmount);
|
||||
if (difference > 5000) {
|
||||
{% for a in finance['annotations'] %}
|
||||
console.log( "{{a['x']}}" )
|
||||
console.log( "{{a['y']}}" )
|
||||
console.log( "{{a['label']}}" )
|
||||
annotations.push({
|
||||
labels: [{
|
||||
point: {
|
||||
x: chartData[i][0], // Time of the data point
|
||||
y: chartData[i][1], // Amount at that point
|
||||
x: {{a['x']}},
|
||||
y: {{a['y']}},
|
||||
xAxis: 0,
|
||||
yAxis: 0
|
||||
},
|
||||
text: `Change: ${difference.toFixed(2)}` // Annotation text
|
||||
text: '{{a['label']}}'
|
||||
}]
|
||||
});
|
||||
}
|
||||
}
|
||||
{% endfor %}
|
||||
|
||||
// Highcharts configuration
|
||||
Highcharts.chart('container', {
|
||||
|
||||
Reference in New Issue
Block a user