Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- details.csv +5 -0
- f.py +157 -0
- requirements.txt +4 -0
- schedule.csv +2 -0
details.csv
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
username,password
|
2 |
+
Armin,1234
|
3 |
+
nima,1234
|
4 |
+
ermin,Armin12
|
5 |
+
armin,12345679
|
f.py
ADDED
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from datetime import datetime, timedelta
|
4 |
+
|
5 |
+
# Load schedule data from CSV
|
6 |
+
@st.cache_data
|
7 |
+
def load_schedule():
|
8 |
+
try:
|
9 |
+
schedule_data = pd.read_csv('schedule.csv')
|
10 |
+
except FileNotFoundError:
|
11 |
+
schedule_data = pd.DataFrame(columns=['Class', 'Day', 'Start Time', 'Username', 'System'])
|
12 |
+
return schedule_data
|
13 |
+
|
14 |
+
# Save schedule data to CSV
|
15 |
+
def save_schedule(schedule_data):
|
16 |
+
schedule_data.to_csv('schedule.csv', index=False)
|
17 |
+
|
18 |
+
# Load user details from CSV
|
19 |
+
@st.cache_data
|
20 |
+
def load_user_details():
|
21 |
+
try:
|
22 |
+
user_details = pd.read_csv('details.csv')
|
23 |
+
except FileNotFoundError:
|
24 |
+
user_details = pd.DataFrame(columns=['username', 'password'])
|
25 |
+
return user_details
|
26 |
+
|
27 |
+
# Check for system availability
|
28 |
+
def has_system_availability(schedule_data, class_selected, day_selected, start_time_selected, system_selected):
|
29 |
+
bookings = schedule_data[
|
30 |
+
(schedule_data['Class'] == class_selected) &
|
31 |
+
(schedule_data['Day'] == day_selected) &
|
32 |
+
(schedule_data['Start Time'] == start_time_selected)
|
33 |
+
]
|
34 |
+
if len(bookings) >= 6:
|
35 |
+
return False
|
36 |
+
elif system_selected in bookings['System'].values:
|
37 |
+
return False
|
38 |
+
else:
|
39 |
+
return True
|
40 |
+
|
41 |
+
# Convert string day and time to datetime
|
42 |
+
def get_class_datetime(day_selected, start_time_selected):
|
43 |
+
days_of_week = ["Sunday", "Monday", "Tuesday", "Wednesday"]
|
44 |
+
today = datetime.now()
|
45 |
+
current_day_index = today.weekday()
|
46 |
+
|
47 |
+
# Find the date of the next occurrence of the given day
|
48 |
+
target_day_index = days_of_week.index(day_selected)
|
49 |
+
delta_days = (target_day_index - current_day_index) % 7
|
50 |
+
|
51 |
+
# If the class day is today but time has passed, move to the next week
|
52 |
+
if delta_days == 0 and datetime.strptime(start_time_selected, "%I:%M %p").time() < today.time():
|
53 |
+
delta_days = 7
|
54 |
+
|
55 |
+
class_date = today + timedelta(days=delta_days)
|
56 |
+
class_time = datetime.strptime(start_time_selected, "%I:%M %p").time()
|
57 |
+
class_datetime = datetime.combine(class_date.date(), class_time)
|
58 |
+
|
59 |
+
return class_datetime
|
60 |
+
|
61 |
+
# Initialize session state variables
|
62 |
+
if 'username' not in st.session_state:
|
63 |
+
st.session_state.username = ""
|
64 |
+
if 'password' not in st.session_state:
|
65 |
+
st.session_state.password = ""
|
66 |
+
if 'schedule_data' not in st.session_state:
|
67 |
+
st.session_state.schedule_data = load_schedule()
|
68 |
+
if 'authenticated' not in st.session_state:
|
69 |
+
st.session_state.authenticated = False
|
70 |
+
if 'is_admin' not in st.session_state:
|
71 |
+
st.session_state.is_admin = False
|
72 |
+
|
73 |
+
# Login Page
|
74 |
+
def login_page():
|
75 |
+
st.title("Login")
|
76 |
+
st.session_state.username = st.text_input("Username")
|
77 |
+
st.session_state.password = st.text_input("Password", type='password')
|
78 |
+
|
79 |
+
user_details = load_user_details()
|
80 |
+
|
81 |
+
if st.button("Login"):
|
82 |
+
if (
|
83 |
+
(st.session_state.username in user_details['username'].values) and
|
84 |
+
(st.session_state.password in user_details[user_details['username'] == st.session_state.username]['password'].values)
|
85 |
+
) or (st.session_state.username == "armin" and st.session_state.password == "12345679"):
|
86 |
+
st.session_state.authenticated = True
|
87 |
+
st.session_state.is_admin = (st.session_state.username == "armin")
|
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 = ["mobile", "Math", "Chemistry", "Programming"]
|
97 |
+
days = ["Sunday", "Monday", "Tuesday", "Wednesday"]
|
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 |
+
class_to_remove = st.selectbox("Class", st.session_state.schedule_data['Class'].unique(), key='remove_class_select')
|
127 |
+
user_booking = st.session_state.schedule_data[
|
128 |
+
(st.session_state.schedule_data['Class'] == class_to_remove) &
|
129 |
+
(st.session_state.schedule_data['Username'] == st.session_state.username)
|
130 |
+
]
|
131 |
+
|
132 |
+
if st.button("Remove Class"):
|
133 |
+
if st.session_state.is_admin or not user_booking.empty:
|
134 |
+
st.session_state.schedule_data = st.session_state.schedule_data[~(
|
135 |
+
(st.session_state.schedule_data['Class'] == class_to_remove) &
|
136 |
+
((st.session_state.is_admin) or (st.session_state.schedule_data['Username'] == st.session_state.username))
|
137 |
+
)]
|
138 |
+
save_schedule(st.session_state.schedule_data)
|
139 |
+
st.success(f"Class {class_to_remove} removed successfully.")
|
140 |
+
else:
|
141 |
+
st.error("You can only remove your own classes.")
|
142 |
+
|
143 |
+
st.header("Your Schedule")
|
144 |
+
st.table(st.session_state.schedule_data)
|
145 |
+
|
146 |
+
if st.button("Log Out"):
|
147 |
+
st.session_state['authenticated'] = False
|
148 |
+
st.session_state['username'] = ""
|
149 |
+
st.session_state['password'] = ""
|
150 |
+
st.session_state['is_admin'] = False
|
151 |
+
st.experimental_rerun()
|
152 |
+
|
153 |
+
# Authentication check
|
154 |
+
if not st.session_state['authenticated']:
|
155 |
+
login_page()
|
156 |
+
else:
|
157 |
+
schedule_page()
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
pandas
|
3 |
+
datetime
|
4 |
+
|
schedule.csv
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
Class,Day,Start Time,Username,System
|
2 |
+
|