Spaces:
Sleeping
Sleeping
Create timetable.py
Browse files- timetable.py +56 -0
timetable.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
from datetime import time
|
| 3 |
+
|
| 4 |
+
DAYS = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
|
| 5 |
+
|
| 6 |
+
def generate_time_slots():
|
| 7 |
+
slots = []
|
| 8 |
+
start_hour = 9.0
|
| 9 |
+
end_hour = 15.0
|
| 10 |
+
|
| 11 |
+
while start_hour < end_hour:
|
| 12 |
+
slots.append(start_hour)
|
| 13 |
+
start_hour += 1.5 if start_hour + 1.5 <= end_hour else 1.0
|
| 14 |
+
|
| 15 |
+
return slots
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def generate_timetable(courses_path, rooms_path):
|
| 19 |
+
courses = pd.read_csv(courses_path)
|
| 20 |
+
rooms = pd.read_csv(rooms_path)["Room"].tolist()
|
| 21 |
+
|
| 22 |
+
slots = generate_time_slots()
|
| 23 |
+
timetable = []
|
| 24 |
+
|
| 25 |
+
day_idx = 0
|
| 26 |
+
slot_idx = 0
|
| 27 |
+
room_idx = 0
|
| 28 |
+
|
| 29 |
+
for _, row in courses.iterrows():
|
| 30 |
+
remaining_hours = row["Hours"]
|
| 31 |
+
|
| 32 |
+
while remaining_hours > 0:
|
| 33 |
+
duration = 1.5 if remaining_hours >= 1.5 else 1.0
|
| 34 |
+
start = slots[slot_idx]
|
| 35 |
+
end = start + duration
|
| 36 |
+
|
| 37 |
+
timetable.append({
|
| 38 |
+
"Day": DAYS[day_idx],
|
| 39 |
+
"Time": f"{start:0.1f} - {end:0.1f}",
|
| 40 |
+
"Course": row["Course"],
|
| 41 |
+
"Teacher": row["Teacher"],
|
| 42 |
+
"Room": rooms[room_idx % len(rooms)]
|
| 43 |
+
})
|
| 44 |
+
|
| 45 |
+
remaining_hours -= duration
|
| 46 |
+
slot_idx += 1
|
| 47 |
+
room_idx += 1
|
| 48 |
+
|
| 49 |
+
if slot_idx >= len(slots):
|
| 50 |
+
slot_idx = 0
|
| 51 |
+
day_idx += 1
|
| 52 |
+
|
| 53 |
+
if day_idx >= len(DAYS):
|
| 54 |
+
return pd.DataFrame(timetable)
|
| 55 |
+
|
| 56 |
+
return pd.DataFrame(timetable)
|