Skip to content

Commit

Permalink
Updated Overall Attendance
Browse files Browse the repository at this point in the history
  • Loading branch information
ezhil56x committed Mar 31, 2024
1 parent e7d283b commit 6329fee
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,9 @@ private void downloadAttendance() {
List<Attendance> 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);
Expand All @@ -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();
Expand Down

0 comments on commit 6329fee

Please sign in to comment.