diff --git a/bills.py b/bills.py index f5314c2..9d7b650 100644 --- a/bills.py +++ b/bills.py @@ -71,6 +71,20 @@ def add_missing_monthly_bills_in_yr( bill_type, bill_info, yr ): new_bill( bill_type, amt, new_date, 1 ) return +# given the bill_type has a which_growth contain min/avg/max, return the corresponding growth number +def get_growth_value( bt, bill_type ): + for el in bt: + if el['id'] == bill_type: + which = el['which_growth'] + break + + if which == 'avg': + return el['ann_growth_avg'] + elif which == 'min': + return el['ann_growth_min'] + else: + return el['ann_growth_max'] + # go through the bill data from the DB, put it into more friendly formats, then # work out and then add missing bill data (might be b/c we have monthly bills, @@ -94,7 +108,7 @@ def process_bill_data(bd, bt, bf): # new bill type if not bill_type in bill_info: bill_info[bill_type]={} - bill_info[bill_type]['growth'] = bt_id_ann_growth_avg[bill_type] + bill_info[bill_type]['growth'] = get_growth_value( bt, bill_type ) bill_info[bill_type]['num_ann_bills'] = bf_id_num[bt_id_freq[bill_type]] bill_info[bill_type]['first_bill']={} bill_info[bill_type]['last_bill']={} diff --git a/db.py b/db.py index 4208ced..3388e60 100644 --- a/db.py +++ b/db.py @@ -278,6 +278,16 @@ def get_bill_types(): conn.close() return bt +def use_growth( bill_type, which_growth ): + conn = connect_db(False) + cur = conn.cursor() + cur.execute( f"update bill_type set which_growth = '{which_growth}' where id = {bill_type}" ) + # okay, new growth type being used, delete old estimated bills are recreate them + cur.execute( f"delete from bill_data where estimated=1 and bill_type = {bill_type}" ) + conn.commit() + conn.close() + return + def get_bill_freqs(): conn = connect_db(True) cur = conn.cursor() diff --git a/main.py b/main.py index 34ca79a..520c9d3 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,7 @@ from flask import Flask, render_template, request, redirect, url_for, Response, 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, get_bill_freqs from db import get_bill_data, new_bill, update_bill_data, delete_bill -from db import get_bill_types, insert_bill_type, update_bill_type, delete_bill_type +from db import get_bill_types, insert_bill_type, update_bill_type, delete_bill_type, use_growth from bills import process_bill_data from collections import defaultdict, Counter from datetime import datetime @@ -185,6 +185,12 @@ def DeleteBill(): delete_bill( data['id'] ) return "200" +@app.route('/usegrowth', methods=['POST']) +def UseGrowth(): + data = request.get_json() + use_growth( data['bill_type'], data['which_growth'] ) + return "200" + # Main program if __name__ == '__main__': app.run(debug=True) diff --git a/templates/bills.html b/templates/bills.html index 650ddc3..e85d7c0 100644 --- a/templates/bills.html +++ b/templates/bills.html @@ -54,18 +54,21 @@
- -