From 99f98232f459164cc2eb1fb87ffcdf1c8f2a808b Mon Sep 17 00:00:00 2001 From: Sujit Kumar <60378235+therealsujitk@users.noreply.github.com> Date: Sun, 28 Jul 2024 16:31:59 +0530 Subject: [PATCH] fix: incorrect attendance excess for some courses --- .../adapters/TimetableItemAdapter.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/tk/therealsuji/vtopchennai/adapters/TimetableItemAdapter.java b/app/src/main/java/tk/therealsuji/vtopchennai/adapters/TimetableItemAdapter.java index 8591557..91567fd 100644 --- a/app/src/main/java/tk/therealsuji/vtopchennai/adapters/TimetableItemAdapter.java +++ b/app/src/main/java/tk/therealsuji/vtopchennai/adapters/TimetableItemAdapter.java @@ -178,24 +178,27 @@ public void onSuccess(@io.reactivex.rxjava3.annotations.NonNull Course.AllData c // percentage = attended * 100 / total // // CALCULATING POSITIVE EXCESS - // (attended) * 100 / (total + x) = 74 - // 100 * attended = 74 * total + 74 * x - // x = (100 * attended - 74 * total) / 74 + // (attended) * 100 / (total + x) = 75 + // 100 * attended = 75 * total + 75 * x + // x = (100 * attended - 75 * total) / 75 + // positiveExcess = floor(x) <-- can afford these many days off // // CALCULATING NEGATIVE EXCESS - // (attended + x) * 100 / (total + x) = 74 - // 100 * attended + 100 * x = 74 * total + 74 * x - // 26 * x = 74 * total - 100 * attended - // x = (74 * total - 100 * attended) / 26 + // (attended + x) * 100 / (total + x) = 75 + // 100 * attended + 100 * x = 75 * total + 75 * x + // 25 * x = 75 * total - 100 * attended + // x = (75 * total - 100 * attended) / 25 + // negativeExcess = ceil(x) <-- requires these many extra classes // if (SettingsRepository.getCGPA(timetableItem.getContext()) < 9) { - double attendanceExcess = 100 * course.attendanceAttended - 74 * course.attendanceTotal; + double attendanceExcess = 100 * course.attendanceAttended - 75 * course.attendanceTotal; if (course.attendancePercentage < 75) { - attendanceExcess = Math.floor(attendanceExcess / 26) + 1; + // We use floor() instead of ceil() here because the argument is negative + attendanceExcess = Math.floor(attendanceExcess / 25); attendanceProgress.setSecondaryProgress(75); } else { - attendanceExcess = Math.ceil(attendanceExcess / 74) - 1; + attendanceExcess = Math.floor(attendanceExcess / 75); } attendanceExcessText.setVisibility(View.VISIBLE);