diff --git a/app/src/main/java/tk/therealsuji/vtopchennai/services/VTOPService.java b/app/src/main/java/tk/therealsuji/vtopchennai/services/VTOPService.java index 44ff306..ed0f868 100644 --- a/app/src/main/java/tk/therealsuji/vtopchennai/services/VTOPService.java +++ b/app/src/main/java/tk/therealsuji/vtopchennai/services/VTOPService.java @@ -1300,7 +1300,9 @@ private void downloadAttendance() { List attendance = new ArrayList<>(); float overallAttendance = 0; - int attendanceLength = 0; + + int attendedClasses = 0; + int totalClasses = 0; for (int i = 0; i < attendanceArray.length(); ++i) { JSONObject attendanceObject = attendanceArray.getJSONObject(i); @@ -1318,16 +1320,15 @@ private void downloadAttendance() { attendanceItem.total = this.getIntegerValue(attendanceObject, "total"); if (attendanceItem.attended != null && attendanceItem.total != null && attendanceItem.total != 0) { - attendanceItem.percentage = (int) Math.ceil((attendanceItem.attended * 100.0) / attendanceItem.total); - overallAttendance += attendanceItem.percentage; - ++attendanceLength; + attendedClasses += attendanceItem.attended; + totalClasses += attendanceItem.total; } attendance.add(attendanceItem); } - if (attendanceLength != 0) { - overallAttendance /= attendanceLength; + if (totalClasses != 0) { + overallAttendance = (attendedClasses * 100.0f) / totalClasses; } sharedPreferences.edit().putInt("overallAttendance", (int) overallAttendance).apply();