Skip to content

Commit

Permalink
fix: incorrect attendance excess for some courses
Browse files Browse the repository at this point in the history
  • Loading branch information
therealsujitk committed Jul 28, 2024
1 parent 3f3f89e commit 99f9823
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 99f9823

Please sign in to comment.