-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_improve.py
More file actions
185 lines (150 loc) Β· 7.08 KB
/
app_improve.py
File metadata and controls
185 lines (150 loc) Β· 7.08 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import streamlit as st
from datetime import datetime, timedelta
import pandas as pd
if 'data_done' not in st.session_state:
st.session_state.data_done = False
if 'planning_done' not in st.session_state:
st.session_state.planning_done = False
if 'end_done' not in st.session_state:
st.session_state.end_done = False
# Part 1: Define a function to input and save information about family members and friends
def input_family_and_friends():
st.markdown("## π Family Members and Friends Information")
num_people = st.number_input(
"π₯ Enter the number of family members and friends:",
min_value=0,
step=1,
value=0)
today = datetime.now().date()
people_info = []
if num_people > 0:
st.markdown("----") # Add a divider for visual separation
for i in range(num_people):
with st.container(
): # Use a container for each person's inputs to group them visually
st.markdown(f"### Person {i+1}")
cols = st.columns([3, 2, 3]) # Adjust column ratios as needed
name = cols[0].text_input("π€ Name:", key=f"name_{i}")
relationship = cols[1].selectbox("π€ Relationship:", [
"Father", "Mother", "Grandfather", "Grandmother", "Spouse",
"Partner", "Sibling", "Friend", "Other"
],
key=f"relationship_{i}")
birthday = cols[2].date_input(
"π Birthday:",
min_value=datetime(today.year - 100, 1, 1),
max_value=datetime(today.year + 1, 12, 31),
value=datetime(today.year, today.month, today.day),
key=f"birthday_{i}")
people_info.append({
"Name": name,
"Relationship": relationship,
"Birth Date": birthday
})
st.markdown(
"---"
) # Add a subtle divider between inputs for different people
if st.button("πΎ Save"):
df = pd.DataFrame(people_info)
st.session_state['df_people'] = df
st.success("π₯ Information Saved Successfully!")
st.dataframe(df) # Display the dataframe in a more compact way
def is_within_holiday_period(plan_date):
if (plan_date.month == 5
and 1 <= plan_date.day <= 3) or (plan_date.month == 10
and 1 <= plan_date.day <= 7):
return True
return False
def adjust_to_nearest_saturday(plan_date):
if is_within_holiday_period(plan_date):
return plan_date, "It's a holiday period, so no adjustment is made."
if plan_date.weekday() in [0, 1]: # Monday or Tuesday
adjusted_date = plan_date - timedelta(days=plan_date.weekday() + 2)
adjustment_message = "Adjusted to the previous Saturday."
elif 2 <= plan_date.weekday() <= 4: # Wednesday to Friday
adjusted_date = plan_date + timedelta(days=5 - plan_date.weekday())
adjustment_message = "Adjusted to the next Saturday."
else:
adjusted_date = plan_date
adjustment_message = "No adjustment needed, it's already a weekend."
return adjusted_date, adjustment_message
def calculate_days_until_next_birthday(birthday):
today = datetime.now().date()
this_year_birthday = birthday.replace(year=today.year)
next_birthday = this_year_birthday if this_year_birthday > today else this_year_birthday.replace(
year=this_year_birthday.year + 1)
return (next_birthday - today).days, next_birthday
# Part 2: Planning part
def planning_part(df_people):
st.markdown("## π Birthday Party Planning")
selected_person = st.selectbox("π€ Select a person:", df_people["Name"])
person_info = df_people[df_people["Name"] == selected_person].iloc[0]
birthday = person_info["Birth Date"]
idx = df_people.index[df_people['Name'] == selected_person].tolist()[0]
st.markdown(f"### π
Birthday Information for {selected_person}")
days_until_birthday, next_birthday = calculate_days_until_next_birthday(
birthday)
st.write(f"π Days until next birthday: {days_until_birthday}")
days_in_advance = st.number_input(
"π Enter number of days in advance to make plans:",
min_value=0,
step=1,
value=0)
plan_date = next_birthday - timedelta(days=days_in_advance)
plan_date, adjustment_message = adjust_to_nearest_saturday(plan_date)
df_people.at[idx, 'Plan Date'] = plan_date
st.session_state['df_people'] = df_people
st.markdown(f"### β
Plan Date: {plan_date.strftime('%B %d, %Y')}")
st.info(adjustment_message)
def end_page(df_people):
st.markdown("## π Birthday Planning Summary")
for index, row in df_people.iterrows():
with st.container():
st.markdown(f"### {row['Name']}")
cols = st.columns(2)
cols[0].markdown(f"**Relationship:** {row['Relationship']}")
cols[0].markdown(
f"**Birth Date:** {row['Birth Date'].strftime('%B %d, %Y')}")
if 'Plan Date' in row and not pd.isnull(row['Plan Date']):
days_until_next_birthday, _ = calculate_days_until_next_birthday(
row['Birth Date'])
cols[1].markdown(
f"**Days until next birthday:** {days_until_next_birthday}"
)
cols[1].markdown(
f"**Planned celebration date:** {row['Plan Date'].strftime('%B %d, %Y')}"
)
else:
cols[1].markdown("**Birthday plan:** Not set")
st.markdown("---") # Divider for readability
redo_planning = st.button("π Plan or Replan Birthdays")
if redo_planning:
st.session_state.data_done = False
def goodbye():
st.markdown("""
### π Congratulations on completing your birthday party plan!
Your party is now on track to be a memorable event, thanks to your thoughtful planning and organization.
**What's Next?**
- **Invite Your Guests:** It's time to let them know about the upcoming celebration.
- **Finalize Details:** From the venue to the menu, ensure every aspect of your party is as perfect as you've imagined.
- **Enjoy Your Party:** Remember, the goal is to celebrate and create lasting memories. Have fun!
**π Thank you for using the Birthday Party Planner!**
""")
def main():
st.title("π Birthday Party Planner")
if 'df_people' not in st.session_state:
st.session_state['df_people'] = pd.DataFrame(
) # Initialize in session state if not present
df_people = input_family_and_friends()
if st.button("β‘οΈ Continue to make plan"):
st.session_state.data_done = True
if st.session_state.data_done and not st.session_state['df_people'].empty:
planning_part(st.session_state['df_people'])
if st.button("π End Planning"):
st.session_state.planning_done = True
end_page(st.session_state['df_people']) # Pass the updated dataframe
finish = st.button("β
Finish and Exit")
if finish:
goodbye()
if __name__ == "__main__":
main()