-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathResult_Convertor.py
479 lines (385 loc) · 20.3 KB
/
Result_Convertor.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
import streamlit as st
import pandas as pd
import time
import re
import numpy as np
from itdepartment import getTabledownloadLink, displayPDF, pdfToText, cleanText, studentDetails, cleanMarks,getSubjectCodes,getSubjectNames
from st_aggrid import AgGrid
from utils import PdfProcessor
@st.cache_resource
def concat_subjects(d: dict):
#function to concat subject wise marks
return pd.concat([i for i in d.values()], axis=1)
@st.cache_resource
def cleanTextRe(text: str) -> str:
text = re.sub(r'^[a-zA-Z]{2}', '', text)
return text
@st.cache_resource
def extractPrnNo(text: str):
# function to extract prn no from text
pattern = re.findall(
r'7\d{7}[a-zA-Z]*', text
)
d = {'PRN-NO': []}
for i in pattern:
temp = i.split()
d['PRN-NO'].append(temp[0])
return pd.DataFrame(d)
@st.cache_resource
def replaceNan(df: pd.DataFrame) -> pd.DataFrame:
# function to replace nan values
df = df.replace('nnn', np.nan)
df = df.replace('nan', np.nan)
df = df.replace('nnnn', np.nan)
df = df.replace('nnnn', np.nan)
df = df.replace('nan', np.nan)
df = df.replace('nnnnn', np.nan)
df = df.replace('nnnnn', np.nan)
df = df.replace('nnnnnnn', np.nan)
df = df.replace('nnnnnnn', np.nan)
df = df.replace('nnn', np.nan)
df = df.replace('nan', np.nan)
df = df.replace('nnnn', np.nan)
return df
def App():
st.markdown("""
## :outbox_tray: Result Analyser :outbox_tray:
<a href="https://github.com/Suraj1089/SPPU-Result-Convertor/network/members"><img src="https://img.shields.io/github/forks/Suraj1089/SPPU-Result-Convertor" alt="Forks Badge"/></a>
<a href="https://github.com/Suraj1089/SPPU-Result-Convertor/pulls"><img src="https://img.shields.io/github/issues-pr/Suraj1089/SPPU-Result-Convertor" alt="Pull Requests Badge"/></a>
<a href="https://github.com/Suraj1089/SPPU-Result-Convertor/issues"><img src="https://img.shields.io/github/issues/Suraj1089/SPPU-Result-Convertor" alt="Issues Badge"/></a>
<a href="https://github.com/Suraj1089/SPPU-Result-Convertor/graphs/contributors"><img alt="GitHub contributors" src="https://img.shields.io/github/contributors/Suraj1089/SPPU-Result-Convertor?color=2b9348"></a>
[![GitHub license](https://img.shields.io/github/license/Suraj1089/SPPU-Result-Convertor?color=orange)](https://github.com/Suraj1089/SPPU-Result-Convertor/blob/main/LICENSE)
[![GitHub commit activity](https://img.shields.io/github/commit-activity/m/Suraj1089/SPPU-Result-Convertor)](https://github.com/Suraj1089/SPPU-Result-Convertor/graphs/commit-activity)
[![GitHub issues](https://img.shields.io/github/issues/Suraj1089/SPPU-Result-Convertor?color=blue)](https://github.com/Suraj1089/SPPU-Result-Convertor/issues)
[![GitHub stars](https://img.shields.io/github/stars/Suraj1089/SPPU-Result-Convertor)](https://github.com/Suraj1089/SPPU-Result-Convertor/stargazers)
""", unsafe_allow_html=True)
col1, col2 = st.columns(2)
with col1:
department = st.selectbox(
'Select Department',
('IT', 'COMPUTER', 'AIDS', 'MECHANICAL', 'E&TC',
'CIVIL', 'ELECTRICAL', 'INSTRUMENTATION')
)
st.success(f'Selected department is {department}')
with col2:
year = st.selectbox(
'SELECT YEAR',
('BE','TE','SE','FE')
)
st.success(f'Selected year is {year}')
if department:
pdf_file = st.file_uploader(label="Upload Pdf File", type="pdf")
if pdf_file:
# display document
with st.expander(label="Show Uploaded File"):
displayPDF(pdf_file)
try:
text = pdfToText(pdf_file)
except FileNotFoundError:
st.error('File not found try again!')
return
# store text to find subject names
textForSubjectNames = text
subjectNamesList = []
# other departments than IT
if department !='IT':
st.info('Enter subject Names')
subjectNamesList = st.text_area(label="Enter subject Names(Each subject on separate line)")
subjectNamesListBtn = st.button(label='Add Subjects')
if subjectNamesListBtn and subjectNamesList:
st.success('Selected subjects are')
# convert string to list
subjectNamesList = subjectNamesList.split('\n')
st.write(subjectNamesList)
# store the subjectNames in session state
if 'subjectNamesList' not in st.session_state:
st.session_state['subjectnamesList'] = subjectNamesList
else:
st.error('Subject Name must be added to work.')
text = cleanText(text)
try:
seat_no_name = studentDetails(text)
student_prn_no = extractPrnNo(text)
student_data = pd.concat(
[seat_no_name, student_prn_no], axis=1)
except Exception as e:
st.error(
f"Error in extracting data from pdf. Please check the pdf file and try again. {e}")
return
# show progress bar
# Create an empty container for the progress bar
progressBar = st.progress(0, text='Processing File')
for percentageComplete in range(100):
time.sleep(0.05)
progressBar.progress(percentageComplete + 1, text='Processing File')
# hide progress bar after finish
progressBar.empty()
with st.expander('Show Students Details'):
# remove columns with all nan values
student_data = student_data.dropna(axis=1, how='all')
storeStudentData = student_data.copy()
AgGrid(student_data)
st.spinner('Processing...')
time.sleep(4)
st.text("")
downloadButtonAllCol1,downloadButtonAllCol2 = st.columns(2)
with downloadButtonAllCol1:
st.download_button(
'Download CSV File',
data=storeStudentData.to_csv().encode('utf-8'),
file_name=f"{str(pdf_file.name).split('.')[0]}.csv",
mime='text/csv'
)
with downloadButtonAllCol2:
st.markdown(getTabledownloadLink(
df=storeStudentData,fileName=f"{str(pdf_file.name).split('.')[0]}.xlsx",), unsafe_allow_html=True)
with st.expander('Show Students Marks by Subject Code'):
# text = cleanTextRe(text)
subject_codes = st.text_input(
'Enter subject code to see subject marks(One at at time)')
subject_codes_submit = st.button(
'Submit', key='one_subject_codes_submit')
if subject_codes_submit:
try:
subject_codes = subject_codes.split()
subject_codes = {i: None for i in subject_codes}
st.markdown('#### Selected subjects')
st.write(subject_codes)
st.spinner('Processing...')
pattern = r'[A-Z]{3}'
text = cleanTextRe(text)
text = re.sub(pattern, '', text)
try:
marks = cleanMarks(text, subject_codes)
except Exception as e:
st.error(
f'Error in processing pdf. Please check the pdf file and try again {e}')
return
try:
student_marks = concat_subjects(marks)
student_marks = pd.concat(
[student_data, student_marks], axis=1)
except Exception as e:
st.error(
f'Error in extracting marks. Please check the pdf file and try again.@concat_subjects {e}')
return
st.success('Done!....')
# remove columns with all nan values
# student_marks = replaceNan(student_marks)
student_marks = student_marks.replace(
'nnnnnnn', np.nan)
student_marks = student_marks.replace(
'nnnnnnn', np.nan)
student_marks = student_marks.replace('nnn', np.nan)
student_marks = student_marks.replace('nan', np.nan)
student_marks = student_marks.replace('nnnn', np.nan)
student_marks = student_marks.replace('nnn', np.nan)
student_marks = student_marks.dropna(axis=1, how='all')
studentMarksStore = student_marks.copy()
AgGrid(student_marks)
st.spinner('Processing...')
time.sleep(4)
st.text("")
downloadButtonCol1,downloadButtonCol2 = st.columns(2)
with downloadButtonCol1:
st.download_button(
'Download CSV File',
data=studentMarksStore.to_csv().encode('utf-8'),
file_name=f"{str(pdf_file.name).split('.')[0]}.csv",
mime='text/csv'
)
with downloadButtonCol2:
st.markdown(getTabledownloadLink(
df=studentMarksStore,fileName=f"{str(pdf_file.name).split('.')[0]}.xlsx",), unsafe_allow_html=True)
except Exception as e:
st.error(f'Please enter valid subject code or cannot convert this marks {e}')
return
with st.expander('Download Student marks in Excel/Csv File'):
st.warning(
'Enter subject codes those are common for all student(Exclude honors courses)')
subject_codes = st.text_input(
'Enter subject codes separated by space Example: 18IT101 18IT102')
subject_codes_submit = st.button(
'Submit', key='all_subject_codes_submit')
if subject_codes_submit:
try:
subject_codes = subject_codes.split()
subject_codes = {i: None for i in subject_codes}
st.markdown('### Selected subjects are :')
student_data = replaceNan(student_data)
st.write(subject_codes)
st.spinner('Processing...')
stored_text = text
text = cleanTextRe(text)
# pattern = r'[A-Z]\w*[A-Z]'
pattern = r'[A-Z]{3}'
text = re.sub(pattern, '', text)
# uncomment to log the data
try:
marks = cleanMarks(text, subject_codes)
except Exception as e:
st.error(
f'Error in extracting marks. Please check the pdf file and try again.@cleanMarks {e}')
return
try:
student_marks = concat_subjects(marks)
student_marks = pd.concat(
[student_data, student_marks], axis=1)
except Exception as e:
st.error(
f'Error in extracting marks. Please check the pdf file and try again.@concat_subjects {e}')
return
student_marks = replaceNan(student_marks)
try:
# find sgpa
print('trying to extract spga')
pattern = re.findall(r'SGPA1?\W*\d*\W*\d*', stored_text)
# SGPA1: 8.3
d = {'sgpa':[],'score':[]}
for i in pattern:
try:
temp = i.split()
if len(temp) == 1:
temp.append('00')
except Exception as e:
temp = ['SGPA1','00']
d['sgpa'].append(temp[0])
d['score'].append(temp[1])
sgpa = pd.DataFrame(d)
student_marks = pd.concat([student_marks,sgpa],axis=1)
except:
print('error in extracting spga')
st.error('Error in extracting sgpa')
pass
student_marks = student_marks.dropna(axis=1, how='all')
# st.markdown(getTabledownloadLink(
# student_marks), unsafe_allow_html=True)
downloadButtonAllCol1,downloadButtonAllCol2 = st.columns(2)
with downloadButtonAllCol1:
st.download_button(
'Download CSV File',
data=student_marks.to_csv().encode('utf-8'),
file_name=f"{str(pdf_file.name).split('.')[0]}.csv",
mime='text/csv'
)
with downloadButtonAllCol2:
st.markdown(getTabledownloadLink(
df=student_marks,fileName=f"{str(pdf_file.name).split('.')[0]}.xlsx",), unsafe_allow_html=True)
except Exception as e:
st.error(
f'Please enter valid subject codes OR Cannot convert following subject codes to excel file {e}')
return
with st.expander('Advance subject wise marks'):
st.warning('Use this feature only if above feature is not working')
st.warning('Keep default values if you are not sure')
result_type = st.selectbox(
'Select result type', ['SEMESTER', 'YEAR'])
st.write('You selected:', result_type)
# IF SEMESTER RESULT then 10 SUBJECTS ELSE 20
if result_type == 'SEMESTER':
options = st.multiselect(
'select subject codes',
getSubjectCodes(text,10)
)
else:
options = st.multiselect(
'select subject codes',
getSubjectCodes(text,20)
)
st.write('Selected subject codes:', options)
if options:
subject_names = st.multiselect(
'select subject names',
list(set(getSubjectNames(textForSubjectNames)))
)
st.write('Selected subject names:', subject_names)
subject_codes = st.text_input(
'Enter subject code')
subject_name = st.text_input(
"Enter subject name"
)
pattern = st.selectbox(
options=['[A-Z]{3}','[A-Z]\w*[A-Z]'],
label='Try changing pattern if not working(Select one) optional',
)
subject_codes_submit = st.button(
'Submit', key='one_subject_codes_submit_advance')
if subject_codes_submit:
try:
subject_codes = subject_codes.split()
subject_codes = {i: None for i in subject_codes}
st.markdown('#### Selected subjects')
st.write(subject_codes)
st.spinner('Processing...')
text = cleanTextRe(text)
text = text.replace(subject_name,'')
text = re.sub(pattern, '', text)
try:
marks = cleanMarks(text, subject_codes)
except:
st.error(
'Error in processing pdf. Please check the pdf file and try again')
return
try:
student_marks = concat_subjects(marks)
student_marks = pd.concat(
[student_data, student_marks], axis=1)
except:
st.error(
'Error in extracting marks. Please check the pdf file and try again.@concat_subjects')
return
st.success('Done!....')
# remove columns with all nan values
student_marks = replaceNan(student_marks)
student_marks = student_marks.dropna(axis=1, how='all')
studentMarksStore = student_marks.copy()
AgGrid(student_marks)
st.spinner('Processing...')
time.sleep(4)
st.text("")
downloadButtonAdvanceCol1,downloadButtonAdvanceCol2 = st.columns(2)
with downloadButtonAdvanceCol1:
st.download_button(
'Download CSV File',
data=studentMarksStore.to_csv().encode('utf-8'),
file_name=f"{str(pdf_file.name).split('.')[0]}.csv",
mime='text/csv'
)
with downloadButtonAdvanceCol2:
st.markdown(getTabledownloadLink(
df=studentMarksStore,fileName=f"{str(pdf_file.name).split('.')[0]}.xlsx",), unsafe_allow_html=True)
except:
st.error('Please enter valid subject code or cannot convert this marks')
return
else:
st.write('selected department is ', department)
if __name__ == "__main__":
# set page title and icon
try:
st.set_page_config(
page_title='Result Analysis',
page_icon='📃',
)
with st.sidebar:
st.header('Our Contributors')
import streamlit as st
st.markdown(
"""
<style>
/* Add CSS styles here */
.avatar-container {
display: inline-block;
margin-right: 20px; /* Adjust the margin to your desired spacing */
}
</style>
<div class="avatar-container">
<a href="https://github.com/Suraj1089/SPPU-Result-Convertor/graphs/contributors">
<img src="https://contrib.rocks/image?max=50&repo=Suraj1089/SPPU-Result-Convertor" />
</a>
</div>
""",
unsafe_allow_html=True
)
except Exception as e:
pass
App()