redo the way we do padding to be much more accurate
This commit is contained in:
19
main.py
19
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():
|
||||
|
||||
Reference in New Issue
Block a user