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,34 @@ 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
-
278
- cols = data . pop ( 0 )
279
- df = pd . DataFrame ( data , columns = cols )
277
+ print ( "No Course Info available !!" )
278
+
279
+ if len ( data ) == 0 and len ( latest_sem_data ) == 0 :
280
+ return { 'error' : 'No data' }
280
281
281
- # Add latest sem results if available
282
+ global df
283
+ global latest_sem_records
284
+
285
+ # Preprocess latest sem results if available
282
286
if len (latest_sem_data ) != 0 :
283
287
latest_sem_data .pop (0 )
284
288
latest_sem_records = pd .DataFrame (latest_sem_data , columns = ['COURSE SEM' , 'COURSE CODE' , 'COURSE TITLE' , 'CREDITS' , 'GRADE' , 'RESULT' ])
285
289
latest_sem_records ['GRADE' ] = latest_sem_records ['GRADE' ].str .split ().str [- 1 ]
290
+ latest_sem_records ['COURSE SEM' ] = latest_sem_records ['COURSE SEM' ].replace (r'^\s*$' , np .nan , regex = True )
291
+ latest_sem_records ['COURSE SEM' ].fillna (method = 'ffill' , inplace = True )
292
+
293
+ try :
294
+ cols = data .pop (0 )
295
+ df = pd .DataFrame (data , columns = cols )
286
296
287
- df = df .append (latest_sem_records , ignore_index = True )
288
- df .drop_duplicates (subset = "COURSE CODE" , keep = "last" , inplace = True )
297
+ # Add latest sem results if available
298
+ if len (latest_sem_data ) != 0 :
299
+ df = df .append (latest_sem_records , ignore_index = True )
300
+ df .drop_duplicates (subset = "COURSE CODE" , keep = "last" , inplace = True )
301
+ except :
302
+ df = latest_sem_records .copy ()
289
303
290
304
# CPGA calculation
291
305
latest_sem = df ['COURSE SEM' ].max ()
0 commit comments