Spaces:
Sleeping
Sleeping
File size: 2,032 Bytes
7068b71 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import streamlit as st
import datetime
# Initialize session state
if "balance" not in st.session_state:
st.session_state.balance = 0
if "transactions" not in st.session_state:
st.session_state.transactions = []
if "multiple" not in st.session_state:
st.session_state.multiple = 5 # default multiple
# Function to calculate round-up
def round_up(transaction, multiple):
rounded = ((transaction + multiple - 1) // multiple) * multiple
savings = rounded - transaction
return rounded, savings
# App title
st.title("π° Smart Round-Up Savings (User Controlled)")
st.markdown("*Choose your round-up multiple:*")
multiple = st.selectbox("Round to nearest:", [5, 10, 20, 50], index=[5,10,20,50].index(st.session_state.multiple))
st.session_state.multiple = multiple
# Transaction input
transaction = st.number_input("Enter transaction amount (βΉ):", min_value=1, step=1)
if st.button("Add Transaction"):
rounded, savings = round_up(transaction, st.session_state.multiple)
st.session_state.balance += savings
st.session_state.transactions.append(
{"amount": transaction, "rounded": rounded, "savings": savings, "date": datetime.date.today()}
)
st.success(f"Spent βΉ{transaction} β Rounded to βΉ{rounded} β Saved βΉ{savings}")
# Show Smart Pot Balance
st.metric("π° Smart Pot Balance", f"βΉ{st.session_state.balance}")
# Show transaction history
st.subheader("π Transaction History")
if st.session_state.transactions:
for t in reversed(st.session_state.transactions[-5:]):
st.write(f"π’ βΉ{t['amount']} β βΉ{t['rounded']} (Saved βΉ{t['savings']}) on {t['date']}")
else:
st.write("No transactions yet.")
# Monthly reminder simulation
if st.button("π
New Month"):
st.info(f"Last month you saved βΉ{st.session_state.balance} with multiples of βΉ{st.session_state.multiple}.")
st.info("π Do you want to keep it the same, lower for less pressure, or increase for faster savings?")
|