Skip to content

Commit

Permalink
refactor scoring apply late penalty earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
19mdavenport committed Jun 22, 2024
1 parent 6302c25 commit fa39fde
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
45 changes: 25 additions & 20 deletions src/main/java/edu/byu/cs/autograder/score/Scorer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -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());
}


Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -288,6 +278,21 @@ private boolean passed(Rubric rubric) {
return passoffTestItem.results().score() >= passoffTestItem.results().possiblePoints();
}

private void applyLatePenalty(EnumMap<Rubric.RubricType, Rubric.RubricItem> items, int daysLate) {
float lateAdjustment = daysLate * PER_DAY_LATE_PENALTY;
for(Map.Entry<Rubric.RubricType, Rubric.RubricItem> 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`.
* <br>
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/edu/byu/cs/canvas/CanvasUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, CanvasRubricItem> 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<String, CanvasRubricItem> 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);
}
Expand Down

0 comments on commit fa39fde

Please sign in to comment.