From 67c855b731786ea2aaf9f8bd5328c1518aca4df9 Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Sat, 24 May 2025 16:19:29 +1000 Subject: [PATCH] redo the way we do padding to be much more accurate --- db.py | 2 +- main.py | 19 +++++++++++++++++-- templates/index.html | 22 +++++----------------- 3 files changed, 23 insertions(+), 20 deletions(-) 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 @@
2025
- {% set first_yr=2025 %} - {% set started=namespace( val=0 ) %} - {% set mon_cnt=namespace( now=4 ) %} + {# inside started if below, we add blank lines to the start of the year so the dates line up #} + {% for _ in range( 0, padding ) %} +
+ {% endfor %} + {% for date, dollars in savings %} {% set yr=date[:4] %} {% set mon=date[5:7] %} {% set day=date[8:10 ] %} - {# inside started if below, we add blank lines to the start of the year so the dates line up #} - {% if started.val == 0 %} - {% if day|int > 14 %} -
- {% else %} -
-
- {% endif %} - {% for _ in range( 1, 2*mon_cnt.now ) %} -
- {% endfor %} - - {% set started.val = 1 %} - {% endif %} {% if yr|int > first_yr|int and mon == '01' and day|int <= 14 %}