-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathduplicates.py
91 lines (84 loc) · 3.78 KB
/
duplicates.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
def duplicatesInDay(timeTable):
'Returns list of all lectures of a day irrespective of class and room'
import timing
import TimeTable
for d in timing.daysOfWeek():
dayData = timeTable.loc[d]
periodList = list()
for room in dayData.index:
for period in dayData.columns:
if(dayData[period][room] == TimeTable.theDefaultEmptyChar()):
continue
data = extractPeriodDetail(timeTable, d,room,period)
if(periodList.count(data) >= 1):
print('Duplicate : %s'%(data))
removeDuplicateSubjectsOfDay(timeTable,d,room,period)
duplicatesInDay(timeTable)
timeTable.to_html('TimeTable.html')
return
else:
periodList.append(data)
timeTable.to_csv('TimeTable.csv')
return
def trySwap(timeTable,day,room,period,nextDay):
import TimeTable
oldDayData = timeTable.loc[day]
nextDayData = timeTable.loc[nextDay]
oldDayPeriodList = list()
nextDayPeriodList = list()
for r in oldDayData.index:
for p in oldDayData.columns:
if(oldDayData[p][r] != TimeTable.theDefaultEmptyChar()):
oldDayPeriodList.append(extractPeriodDetail(timeTable,day,r,p))
for r in nextDayData.index:
for p in nextDayData.columns:
if(nextDayData[p][r] != TimeTable.theDefaultEmptyChar()):
nextDayPeriodList.append(extractPeriodDetail(timeTable,nextDay,r,p))
''' # Debugging
for t in oldDayPeriodList:
print(t)
print('Next Day')
for t in nextDayPeriodList:
print(t)
'''
if(nextDayPeriodList.count(extractPeriodDetail(timeTable,day,room,period)) == 0):
for temp in nextDayPeriodList:
''' # Debugging
print('temp: ',eval(temp)[0])
print('old: ',eval(oldDayData[period][room])[0])
print('class match:',(eval(temp)[0] == eval(oldDayData[period][room])[0]))
print('count : ',oldDayPeriodList.count(temp) == 0)
'''
if((eval(temp)[0] == eval(oldDayData[period][room])[0]) and
oldDayPeriodList.count(temp) == 0):
for r in nextDayData.index:
for p in nextDayData.columns:
if(extractPeriodDetail(timeTable,nextDay,r,p) == temp):
input('Doing swapping...')
data1 = eval(timeTable.loc[(day,room),period])
data2 = eval(timeTable.loc[(nextDay,r),p])
small1 = data1[:3].copy()
small2 = data2[:3].copy()
small2.extend(data1[3:].copy())
small1.extend(data2[3:].copy())
timeTable.loc[(day,room),period] = str(small2)
timeTable.loc[(nextDay,r),p] = str(small1)
print('Swapped %s with %s' %(small1, small2))
timeTable.to_html('Duplicate.html')
return True
return False
def removeDuplicateSubjectsOfDay(timeTable,day,room,period):
import timing
for d in timing.daysOfWeek():
if (d == day):
continue
if(trySwap(timeTable, day,room,period, d)):
return
return
def extractPeriodDetail(timeTable,day,room,period):
import TimeTable
if(timeTable.loc[(day,room),period] == TimeTable.theDefaultEmptyChar()):
return TimeTable.theDefaultEmptyChar()
temp = eval(timeTable.loc[(day,room),period])[:3]
data = str(temp)
return data