2052man commited on
Commit
66419b7
1 Parent(s): bc23c78

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -35
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 = ["Sunday", "Monday", "Tuesday", "Wednesday", "Friday"]
42
- today = datetime.now()
43
- current_day_index = today.weekday()
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, "%I:%M %p").time() < today.time():
51
  delta_days = 7
52
 
53
  class_date = today + timedelta(days=delta_days)
54
- class_time = datetime.strptime(start_time_selected, "%I:%M %p").time()
55
- class_datetime = datetime.combine(class_date.date(), class_time)
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("Login")
74
- st.session_state.username = st.text_input("Username")
75
- st.session_state.password = st.text_input("Password", type='password')
76
 
77
  user_details = load_user_details()
78
 
79
- if st.button("Login"):
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("Invalid username or password. Please try again.")
91
 
92
  # Class Schedule Page
93
  def schedule_page():
94
- st.title("Class Schedule")
95
 
96
- classes = ["Physics", "Math", "Chemistry", "Programming"]
97
- days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Friday"]
98
- start_times = ["8:00 AM", "10:00 AM", "12:00 PM", "2:00 PM"]
99
- systems = ["System 1", "System 2", "System 3", "System 4", "System 5", "System 6"]
100
 
101
- st.header("Manage Classes")
102
 
103
  col1, col2 = st.columns(2)
104
 
105
  with col1:
106
- st.subheader("Add a Class")
107
- class_selected = st.selectbox("Class", classes, key='add_class_select')
108
- day_selected = st.selectbox("Day", days, key='add_day_select')
109
- start_time_selected = st.selectbox("Start Time", start_times, key='add_time_select')
110
- system_selected = st.selectbox("System", systems, key='add_system_select')
111
 
112
- if st.button("Add Class"):
113
  class_datetime = get_class_datetime(day_selected, start_time_selected)
114
  if class_datetime - datetime.now() < timedelta(hours=30):
115
- st.error("Classes can only be booked at least 30 hours in advance.")
116
  elif not has_system_availability(st.session_state.schedule_data, class_selected, day_selected, start_time_selected, system_selected):
117
- st.error(f"System '{system_selected}' is not available for '{class_selected}' at {start_time_selected} on {day_selected}.")
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"Class {class_selected} added successfully with {system_selected}.")
123
 
124
  with col2:
125
- st.subheader("Remove a Class")
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("Class", user_classes['Class'].unique(), key='remove_class_select')
133
 
134
- if st.button("Remove Class"):
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"Class {class_to_remove} removed successfully.")
142
  else:
143
- st.error("You can only remove your own classes.")
144
  else:
145
- st.error("You have no classes to remove.")
146
  else:
147
- st.error("No classes available for removal or 'Username' column is missing.")
148
 
149
- st.header("Your Schedule")
150
  st.table(st.session_state.schedule_data)
151
 
152
- if st.button("Log Out"):
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'] = ""