Skip to content

Commit

Permalink
Fix inconsistent attendance percentages (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
therealsujitk committed Nov 6, 2023
1 parent 7cc625e commit 24c082c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,28 @@ public void onSuccess(@io.reactivex.rxjava3.annotations.NonNull Course.AllData c
attendanceText.setText(new DecimalFormat("#'%'").format(course.attendancePercentage));
attendanceProgress.setProgress(course.attendancePercentage);

//
// percentage = attended * 100 / total
//
// CALCULATING POSITIVE EXCESS
// (attended) * 100 / (total + x) = 74
// 100 * attended = 74 * total + 74 * x
// x = (100 * attended - 74 * total) / 74
//
// 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
//
if (SettingsRepository.getCGPA(timetableItem.getContext()) < 9) {
int attendanceExcess = 4 * course.attendanceAttended - 3 * course.attendanceTotal;
double attendanceExcess = 100 * course.attendanceAttended - 74 * course.attendanceTotal;

if (course.attendancePercentage < 75) {
attendanceExcess = Math.floor(attendanceExcess / 26) + 1;
attendanceProgress.setSecondaryProgress(75);
} else {
attendanceExcess /= 3;
attendanceExcess = Math.ceil(attendanceExcess / 74) - 1;
}

attendanceExcessText.setVisibility(View.VISIBLE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ private void downloadAttendance() {
attendanceItem.total = this.getIntegerValue(attendanceObject, "total");

if (attendanceItem.attended != null && attendanceItem.total != null && attendanceItem.total != 0) {
attendanceItem.percentage = (attendanceItem.attended * 100) / attendanceItem.total;
attendanceItem.percentage = (int) Math.ceil((attendanceItem.attended * 100.0) / attendanceItem.total);
overallAttendance += attendanceItem.percentage;
++attendanceLength;
}
Expand Down

0 comments on commit 24c082c

Please sign in to comment.