8
8
# import plotly.graph_objects as go
9
9
# from plotly.subplots import make_subplots
10
10
import pandas as pd
11
+ import numpy as np
11
12
12
13
13
14
# def many_pieplot(res,specs,subplot_titles,labels,total_class,total_present):
@@ -249,7 +250,7 @@ def return_cgpa(session):
249
250
for index ,row in enumerate (rows ):
250
251
251
252
cols = row .find_all ('td' )
252
- cols = [ele .text . strip () for ele in cols ]
253
+ cols = [ele .text for ele in cols ]
253
254
latest_sem_data .append ([ele for ele in cols if ele ])
254
255
except :
255
256
print ("No results available !!" )
@@ -271,21 +272,31 @@ def return_cgpa(session):
271
272
cols = [ele .text .strip () for ele in cols ]
272
273
data .append ([ele for ele in cols if ele ])
273
274
except :
274
- return { "error" : "no data" }
275
+ print ( "No Course Info available !!" )
275
276
else :
276
- return { "error" : "no data" }
277
+ print ( "No Course Info available !!" )
277
278
278
- cols = data . pop ( 0 )
279
- df = pd . DataFrame ( data , columns = cols )
280
-
281
- # Add latest sem results if available
279
+ global df
280
+ global latest_sem_records
281
+
282
+ # Preprocess latest sem results if available
282
283
if len (latest_sem_data ) != 0 :
283
284
latest_sem_data .pop (0 )
284
285
latest_sem_records = pd .DataFrame (latest_sem_data , columns = ['COURSE SEM' , 'COURSE CODE' , 'COURSE TITLE' , 'CREDITS' , 'GRADE' , 'RESULT' ])
285
286
latest_sem_records ['GRADE' ] = latest_sem_records ['GRADE' ].str .split ().str [- 1 ]
287
+ latest_sem_records ['COURSE SEM' ] = latest_sem_records ['COURSE SEM' ].replace (r'^\s*$' , np .nan , regex = True )
288
+ latest_sem_records ['COURSE SEM' ].fillna (method = 'ffill' , inplace = True )
286
289
287
- df = df .append (latest_sem_records , ignore_index = True )
288
- df .drop_duplicates (subset = "COURSE CODE" , keep = "last" , inplace = True )
290
+ try :
291
+ cols = data .pop (0 )
292
+ df = pd .DataFrame (data , columns = cols )
293
+
294
+ # Add latest sem results if available
295
+ if len (latest_sem_data ) != 0 :
296
+ df = df .append (latest_sem_records , ignore_index = True )
297
+ df .drop_duplicates (subset = "COURSE CODE" , keep = "last" , inplace = True )
298
+ except :
299
+ df = latest_sem_records .copy ()
289
300
290
301
# CPGA calculation
291
302
latest_sem = df ['COURSE SEM' ].max ()
0 commit comments