Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
from datetime import datetime, timedelta
|
|
|
4 |
|
5 |
# Load schedule data from CSV
|
6 |
def load_schedule():
|
@@ -38,21 +39,21 @@ def has_system_availability(schedule_data, class_selected, day_selected, start_t
|
|
38 |
|
39 |
# Convert string day and time to datetime
|
40 |
def get_class_datetime(day_selected, start_time_selected):
|
41 |
-
days_of_week = ["
|
42 |
-
today =
|
43 |
-
current_day_index = today.
|
44 |
|
45 |
# Find the date of the next occurrence of the given day
|
46 |
target_day_index = days_of_week.index(day_selected)
|
47 |
delta_days = (target_day_index - current_day_index) % 7
|
48 |
|
49 |
# If the class day is today but time has passed, move to the next week
|
50 |
-
if delta_days == 0 and datetime.strptime(start_time_selected, "%
|
51 |
delta_days = 7
|
52 |
|
53 |
class_date = today + timedelta(days=delta_days)
|
54 |
-
class_time = datetime.strptime(start_time_selected, "%
|
55 |
-
class_datetime = datetime.combine(class_date.
|
56 |
|
57 |
return class_datetime
|
58 |
|
@@ -70,13 +71,13 @@ if 'is_admin' not in st.session_state:
|
|
70 |
|
71 |
# Login Page
|
72 |
def login_page():
|
73 |
-
st.title("
|
74 |
-
st.session_state.username = st.text_input("
|
75 |
-
st.session_state.password = st.text_input("
|
76 |
|
77 |
user_details = load_user_details()
|
78 |
|
79 |
-
if st.button("
|
80 |
if (
|
81 |
(st.session_state.username in user_details['username'].values) and
|
82 |
(st.session_state.password in user_details[user_details['username'] == st.session_state.username]['password'].values)
|
@@ -87,69 +88,69 @@ def login_page():
|
|
87 |
st.session_state.schedule_data = load_schedule()
|
88 |
st.experimental_rerun()
|
89 |
else:
|
90 |
-
st.error("
|
91 |
|
92 |
# Class Schedule Page
|
93 |
def schedule_page():
|
94 |
-
st.title("
|
95 |
|
96 |
-
classes = ["
|
97 |
-
days = ["
|
98 |
-
start_times = ["
|
99 |
-
systems = ["
|
100 |
|
101 |
-
st.header("
|
102 |
|
103 |
col1, col2 = st.columns(2)
|
104 |
|
105 |
with col1:
|
106 |
-
st.subheader("
|
107 |
-
class_selected = st.selectbox("
|
108 |
-
day_selected = st.selectbox("
|
109 |
-
start_time_selected = st.selectbox("
|
110 |
-
system_selected = st.selectbox("
|
111 |
|
112 |
-
if st.button("
|
113 |
class_datetime = get_class_datetime(day_selected, start_time_selected)
|
114 |
if class_datetime - datetime.now() < timedelta(hours=30):
|
115 |
-
st.error("
|
116 |
elif not has_system_availability(st.session_state.schedule_data, class_selected, day_selected, start_time_selected, system_selected):
|
117 |
-
st.error(f"
|
118 |
else:
|
119 |
new_row = pd.DataFrame([[class_selected, day_selected, start_time_selected, st.session_state.username, system_selected]], columns=['Class', 'Day', 'Start Time', 'Username', 'System'])
|
120 |
st.session_state.schedule_data = pd.concat([st.session_state.schedule_data, new_row], ignore_index=True)
|
121 |
save_schedule(st.session_state.schedule_data)
|
122 |
-
st.success(f"
|
123 |
|
124 |
with col2:
|
125 |
-
st.subheader("
|
126 |
if not st.session_state.schedule_data.empty and 'Username' in st.session_state.schedule_data.columns:
|
127 |
user_classes = st.session_state.schedule_data[
|
128 |
(st.session_state.schedule_data['Username'] == st.session_state.username) |
|
129 |
st.session_state.is_admin
|
130 |
]
|
131 |
if not user_classes.empty:
|
132 |
-
class_to_remove = st.selectbox("
|
133 |
|
134 |
-
if st.button("
|
135 |
if st.session_state.is_admin or not user_classes.empty:
|
136 |
st.session_state.schedule_data = st.session_state.schedule_data[~(
|
137 |
(st.session_state.schedule_data['Class'] == class_to_remove) &
|
138 |
((st.session_state.is_admin) or (st.session_state.schedule_data['Username'] == st.session_state.username))
|
139 |
)]
|
140 |
save_schedule(st.session_state.schedule_data)
|
141 |
-
st.success(f"
|
142 |
else:
|
143 |
-
st.error("
|
144 |
else:
|
145 |
-
st.error("
|
146 |
else:
|
147 |
-
st.error("
|
148 |
|
149 |
-
st.header("
|
150 |
st.table(st.session_state.schedule_data)
|
151 |
|
152 |
-
if st.button("
|
153 |
st.session_state['authenticated'] = False
|
154 |
st.session_state['username'] = ""
|
155 |
st.session_state['password'] = ""
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
from datetime import datetime, timedelta
|
4 |
+
from persiantools.jdatetime import JalaliDate
|
5 |
|
6 |
# Load schedule data from CSV
|
7 |
def load_schedule():
|
|
|
39 |
|
40 |
# Convert string day and time to datetime
|
41 |
def get_class_datetime(day_selected, start_time_selected):
|
42 |
+
days_of_week = ["یکشنبه", "دوشنبه", "سهشنبه", "چهارشنبه", "پنجشنبه", "جمعه", "شنبه"]
|
43 |
+
today = JalaliDate.today()
|
44 |
+
current_day_index = today.day_of_week
|
45 |
|
46 |
# Find the date of the next occurrence of the given day
|
47 |
target_day_index = days_of_week.index(day_selected)
|
48 |
delta_days = (target_day_index - current_day_index) % 7
|
49 |
|
50 |
# If the class day is today but time has passed, move to the next week
|
51 |
+
if delta_days == 0 and datetime.strptime(start_time_selected, "%H:%M").time() < today.to_gregorian().time():
|
52 |
delta_days = 7
|
53 |
|
54 |
class_date = today + timedelta(days=delta_days)
|
55 |
+
class_time = datetime.strptime(start_time_selected, "%H:%M").time()
|
56 |
+
class_datetime = datetime.combine(class_date.to_gregorian(), class_time)
|
57 |
|
58 |
return class_datetime
|
59 |
|
|
|
71 |
|
72 |
# Login Page
|
73 |
def login_page():
|
74 |
+
st.title("ورود")
|
75 |
+
st.session_state.username = st.text_input("نام کاربری")
|
76 |
+
st.session_state.password = st.text_input("رمز عبور", type='password')
|
77 |
|
78 |
user_details = load_user_details()
|
79 |
|
80 |
+
if st.button("ورود"):
|
81 |
if (
|
82 |
(st.session_state.username in user_details['username'].values) and
|
83 |
(st.session_state.password in user_details[user_details['username'] == st.session_state.username]['password'].values)
|
|
|
88 |
st.session_state.schedule_data = load_schedule()
|
89 |
st.experimental_rerun()
|
90 |
else:
|
91 |
+
st.error("نام کاربری یا رمز عبور اشتباه است. لطفا دوباره تلاش کنید.")
|
92 |
|
93 |
# Class Schedule Page
|
94 |
def schedule_page():
|
95 |
+
st.title("برنامه کلاسی")
|
96 |
|
97 |
+
classes = ["فیزیک", "ریاضی", "شیمی", "برنامهنویسی"]
|
98 |
+
days = ["شنبه", "یکشنبه", "دوشنبه", "سهشنبه", "چهارشنبه", "پنجشنبه", "جمعه"]
|
99 |
+
start_times = ["08:00", "10:00", "12:00", "14:00"]
|
100 |
+
systems = ["سیستم ۱", "سیستم ۲", "سیستم ۳", "سیستم ۴", "سیستم ۵", "سیستم ۶"]
|
101 |
|
102 |
+
st.header("مدیریت کلاسها")
|
103 |
|
104 |
col1, col2 = st.columns(2)
|
105 |
|
106 |
with col1:
|
107 |
+
st.subheader("اضافه کردن کلاس")
|
108 |
+
class_selected = st.selectbox("کلاس", classes, key='add_class_select')
|
109 |
+
day_selected = st.selectbox("روز", days, key='add_day_select')
|
110 |
+
start_time_selected = st.selectbox("زمان شروع", start_times, key='add_time_select')
|
111 |
+
system_selected = st.selectbox("سیستم", systems, key='add_system_select')
|
112 |
|
113 |
+
if st.button("اضافه کردن کلاس"):
|
114 |
class_datetime = get_class_datetime(day_selected, start_time_selected)
|
115 |
if class_datetime - datetime.now() < timedelta(hours=30):
|
116 |
+
st.error("کلاسها باید حداقل ۳۰ ساعت قبل رزرو شوند.")
|
117 |
elif not has_system_availability(st.session_state.schedule_data, class_selected, day_selected, start_time_selected, system_selected):
|
118 |
+
st.error(f"سیستم '{system_selected}' در زمان '{start_time_selected}' در روز '{day_selected}' برای '{class_selected}' موجود نیست.")
|
119 |
else:
|
120 |
new_row = pd.DataFrame([[class_selected, day_selected, start_time_selected, st.session_state.username, system_selected]], columns=['Class', 'Day', 'Start Time', 'Username', 'System'])
|
121 |
st.session_state.schedule_data = pd.concat([st.session_state.schedule_data, new_row], ignore_index=True)
|
122 |
save_schedule(st.session_state.schedule_data)
|
123 |
+
st.success(f"کلاس {class_selected} با موفقیت اضافه شد به {system_selected}.")
|
124 |
|
125 |
with col2:
|
126 |
+
st.subheader("حذف کلاس")
|
127 |
if not st.session_state.schedule_data.empty and 'Username' in st.session_state.schedule_data.columns:
|
128 |
user_classes = st.session_state.schedule_data[
|
129 |
(st.session_state.schedule_data['Username'] == st.session_state.username) |
|
130 |
st.session_state.is_admin
|
131 |
]
|
132 |
if not user_classes.empty:
|
133 |
+
class_to_remove = st.selectbox("کلاس", user_classes['Class'].unique(), key='remove_class_select')
|
134 |
|
135 |
+
if st.button("حذف کلاس"):
|
136 |
if st.session_state.is_admin or not user_classes.empty:
|
137 |
st.session_state.schedule_data = st.session_state.schedule_data[~(
|
138 |
(st.session_state.schedule_data['Class'] == class_to_remove) &
|
139 |
((st.session_state.is_admin) or (st.session_state.schedule_data['Username'] == st.session_state.username))
|
140 |
)]
|
141 |
save_schedule(st.session_state.schedule_data)
|
142 |
+
st.success(f"کلاس {class_to_remove} با موفقیت حذف شد.")
|
143 |
else:
|
144 |
+
st.error("شما فقط میتوانید کلاسهای خودتان را حذف کنید.")
|
145 |
else:
|
146 |
+
st.error("شما هیچ کلاسی برای حذف ندارید.")
|
147 |
else:
|
148 |
+
st.error("هیچ کلاسی برای حذف وجود ندارد یا ستون 'Username' موجود نیست.")
|
149 |
|
150 |
+
st.header("برنامه شما")
|
151 |
st.table(st.session_state.schedule_data)
|
152 |
|
153 |
+
if st.button("خروج"):
|
154 |
st.session_state['authenticated'] = False
|
155 |
st.session_state['username'] = ""
|
156 |
st.session_state['password'] = ""
|