Skip to content

Commit 2ddd7d7

Browse files
Merge pull request #4 from mathanamathav/CPGA-bug-fix
CGPA bug fix & enhancement
2 parents a081c50 + d971f00 commit 2ddd7d7

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed
277 Bytes
Binary file not shown.

bunker_mod.py

+23-9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# import plotly.graph_objects as go
99
# from plotly.subplots import make_subplots
1010
import pandas as pd
11+
import numpy as np
1112

1213

1314
# def many_pieplot(res,specs,subplot_titles,labels,total_class,total_present):
@@ -249,7 +250,7 @@ def return_cgpa(session):
249250
for index,row in enumerate(rows):
250251

251252
cols = row.find_all('td')
252-
cols = [ele.text.strip() for ele in cols]
253+
cols = [ele.text for ele in cols]
253254
latest_sem_data.append([ele for ele in cols if ele])
254255
except:
255256
print("No results available !!")
@@ -271,21 +272,34 @@ def return_cgpa(session):
271272
cols = [ele.text.strip() for ele in cols]
272273
data.append([ele for ele in cols if ele])
273274
except:
274-
return {"error" : "no data"}
275+
print("No Course Info available !!")
275276
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'}
280281

281-
# Add latest sem results if available
282+
global df
283+
global latest_sem_records
284+
285+
# Preprocess latest sem results if available
282286
if len(latest_sem_data) != 0:
283287
latest_sem_data.pop(0)
284288
latest_sem_records = pd.DataFrame(latest_sem_data, columns=['COURSE SEM', 'COURSE CODE', 'COURSE TITLE', 'CREDITS', 'GRADE', 'RESULT'])
285289
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)
286296

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()
289303

290304
# CPGA calculation
291305
latest_sem = df['COURSE SEM'].max()

templates/output.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@
3636
<br>
3737
<br>
3838

39+
{% if cgpa.get("error", "") == "" %}
3940
<hr style="width:50%;height:2px;border: width 6px;">
4041
<center class="container">
4142
<h3 style="color:blue;font-family: 'Bebas Neue', cursive;">CGPA upto {{ cgpa.get("lastest_sem") }} sem : {{ cgpa.get("latest_sem_cgpa") }}</h5>
43+
{% endif %}
4244
</center>
43-
<hr style="width:50%;height:2px;border: width 6px;">
44-
4545

4646

47+
<hr style="width:50%;height:2px;border: width 6px;">
4748
{% for key in data %}
4849
<br>
4950
<center>

0 commit comments

Comments
 (0)