-
Notifications
You must be signed in to change notification settings - Fork 1
/
rank.py
98 lines (81 loc) · 2.47 KB
/
rank.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
import camelot
import pandas as pd
import operator
gp = {
'O': 10,
'A+': 9,
'A': 8.5,
'B+': 8,
'B': 7,
'C': 6,
'P': 5,
'F': 0,
'FE': 0,
'd': 0,
'E': 0,
'I': 0
}
#Credits for this semester entered in order of slots
credits = [4,4,4,3,3,3,1,1,1]
tc = sum(credits)
# CREATING REGNO:NAME DICTIONARY
rolltables = camelot.read_pdf('roll.pdf', pages='2')
names = {}
table = rolltables[0].df
regnum = table[1].tolist() + table[4].tolist()
name = table[2].tolist() + table[5].tolist()
for i in range(len(regnum)):
names[str(regnum[i])] = str(name[i])
# Remove and adding some names because the Class Roll List was not read properly
names['TVE18CS017'] = 'DHANESH P S'
names['TVE18CS018'] = 'DHRUV ELDHO PETER'
names['TVE18CS021'] = 'GOKUL K'
names['TVE18CS022'] = 'HIRA FATHIMA C P M'
names['TVE18CS023'] = 'HRISHIKESH T S'
names['TVE18CS032'] = 'MARIA PAUL T'
names['TVE18CS033'] = 'MEGHA NANDA J'
del(names['TVE18CS017 DHANESH P S'])
del(names['TVE18CS018 DHRUV ELDHO PETER'])
del(names['TVE18CS021 GOKUL K'])
del(names['TVE18CS022 HIRA FATHIMA C P M'])
del(names['TVE18CS023 HRISHIKESH T S'])
del(names['TVE18CS032 MARIA PAUL T'])
del(names['TVE18CS033 MEGHA NANDA J'])
del(names['Register No'])
#########################################
#The result was split across 5 pages
tables = camelot.read_pdf('result_TVE.pdf', pages='38,39,40,41,42')
regno = {}
#Looping through all the tables
for i in tables[1:]:
df = i.df
reg = df[0].tolist()
score = df[1].tolist()
for i in range(len(reg)):
if str(reg[i])[0:5] != 'TVE18':
continue
arr = str(score[i]).split(',')
gpa = 0
for j in range(len(arr)):
if(arr[j][-2] != '+'):
arr[j] = gp[arr[j][-2]]
else:
arr[j] = gp[arr[j][-3:-1]]
for k in range(len(arr)):
gpa += arr[k]*credits[k]
gpa /= float(tc)
regno[str(reg[i])] = gpa
#Student left the College :)
del(regno['TVE18CS034'])
prev_rank = 1
rank = 1
people_passed = 0
sorted_ranklist = sorted(regno.items(), key=operator.itemgetter(1))[::-1]
for i in range(len(sorted_ranklist)):
people_passed += 1
if i != 0:
if(sorted_ranklist[i-1][1] != sorted_ranklist[i][1]):
rank=people_passed
print str(rank) + ":" + names[sorted_ranklist[i][0]] + ":" + str(sorted_ranklist[i][1])
else:
print str(rank) + ":" + names[sorted_ranklist[i][0]] + ":" + str(sorted_ranklist[i][1])