-
Notifications
You must be signed in to change notification settings - Fork 5
/
sgparank.py
125 lines (120 loc) · 3.74 KB
/
sgparank.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
def grade(m):
grade_point = 0
grade_letter = ''
if m >= 90:
grade_letter += ',S+,'
grade_point = 10
elif m >= 80:
grade_letter += ',S,'
grade_point = 9
elif m >= 70:
grade_letter += ',A,'
grade_point = 8
elif m >= 60:
grade_letter += ',B,'
grade_point = 7
elif m >= 50:
grade_letter += ',C,'
grade_point = 6
elif m >= 45:
grade_letter += ',D,'
grade_point = 5
elif m >= 40:
grade_letter += ',E,'
grade_point = 4
elif m >= 0:
grade_letter += ',F,'
grade_point = 0
elif m == -1:
grade_letter += ',Ab,'
grade_point = 0
return grade_letter, grade_point
def calc(sub, subj, count1, count2, count3, record):
c = count1 * 4 + count3 * 3 + count2 * 2
cp = 0
for i in range(0, count1):
record += str(subj.pop(0))
st, g = grade(sub.pop(0))
record += st
cp += g * 4
if count3 != 0:
for i in range(0, count3):
record += str(subj.pop(0))
st, g = grade(sub.pop(0))
record += st
cp += g * 3
for i in range(0, count2):
record += str(subj.pop(0))
st, g = grade(sub.pop(0))
record += st
cp += g * 2
gp = str(round((cp / c), 2))
return record, gp
def gpa2(year, branch, low, high, sem, cycle):
if int(sem) == 1 or int(sem) == 2:
count1 = 5
count2 = 2
count3 = 0
elif int(sem) == 5 or int(sem) == 6:
count1 = 4
count2 = 2
count3 = 2
elif int(sem) == 7 or int(sem) == 8:
count1 = 3
count2 = 3
count3 = 2
else:
count1 = 6
count2 = 2
count3 = 0
if cycle == 'P':
marks_code = 36
gpa_col = 9
else:
marks_code = 41
gpa_col = 10
pth = 'ExcelFiles2/'
import pandas as pd
df = pd.read_csv("test2.txt", sep=",")
sub, subj = [], []
with open('gpa2.txt', 'w+') as f:
for i in range(0, df.shape[0]):
record = ''
string = ''
record += df.iloc[i, 0] + ',' + df.iloc[i, 1] + ','
for j in range(5, marks_code, 5):
# record += df.iloc[i, j-3) + ','
if int(sem) == 1 and cycle == 'C' and j == 35:
string = df.iloc[i, j - 3] + ',' + df.iloc[i, j + 1]
elif df.iloc[i, j + 1] == 'P':
subj.append(df.iloc[i, j - 3])
sub.append(int(df.iloc[i, j]))
elif df.iloc[i, j + 1] == 'A':
subj.append(df.iloc[i, j - 3])
sub.append(-1)
else:
subj.append(df.iloc[i, j - 3])
sub.append(0)
record, sgpa = calc(sub, subj, count1, count2, count3, record)
percent = str(round((float(sgpa) - 0.750) * 10, 2))
if cycle != 'C':
record += sgpa + ',' + percent + ','
else:
record += string + ',' + sgpa + ',' + percent + ','
print(record, end='\t')
print('\n')
f.write(record + '\n')
f.close()
cols = pd.read_csv("gpa2.txt").columns
r = [0, 1, -3, -2]
df1 = pd.read_csv("gpa2.txt", sep=",", usecols=cols[r])
df1.to_csv("gpa2r.txt", sep=",", index=False)
df2 = pd.read_csv("gpa2r.txt", sep=",", header=None)
df2.columns = ['USN', 'Name', 'GPA', 'Percentage']
try:
df2 = df2.sort_values(by=[df2.columns[2]], ascending=False)
except AttributeError:
print(" ")
writer = pd.ExcelWriter(pth + year + branch + str(low) + '-' + str(high - 1) + 'rank2.xls')
df2.to_excel(writer, sheet_name='Sheet1', index=False)
writer.save()