diff --git a/src/main/java/edu/byu/cs/autograder/score/LateDayCalculator.java b/src/main/java/edu/byu/cs/autograder/score/LateDayCalculator.java index fe340f8bf..041895106 100644 --- a/src/main/java/edu/byu/cs/autograder/score/LateDayCalculator.java +++ b/src/main/java/edu/byu/cs/autograder/score/LateDayCalculator.java @@ -41,6 +41,11 @@ public LateDayCalculator() { } public int calculateLateDays(Phase phase, String netId) throws GradingException, DataAccessException { + ZonedDateTime handInDate = ScorerHelper.getHandInDateZoned(netId); + return calculateLateDays(phase, netId, handInDate); + } + + public int calculateLateDays(Phase phase, String netId, ZonedDateTime handInDate) throws GradingException, DataAccessException { if (!ApplicationProperties.useCanvas()) return 0; int assignmentNum = PhaseUtils.getPhaseAssignmentNumber(phase); @@ -53,7 +58,6 @@ public int calculateLateDays(Phase phase, String netId) throws GradingException, throw new GradingException("Failed to get due date for assignment " + assignmentNum + " for user " + netId, e); } - ZonedDateTime handInDate = ScorerHelper.getHandInDateZoned(netId); return Math.min(getNumDaysLate(handInDate, dueDate), MAX_LATE_DAYS_TO_PENALIZE); } 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 6f9a2296b..0a2ff9e16 100644 --- a/src/main/java/edu/byu/cs/autograder/score/Scorer.java +++ b/src/main/java/edu/byu/cs/autograder/score/Scorer.java @@ -18,6 +18,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.EnumMap; import java.util.HashMap; @@ -130,18 +131,21 @@ private Submission successfullyProcessSubmission(Rubric rubric, Rubric lateAppli * Note that this operation will be performed carefully so that existing RubricItem's in Canvas * will not be overwritten by the operation. * - * @param rubric A {@link Rubric} containing values to set in Canvas. - * Any items not set will be populated with their value from Canvas. - * @param phase The phase being graded - * @param netId Net ID of student being + * @param submission Submission object of approved submission * @param penaltyPct The approved GIT_COMMITS penalty percentage * @throws GradingException When preconditions are not met. * @throws DataAccessException When the database cannot be reached. */ - public static void attemptSendToCanvas(Rubric rubric, Phase phase, String netId, int penaltyPct, String commitPenaltyMsg) throws GradingException, DataAccessException { + public static void attemptSendApprovedScoreToCanvas(Submission submission, int penaltyPct, String commitPenaltyMsg) throws GradingException, DataAccessException { + Phase phase = submission.phase(); + String netId = submission.netId(); int canvasUserId = getCanvasUserId(netId); int assignmentNum = PhaseUtils.getPhaseAssignmentNumber(phase); + //TODO: undo this change when developing more permanent solution + int daysLate = new LateDayCalculator().calculateLateDays(phase, netId, submission.timestamp().atZone(ZoneId.of("America/Denver"))); + Rubric rubric = applyLatePenalty(submission.rubric(), daysLate); + CanvasRubricAssessment newAssessment = constructCanvasRubricAssessment(rubric, phase); if (PhaseUtils.phaseHasCommitPenalty(phase)) { @@ -286,7 +290,7 @@ private boolean passed(Rubric rubric) { return passoffTestItem.results().score() >= passoffTestItem.results().possiblePoints(); } - private Rubric applyLatePenalty(Rubric rubric, int daysLate) { + private static Rubric applyLatePenalty(Rubric rubric, int daysLate) { EnumMap items = new EnumMap<>(Rubric.RubricType.class); float lateAdjustment = daysLate * PER_DAY_LATE_PENALTY; for(Map.Entry entry : rubric.items().entrySet()) { diff --git a/src/main/java/edu/byu/cs/util/SubmissionUtils.java b/src/main/java/edu/byu/cs/util/SubmissionUtils.java index 2cb7b815d..93d0b7e5c 100644 --- a/src/main/java/edu/byu/cs/util/SubmissionUtils.java +++ b/src/main/java/edu/byu/cs/util/SubmissionUtils.java @@ -75,8 +75,7 @@ public static void approveSubmission( // Send score to Grade-book float approvedScore = Scorer.prepareModifiedScore(withheldSubmission.score(), penaltyPct); String gitCommitsComment = "Submission initially blocked due to low commits. Submission approved by admin " + approverNetId; - Scorer.attemptSendToCanvas(withheldSubmission.rubric(), withheldSubmission.phase(), withheldSubmission.netId(), - penaltyPct, gitCommitsComment); + Scorer.attemptSendApprovedScoreToCanvas(withheldSubmission, penaltyPct, gitCommitsComment); // Done LOGGER.info("Approved submission for %s on phase %s with score %f. Approval by %s. Affected %d submissions."