-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtimetablegen.py
101 lines (93 loc) · 3.76 KB
/
timetablegen.py
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
import pandas as pd
df = pd.read_csv('ffcs.csv')
df1=pd.read_csv('ffcs.csv')
courses1=df1['Course'].unique().tolist()
print("--------------------")
print("Press 1 for Morning Theory and 2 for Evening Theory")
choice = int(input())
if choice == 1:
df = df[df['Slot'].str.endswith('1')]
df1=df1[df1['Slot'].str.endswith('1')]
slots=['A1','B1','C1','D1','E1','F1','G1']
elif choice == 2:
df = df[df['Slot'].str.endswith('2')]
df1=df1[df1['Slot'].str.endswith('2')]
slots=['A2','B2','C2','D2','E2','F2','G2']
else:
print("Invalid input!")
df = df.reset_index(drop=True)
df1=df1.reset_index(drop=True)
df_sorted = df.sort_values(by='Rating', ascending=False).reset_index(drop=True)
courses = df['Course'].unique().tolist()
selected1 = pd.DataFrame()
i=0
def generator():
global df1,choice
df1 = df1.sample(frac=1).reset_index(drop=True)
selected_entries = []
selected_courses = set()
selected_slots = set()
for _, row in df1.iterrows():
course = row['Course']
slot = row['Slot']
if course not in selected_courses and slot not in selected_slots:
selected_entries.append(row)
selected_courses.add(course)
selected_slots.add(slot)
if len(selected_entries) == 7:
break
selected_df = pd.DataFrame(selected_entries)
selected_df = selected_df.sample(frac=1).reset_index(drop=True)
df1=pd.read_csv('ffcs.csv')
if choice == 1:
df1 = df1[df1['Slot'].str.endswith('1')]
elif choice == 2:
df1 = df1[df1['Slot'].str.endswith('2')]
return selected_df
def generatett():
global selected1, df_sorted, courses, df, i
i+=1
if i==25:
print("No Time Table Possible")
return -1
else:
selected1 = pd.DataFrame()
while (courses):
first_entry = df_sorted.iloc[0]
selected1 = pd.concat([selected1, pd.DataFrame([first_entry])], ignore_index=True)
df_sorted = df_sorted[(df_sorted['Course'] != first_entry['Course']) & (df_sorted['Slot'] != first_entry['Slot'])].reset_index(drop=True)
courses = df_sorted['Course'].unique().tolist()
print(f"Choice {i}")
if (len(selected1)==7):
print(selected1)
else:
selected1=generator()
print(selected1)
df = pd.merge(df, selected1, how='left', indicator=True)
df = df[df['_merge'] == 'left_only'].drop('_merge', axis=1).reset_index(drop=True)
df_sorted = df.sort_values(by='Rating', ascending=False).reset_index(drop=True)
courses=df['Course'].unique().tolist()
return
print("-------------------\nChoose one of the given options:\n1. Generate Time Table\n2. Edit Slot Teachers\n3. Exit")
menuinput = int(input())
while menuinput != 3:
if menuinput == 1:
x=generatett()
if x==-1:
break
if menuinput == 2:
print("Enter the slot you want to edit")
print("---------------------------------\nWhat do you want to change?")
print(selected1[['Course','Slot','Name']])
print("-----------\n What index would you like to change?")
index=int(input())
df5=pd.read_csv('ffcs.csv')
filtered_df = df5[(df5['Course'] == selected1['Course'].values[index]) & (df5['Slot'] == selected1['Slot'].values[index])]
filtered_df = filtered_df.sample(frac=1).reset_index(drop=True)
print(filtered_df[['Course','Slot','Name','Rating']])
print("-----------\n What teacher would you like to substitute?")
index2=int(input())
selected1.loc[index] = filtered_df.loc[index2]
print(selected1)
print("-------------------\nChoose one of the given options:\n1. Generate Time Table\n2. Edit Slot Teachers\n3. Exit")
menuinput = int(input())