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 96c4c6908..81cf81fac 100644 --- a/src/main/java/edu/byu/cs/autograder/score/Scorer.java +++ b/src/main/java/edu/byu/cs/autograder/score/Scorer.java @@ -17,7 +17,9 @@ import org.slf4j.LoggerFactory; import java.time.ZonedDateTime; +import java.util.EnumMap; import java.util.HashMap; +import java.util.Map; import static edu.byu.cs.model.Submission.VerifiedStatus; @@ -59,6 +61,7 @@ public Submission score(Rubric rubric, CommitVerificationResult commitVerificati } int daysLate = new LateDayCalculator().calculateLateDays(gradingContext.phase(), gradingContext.netId()); + applyLatePenalty(rubric.items(), daysLate); float thisScore = calculateScoreWithLatePenalty(rubric, daysLate); // Validate several conditions before submitting to the grade-book @@ -83,7 +86,7 @@ public Submission score(Rubric rubric, CommitVerificationResult commitVerificati */ private Rubric transformRubric(Rubric rubric) throws GradingException, DataAccessException { rubric = CanvasUtils.decimalScoreToPoints(gradingContext.phase(), rubric); - return annotateRubric(rubric); + return new Rubric(rubric.items(), passed(rubric), rubric.notes()); } @@ -115,7 +118,7 @@ private Submission successfullyProcessSubmission( "Would have attempted grade-book submission, but skipped due to application properties."); } - AssessmentSubmittalRemnants submittalRemnants = attemptSendToCanvas(rubric, commitVerificationResult, daysLate, false); + AssessmentSubmittalRemnants submittalRemnants = attemptSendToCanvas(rubric, commitVerificationResult, false); return generateSubmissionObject(rubric, commitVerificationResult, daysLate, thisScore, submittalRemnants.notes); } @@ -145,7 +148,7 @@ public void attemptSendToCanvas(Rubric rubric, int penaltyPct, String commitPena penaltyPct, commitPenaltyMsg, null, null, null, null); } - attemptSendToCanvas(rubric, verification, 0, forceSendScore); + attemptSendToCanvas(rubric, verification, forceSendScore); } /** @@ -159,16 +162,14 @@ public void attemptSendToCanvas(Rubric rubric, int penaltyPct, String commitPena * @throws GradingException When pre-conditions are not met. */ private AssessmentSubmittalRemnants attemptSendToCanvas( - Rubric rubric, CommitVerificationResult commitVerificationResult, - int daysLate, boolean forceSendScore + Rubric rubric, CommitVerificationResult commitVerificationResult, boolean forceSendScore ) throws DataAccessException, GradingException { int canvasUserId = getCanvasUserId(); int assignmentNum = PhaseUtils.getPhaseAssignmentNumber(gradingContext.phase()); CanvasRubricAssessment existingAssessment = getExistingAssessment(canvasUserId, assignmentNum); - CanvasRubricAssessment newAssessment = - addExistingPoints(constructCanvasRubricAssessment(rubric, daysLate), existingAssessment); + CanvasRubricAssessment newAssessment = addExistingPoints(constructCanvasRubricAssessment(rubric), existingAssessment); setCommitVerificationPenalty(newAssessment, gradingContext, commitVerificationResult); // prevent score from being saved to canvas if it will lower their score @@ -260,21 +261,10 @@ private int getCanvasUserId() throws DataAccessException { return user.canvasUserId(); } - private CanvasRubricAssessment constructCanvasRubricAssessment(Rubric rubric, int daysLate) + private CanvasRubricAssessment constructCanvasRubricAssessment(Rubric rubric) throws DataAccessException, GradingException { RubricConfig rubricConfig = DaoService.getRubricConfigDao().getRubricConfig(gradingContext.phase()); - float lateAdjustment = daysLate * PER_DAY_LATE_PENALTY; - return CanvasUtils.convertToAssessment(rubric, rubricConfig, lateAdjustment, gradingContext.phase()); - } - - /** - * Annotates the rubric with notes and passed status - * - * @param rubric the rubric to annotate - * @return the annotated rubric - */ - private Rubric annotateRubric(Rubric rubric) { - return new Rubric(rubric.items(), passed(rubric), rubric.notes()); + return CanvasUtils.convertToAssessment(rubric, rubricConfig, gradingContext.phase()); } private boolean passed(Rubric rubric) { @@ -288,6 +278,21 @@ private boolean passed(Rubric rubric) { return passoffTestItem.results().score() >= passoffTestItem.results().possiblePoints(); } + private void applyLatePenalty(EnumMap items, int daysLate) { + float lateAdjustment = daysLate * PER_DAY_LATE_PENALTY; + for(Map.Entry entry : items.entrySet()) { + Rubric.Results results = entry.getValue().results(); + results = new Rubric.Results(results.notes(), + results.score() * (1 - lateAdjustment), + results.possiblePoints(), + results.testResults(), + results.textResults()); + Rubric.RubricItem rubricItem = entry.getValue(); + rubricItem = new Rubric.RubricItem(rubricItem.category(), results, rubricItem.criteria()); + items.put(entry.getKey(), rubricItem); + } + } + /** * Returns a new CanvasRubricAssessment that represents the result of merging `assessment` into `existing`. *
diff --git a/src/main/java/edu/byu/cs/canvas/CanvasUtils.java b/src/main/java/edu/byu/cs/canvas/CanvasUtils.java index 57d59e4ac..40eed7573 100644 --- a/src/main/java/edu/byu/cs/canvas/CanvasUtils.java +++ b/src/main/java/edu/byu/cs/canvas/CanvasUtils.java @@ -56,29 +56,26 @@ private static Rubric.Results convertPoints(Rubric.Results results, int points) ); } - public static CanvasRubricAssessment convertToAssessment(Rubric rubric, RubricConfig config, - float lateAdjustment, Phase phase) + public static CanvasRubricAssessment convertToAssessment(Rubric rubric, RubricConfig config, Phase phase) throws GradingException { Map items = new HashMap<>(); for(Rubric.RubricType type : Rubric.RubricType.values()) { - items.putAll(convertToCanvasFormat(rubric.items().get(type), lateAdjustment, phase, - config.items().get(type), type).items()); + items.putAll(convertToCanvasFormat(rubric.items().get(type), phase, config.items().get(type), type).items()); } return new CanvasRubricAssessment(items); } private static CanvasRubricAssessment convertToCanvasFormat( - Rubric.RubricItem rubricItem, - float lateAdjustment, Phase phase, RubricConfig.RubricConfigItem rubricConfigItem, + Rubric.RubricItem rubricItem, Phase phase, RubricConfig.RubricConfigItem rubricConfigItem, Rubric.RubricType rubricType ) throws GradingException { Map items = new HashMap<>(); if (rubricConfigItem != null && rubricItem != null) { Rubric.Results results = rubricItem.results(); items.put(PhaseUtils.getCanvasRubricId(rubricType, phase), - new CanvasRubricItem(results.notes(), results.score() * (1 - lateAdjustment))); + new CanvasRubricItem(results.notes(), results.score())); } return new CanvasRubricAssessment(items); }