From 040af87ef7a76c8a7a87b2cc17838b90609b0383 Mon Sep 17 00:00:00 2001 From: 19mdavenport Date: Tue, 26 Nov 2024 01:17:14 +0000 Subject: [PATCH] fix late penalty notes --- .../edu/byu/cs/autograder/score/Scorer.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/edu/byu/cs/autograder/score/Scorer.java b/src/main/java/edu/byu/cs/autograder/score/Scorer.java index c090ddcb..1e390dbc 100644 --- a/src/main/java/edu/byu/cs/autograder/score/Scorer.java +++ b/src/main/java/edu/byu/cs/autograder/score/Scorer.java @@ -429,11 +429,7 @@ public Submission generateSubmissionObject(Rubric rubric, CommitVerificationResu Integer maxLateDays = DaoService.getConfigurationDao().getConfiguration(ConfigurationDao.Configuration.MAX_LATE_DAYS_TO_PENALIZE, Integer.class); - if (numDaysLate >= maxLateDays) - notes += " Late penalty maxed out at " + numDaysLate + " days late: -"; - else if (numDaysLate > 0) - notes += " " + numDaysLate + " days late: -"; - notes += (int)(numDaysLate * PER_DAY_LATE_PENALTY * 100) + "% "; + notes = makeLatePenaltyNotes(numDaysLate, maxLateDays, notes); ZonedDateTime handInDate = ScorerHelper.getHandInDateZoned(netId); Submission.VerifiedStatus verifiedStatus; @@ -465,6 +461,25 @@ else if (numDaysLate > 0) ); } + private String makeLatePenaltyNotes(int numDaysLate, int maxLateDays, String origNotes) { + if (numDaysLate <= 0) { + return origNotes; + } + + String penaltyPercentage = String.format("-%d%%", (int)(numDaysLate * PER_DAY_LATE_PENALTY * 100)); + String lateNotes; + if (numDaysLate >= maxLateDays) { + lateNotes = "Late penalty maxed out: " + penaltyPercentage; + } else { + lateNotes = String.format("%d days late: %s", numDaysLate, penaltyPercentage); + } + + if (origNotes == null || origNotes.isBlank()) { + return lateNotes; + } + return String.format("%s\n%s", origNotes, lateNotes); + } + private void sendToCanvas(int userId, int assignmentNum, CanvasRubricAssessment assessment, String notes) throws GradingException { sendToCanvas(userId, assignmentNum, assessment, notes, gradingContext.netId());