diff --git a/db.py b/db.py index 4107513..7a0180d 100644 --- a/db.py +++ b/db.py @@ -90,7 +90,7 @@ def init_db(): if cur.fetchone()[0] == 0: ### # For now manually update below on the fortnight of the original pay shcedule to compare saved version vs. our reality. Update: - # Savings (Macq+me bank) -- noting ME bank is: $1329.68 + # Savings (Macq+me bank) -- noting ME bank is: $1434.3 # TLS/CBA prices # Interest rate # D_leave_owed_in_days diff --git a/main.py b/main.py index 0c3bcbe..45b24d1 100644 --- a/main.py +++ b/main.py @@ -2,7 +2,7 @@ from flask import Flask, render_template, request, redirect, url_for, Response, jsonify from calc import calculate_savings_depletion from db import init_db, get_finance_data, update_finance, get_budget_data, insert_cset, get_comp_set_data, get_comp_set_options -from collections import defaultdict +from collections import defaultdict, Counter from datetime import datetime import csv import io @@ -80,7 +80,22 @@ def index(): DISP.append(r) now=datetime.today().strftime('%Y-%m-%d') - return render_template('index.html', now=now, finance=finance_data, depletion_date=depletion_date, savings=savings_per_fortnight, BUDGET=BUDGET, COMP=COMP, DISP=DISP) + + # Extract years from the date strings + years = [datetime.strptime(date, "%Y-%m-%d").year for date, _ in savings_per_fortnight] + + # Count how many times each year appears + year_counts = Counter(years) + # Sort the items by year + sorted_years = sorted(year_counts.items()) # List of (year, count) tuples + + # Access the first and second years + first_yr, first_count = sorted_years[0] + second_yr, second_count = sorted_years[1] + + # now work out how much padding we need in the first year to align the last dates for all years + padding=second_count - first_count + return render_template('index.html', now=now, first_yr=first_yr, padding=padding, finance=finance_data, depletion_date=depletion_date, savings=savings_per_fortnight, BUDGET=BUDGET, COMP=COMP, DISP=DISP) @app.route('/save', methods=['POST']) def save(): diff --git a/templates/index.html b/templates/index.html index 1e20a96..ace8685 100644 --- a/templates/index.html +++ b/templates/index.html @@ -93,27 +93,15 @@