Skip to content

Commit 272c693

Browse files
committedOct 25, 2023
added detail
1 parent adfa11f commit 272c693

File tree

3 files changed

+388
-0
lines changed

3 files changed

+388
-0
lines changed
 

‎E/expense_Tracker/README.md

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
2+
3+
## Table of Contents listed
4+
5+
- 📑[Table of Contents](#table-of-contents)
6+
- 🧾[Introduction](#introduction)
7+
-[Features](#features)
8+
- 🛠️[How to Use](#how-to-use)
9+
- ⚙️[Installation](#installation)
10+
- 🙌[How to Contribute](#how-to-contribute)
11+
- 📝[License](#license)
12+
13+
## Introduction
14+
15+
Managing a family's finances can be challenging, especially when dealing with multiple sources of income and various expenses. The Family Expense Tracker simplifies this task by providing a user-friendly interface to:
16+
17+
- 💼 Add Family Members
18+
- 💵 Record Earnings for Each Family Member
19+
- 📉 Track Expenses
20+
- 💰 Calculate Remaining Balance
21+
22+
With this tool, you can easily monitor and manage your family's financial situation.
23+
24+
## Features
25+
26+
- **Add Family Members:** Start by adding the names of family members whose earnings and expenses you want to track.
27+
- **Record Earnings:** Record the earnings for each family member. The tracker calculates the total earnings for the family.
28+
- **Track Expenses:** Log various expenses, and the tracker deducts these from the total earnings, showing the remaining balance.
29+
- **User-Friendly Interface:**
30+
31+
The Expense Tracker features a simple and easy-to-navigate interface, ensuring a seamless user experience, allowing you to effortlessly manage your family's financial data.
32+
33+
## How to Use
34+
35+
1. **Add Family Members:**
36+
- Run the [application](https://expense-tracker-alpha.streamlit.app/) and choose the option to add family members.
37+
- Enter the names of the family members you want to track.
38+
39+
2. **Record Earnings:**
40+
- Select the option to record earnings.
41+
- Specify the earnings for each family member.
42+
43+
3. **Track Expenses:**
44+
- Log expenses for various categories (e.g., groceries, bills).
45+
- The application automatically calculates the remaining balance after deducting expenses.
46+
47+
## Installation
48+
49+
1. Clone the repository:
50+
51+
```bash
52+
git clone https://github.com/sree-hari-s/Expense-Tracker.git
53+
cd Expense-Tracker
54+
```
55+
56+
2. Install the required dependencies
57+
58+
```bash
59+
pip install -r requirements.txt
60+
```
61+
62+
3. Run the Application
63+
64+
Now you can run the Family Expense Tracker application using Streamlit:
65+
66+
```bash
67+
streamlit run app.py
68+
```
69+
70+
## How to Contribute
71+
72+
- If you wish to [contribute](CONTRIBUTING.md) in any way, feel free to get involved. You can suggest improvements or provide support and encouragement by [opening an issue](https://github.com/sree-hari-s/Expense-Tracker/issues).
73+
74+
## Contributors
75+
76+
Thank you all for, your contributions. Your contributions hold immense value for our project, and we are genuinely thankful for your valuable support. Your unwavering commitment and hard work are truly commendable.
77+
78+
<p align="center">
79+
<a href="https://github.com/sree-hari-s/Expense-Tracker/graphs/contributors">
80+
<img src="https://contrib.rocks/image?repo=sree-hari-s/Expense-Tracker" alt="Contributors" />
81+
</a>
82+
</p>
83+
84+
85+
## License
86+
87+
This project is licensed under the terms of the [MIT License](LICENSE).

‎E/expense_Tracker/app.py

+212
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
import streamlit as st
2+
from main import FamilyExpenseTracker
3+
import matplotlib.pyplot as plt
4+
from streamlit_option_menu import option_menu
5+
6+
# Streamlit configuration
7+
st.set_page_config(page_title="Family Expense Tracker", page_icon="💰")
8+
9+
st.title("") # Clear the default title
10+
11+
# Hide Streamlit Style
12+
hide_st_style = """
13+
<style>
14+
#MainMenu {visibility: hidden;}
15+
footer {visibility: hidden;}
16+
header {visibility: hidden;}
17+
</style>
18+
"""
19+
st.markdown(hide_st_style, unsafe_allow_html=True)
20+
21+
# Create a session state object
22+
session_state = st.session_state
23+
24+
# Check if the 'expense_tracker' object exists in the session state
25+
if "expense_tracker" not in session_state:
26+
# If not, create and initialize it
27+
session_state.expense_tracker = FamilyExpenseTracker()
28+
29+
# Center-align the heading using HTML
30+
st.markdown(
31+
'<h1 style="text-align: center;">Family Expense Tracker</h1>',
32+
unsafe_allow_html=True,
33+
)
34+
35+
# Navigation Menu
36+
selected = option_menu(
37+
menu_title=None,
38+
options=["Data Entry", "Data Overview", "Data Visualization"],
39+
icons=[
40+
"pencil-fill",
41+
"clipboard2-data",
42+
"bar-chart-fill",
43+
], # https://icons.getbootstrap.com/
44+
orientation="horizontal",
45+
)
46+
47+
# Access the 'expense_tracker' object from session state
48+
expense_tracker = session_state.expense_tracker
49+
50+
if selected == "Data Entry":
51+
st.header("Add Family Member")
52+
with st.expander("Add Family Member"):
53+
# Sidebar for adding family members
54+
member_name = st.text_input("Name").title()
55+
earning_status = st.checkbox("Earning Status")
56+
if earning_status:
57+
earnings = st.number_input("Earnings", value=1, min_value=1)
58+
else:
59+
earnings = 0
60+
61+
if st.button("Add Member"):
62+
try:
63+
# Check if family member exists
64+
member = [
65+
member
66+
for member in expense_tracker.members
67+
if member.name == member_name
68+
]
69+
# If not exist add family member
70+
if not member:
71+
expense_tracker.add_family_member(
72+
member_name, earning_status, earnings
73+
)
74+
st.success("Member added successfully!")
75+
# Else, update it
76+
else:
77+
expense_tracker.update_family_member(
78+
member[0], earning_status, earnings
79+
)
80+
st.success("Member updated successfully!")
81+
except ValueError as e:
82+
st.error(str(e))
83+
84+
# Sidebar for adding expenses
85+
st.header("Add Expenses")
86+
with st.expander("Add Expenses"):
87+
expense_category = st.selectbox(
88+
"Category",
89+
(
90+
"Housing",
91+
"Food",
92+
"Transportation",
93+
"Entertainment",
94+
"Child-Related",
95+
"Medical",
96+
"Investment",
97+
"Miscellaneous",
98+
),
99+
)
100+
expense_description = st.text_input("Description (optional)").title()
101+
expense_value = st.number_input("Value", min_value=0)
102+
expense_date = st.date_input("Date", value="today")
103+
104+
if st.button("Add Expense"):
105+
try:
106+
# Add the expense
107+
expense_tracker.merge_similar_category(
108+
expense_value, expense_category, expense_description, expense_date
109+
)
110+
st.success("Expense added successfully!")
111+
except ValueError as e:
112+
st.error(str(e))
113+
elif selected == "Data Overview":
114+
# Display family members
115+
if not expense_tracker.members:
116+
st.info(
117+
"Start by adding family members to track your expenses together! Currently, no members have been added. Get started by clicking the 'Add Member' from the Data Entry Tab"
118+
)
119+
else:
120+
st.header("Family Members")
121+
(
122+
name_column,
123+
earning_status_column,
124+
earnings_column,
125+
family_delete_column,
126+
) = st.columns(4)
127+
name_column.write("**Name**")
128+
earning_status_column.write("**Earning status**")
129+
earnings_column.write("**Earnings**")
130+
family_delete_column.write("**Action**")
131+
132+
for member in expense_tracker.members:
133+
name_column.write(member.name)
134+
earning_status_column.write(
135+
"Earning" if member.earning_status else "Not Earning"
136+
)
137+
earnings_column.write(member.earnings)
138+
139+
if family_delete_column.button(f"Delete {member.name}"):
140+
expense_tracker.delete_family_member(member)
141+
st.rerun()
142+
143+
# Display expenses
144+
st.header("Expenses")
145+
if not expense_tracker.expense_list:
146+
st.info(
147+
"Currently, no expenses have been added. Get started by clicking the 'Add Expenses' from the Data Entry Tab"
148+
)
149+
else:
150+
(
151+
value_column,
152+
category_column,
153+
description_column,
154+
date_column,
155+
expense_delete_column,
156+
) = st.columns(5)
157+
value_column.write("**Value**")
158+
category_column.write("**Category**")
159+
description_column.write("**Description**")
160+
date_column.write("**Date**")
161+
expense_delete_column.write("**Delete**")
162+
163+
for expense in expense_tracker.expense_list:
164+
value_column.write(expense.value)
165+
category_column.write(expense.category)
166+
description_column.write(expense.description)
167+
date_column.write(expense.date)
168+
169+
if expense_delete_column.button(f"Delete {expense.category}"):
170+
expense_tracker.delete_expense(expense)
171+
st.rerun()
172+
173+
total_earnings = expense_tracker.calculate_total_earnings() # Calculate total earnings
174+
total_expenditure = expense_tracker.calculate_total_expenditure() # Calculate total expenditure
175+
remaining_balance = total_earnings - total_expenditure # Calculate remaining balance
176+
col1, col2, col3 = st.columns(3)
177+
col1.metric("Total Earnings", f"{total_earnings}") # Display total earnings
178+
col2.metric("Total Expenditure", f"{total_expenditure}") # Display total expenditure
179+
col3.metric("Remaining Balance", f"{remaining_balance}") # Display remaining balance
180+
181+
elif selected == "Data Visualization":
182+
# Create a list of expenses and their values
183+
expense_data = [
184+
(expense.category, expense.value) for expense in expense_tracker.expense_list
185+
]
186+
if expense_data:
187+
# Calculate the percentage of expenses for the pie chart
188+
expenses = [data[0] for data in expense_data]
189+
values = [data[1] for data in expense_data]
190+
total = sum(values)
191+
percentages = [(value / total) * 100 for value in values]
192+
193+
# Create a smaller pie chart with a transparent background
194+
fig, ax = plt.subplots(figsize=(3, 3), dpi=300)
195+
ax.pie(
196+
percentages,
197+
labels=expenses,
198+
autopct="%1.1f%%",
199+
startangle=140,
200+
textprops={"fontsize": 6, "color": "white"},
201+
)
202+
ax.set_title("Expense Distribution", fontsize=12, color="white")
203+
204+
# Set the background color to be transparent
205+
fig.patch.set_facecolor("none")
206+
207+
# Display the pie chart in Streamlit
208+
st.pyplot(fig)
209+
else:
210+
st.info(
211+
"Start by adding family members to track your expenses together! Currently, no members have been added. Get started by clicking the 'Add Member' from the Data Entry Tab."
212+
)

‎E/expense_Tracker/main.py

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
class FamilyMember:
2+
def __init__(self, name, earning_status=True, earnings=0):
3+
self.name = name
4+
self.earning_status = earning_status
5+
self.earnings = earnings
6+
7+
def __str__(self):
8+
return (
9+
f"Name: {self.name}, Earning Status: {'Earning' if self.earning_status else 'Not Earning'}, "
10+
f"Earnings: {self.earnings}"
11+
)
12+
13+
14+
class Expense:
15+
def __init__(self, value, category, description, date):
16+
self.value = value
17+
self.category = category
18+
self.description = description
19+
self.date = date
20+
21+
def __str__(self):
22+
return f"Value: {self.value}, Category: {self.category}, Description: {self.description}, Date: {self.date}"
23+
24+
25+
class FamilyExpenseTracker:
26+
def __init__(self):
27+
self.members = []
28+
self.expense_list = []
29+
30+
def add_family_member(self, name, earning_status=True, earnings=0):
31+
if not name.strip():
32+
raise ValueError("Name field cannot be empty")
33+
34+
member = FamilyMember(name, earning_status, earnings)
35+
self.members.append(member)
36+
37+
def delete_family_member(self, member):
38+
self.members.remove(member)
39+
40+
def update_family_member(self, member, earning_status=True, earnings=0):
41+
if member:
42+
member.earning_status = earning_status
43+
member.earnings = earnings
44+
45+
def calculate_total_earnings(self):
46+
total_earnings = sum(
47+
member.earnings for member in self.members if member.earning_status
48+
)
49+
return total_earnings
50+
51+
def add_expense(self, value, category, description, date):
52+
if value == 0:
53+
raise ValueError("Value cannot be zero")
54+
if not category.strip():
55+
raise ValueError("Please choose a category")
56+
57+
expense = Expense(value, category, description, date)
58+
self.expense_list.append(expense)
59+
60+
def delete_expense(self,expense):
61+
self.expense_list.remove(expense)
62+
63+
64+
def merge_similar_category(self, value, category, description, date):
65+
if value == 0:
66+
raise ValueError("Value cannot be zero")
67+
if not category.strip():
68+
raise ValueError("Please choose a category")
69+
70+
existing_expense = None
71+
for expense in self.expense_list:
72+
if expense.category == category:
73+
existing_expense = expense
74+
break
75+
76+
if existing_expense:
77+
existing_expense.value += value
78+
if description:
79+
existing_expense.description = description
80+
else:
81+
self.add_expense(value, category, description, date)
82+
83+
def calculate_total_expenditure(self):
84+
total_expenditure = sum(expense.value for expense in self.expense_list)
85+
return total_expenditure
86+
87+
88+
if __name__ == "__main__":
89+
expense_tracker = FamilyExpenseTracker()

0 commit comments

Comments
 (0)
Please sign in to comment.