add annotations properly now
This commit is contained in:
26
calc.py
26
calc.py
@@ -1,11 +1,11 @@
|
|||||||
# calc.py
|
# calc.py
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
# this somehow needs to connect the annotation, so maybe store it via date in an annotations array?
|
def add_annotation(finance, dt, amt, text):
|
||||||
# not sure I need amount, etc.
|
tm = dt.timestamp() * 1000
|
||||||
def add_annotation(label,amount):
|
finance['annotations'].append( { 'label': text, 'x': tm, 'y': amt } )
|
||||||
return
|
return
|
||||||
|
|
||||||
def calculate_savings_depletion(finance):
|
def calculate_savings_depletion(finance):
|
||||||
# Extract all the financial data from the database
|
# Extract all the financial data from the database
|
||||||
D_Salary = finance['D_Salary']
|
D_Salary = finance['D_Salary']
|
||||||
@@ -74,6 +74,10 @@ def calculate_savings_depletion(finance):
|
|||||||
fortnight_income = 0
|
fortnight_income = 0
|
||||||
monthly_interest = 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:
|
while current_date <= end_date:
|
||||||
#paid on 8th or 22nd of Jan (so 8th day of fortnight)
|
#paid on 8th or 22nd of Jan (so 8th day of fortnight)
|
||||||
is_fortnight = (days_count % 14 == 7)
|
is_fortnight = (days_count % 14 == 7)
|
||||||
@@ -121,28 +125,28 @@ def calculate_savings_depletion(finance):
|
|||||||
|
|
||||||
if current_date.date() == school_fees_date.date():
|
if current_date.date() == school_fees_date.date():
|
||||||
current_savings -= School_Fees
|
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():
|
if current_date.date() == car_balloon_date.date():
|
||||||
current_savings -= Car_balloon
|
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
|
# 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:
|
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
|
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():
|
if current_date.date() == overseas_trip_date.date():
|
||||||
current_savings -= Overseas_trip
|
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():
|
if current_date.date() == mich_present_date.date():
|
||||||
current_savings -= Mich_present
|
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():
|
if current_date.date() == mark_reno_date.date():
|
||||||
current_savings -= Mark_reno
|
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:
|
if current_savings < 0:
|
||||||
depletion_date = current_date
|
depletion_date = current_date
|
||||||
@@ -172,8 +176,8 @@ def calculate_savings_depletion(finance):
|
|||||||
D_CBA_shares -= 1
|
D_CBA_shares -= 1
|
||||||
Sell_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
|
current_savings += actual_sell
|
||||||
|
add_annotation(finance, current_date, current_savings, f"Selling shares: ${int(actual_sell)}" )
|
||||||
|
|
||||||
|
|
||||||
current_date += timedelta(days=1)
|
current_date += timedelta(days=1)
|
||||||
|
|||||||
@@ -190,24 +190,22 @@
|
|||||||
|
|
||||||
// Add annotations for changes greater than 5000
|
// Add annotations for changes greater than 5000
|
||||||
const annotations = [];
|
const annotations = [];
|
||||||
for (let i = 1; i < chartData.length; i++) {
|
{% for a in finance['annotations'] %}
|
||||||
const previousAmount = chartData[i - 1][1];
|
console.log( "{{a['x']}}" )
|
||||||
const currentAmount = chartData[i][1];
|
console.log( "{{a['y']}}" )
|
||||||
const difference = Math.abs(currentAmount - previousAmount);
|
console.log( "{{a['label']}}" )
|
||||||
if (difference > 5000) {
|
annotations.push({
|
||||||
annotations.push({
|
labels: [{
|
||||||
labels: [{
|
point: {
|
||||||
point: {
|
x: {{a['x']}},
|
||||||
x: chartData[i][0], // Time of the data point
|
y: {{a['y']}},
|
||||||
y: chartData[i][1], // Amount at that point
|
xAxis: 0,
|
||||||
xAxis: 0,
|
yAxis: 0
|
||||||
yAxis: 0
|
},
|
||||||
},
|
text: '{{a['label']}}'
|
||||||
text: `Change: ${difference.toFixed(2)}` // Annotation text
|
}]
|
||||||
}]
|
});
|
||||||
});
|
{% endfor %}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Highcharts configuration
|
// Highcharts configuration
|
||||||
Highcharts.chart('container', {
|
Highcharts.chart('container', {
|
||||||
|
|||||||
Reference in New Issue
Block a user