Skip to content

Commit

Permalink
Merge pull request #429 from softwareconstruction240/428-backend-subm…
Browse files Browse the repository at this point in the history
…issions-with-manual-commit-approval-are-not-given-late-penalties

Spot fix: late penalties on manually approved submissions
  • Loading branch information
19mdavenport authored Sep 25, 2024
2 parents 46f58b5 + 381df8a commit 8df7b27
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down
16 changes: 10 additions & 6 deletions src/main/java/edu/byu/cs/autograder/score/Scorer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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<Rubric.RubricType, Rubric.RubricItem> items = new EnumMap<>(Rubric.RubricType.class);
float lateAdjustment = daysLate * PER_DAY_LATE_PENALTY;
for(Map.Entry<Rubric.RubricType, Rubric.RubricItem> entry : rubric.items().entrySet()) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/edu/byu/cs/util/SubmissionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit 8df7b27

Please sign in to comment.