Skip to content

Conversation

@freyazjiner
Copy link
Member

@freyazjiner freyazjiner commented Oct 23, 2025

Proposed Changes

(Describe your changes here. Also describe the motivation for your changes: what problem do they solve, or how do they improve the application or codebase? If this pull request fixes an open issue, use a keyword to link this pull request to the issue.)
This PR adds a penalty_type option to the late penalty submission rules, allowing instructors to choose whether late penalties are applied as a percentage of total assignment marks (default), a fixed number of points, or a percentage of each student’s earned mark.

Screenshots of your changes (if applicable) image⬇️ image image image image⬇️ image image image image⬇️ image image image image⬇️ image image image image⬇️ image image image image⬇️ image image image
Associated documentation repository pull request (if applicable) See MarkUsProject/Wiki/pull/243 for updated instructor guide.

Type of Change

(Write an X or a brief description next to the type or types that best describe your changes.)

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
New feature (non-breaking change that adds functionality) X
🐛 Bug fix (non-breaking change that fixes an issue)
🎨 User interface change (change to user interface; provide screenshots)
♻️ Refactoring (internal change to codebase, without changing functionality)
🚦 Test update (change that only adds or modifies tests)
📦 Dependency update (change that updates a dependency)
🔧 Internal (change that only affects developers or continuous integration)

Checklist

(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the [ ] into a [x] in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)

Before opening your pull request:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • If this is my first contribution, I have added myself to the list of contributors.

After opening your pull request:

  • I have updated the project Changelog (this is required for all changes).
  • I have verified that the pre-commit.ci checks have passed.
  • I have verified that the CI tests have passed.
  • I have reviewed the test coverage changes reported by Coveralls.
  • I have requested a review from a project maintainer.

Questions and Comments

(Include any questions or comments you have regarding your changes.)

@freyazjiner freyazjiner changed the title Add penalty_type to submission_rules Add penalty_type option to submission rules for percentage_of_mark penalties Oct 23, 2025
@freyazjiner freyazjiner marked this pull request as ready for review October 23, 2025 21:31
@coveralls
Copy link
Collaborator

coveralls commented Oct 23, 2025

Pull Request Test Coverage Report for Build 19217721017

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 78 of 78 (100.0%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 91.583%

Totals Coverage Status
Change from base Build 19081473154: 0.01%
Covered Lines: 42826
Relevant Lines: 45981

💛 - Coveralls

@freyazjiner freyazjiner marked this pull request as draft October 24, 2025 03:46
@freyazjiner freyazjiner removed the request for review from david-yz-liu October 24, 2025 03:46
@freyazjiner freyazjiner marked this pull request as ready for review October 24, 2025 13:13
Copy link
Collaborator

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @freyazjiner, I'm just leaving a few quick comments now (will wait for you to work on these and re-request a review).

  1. You made a great point at our meeting today about the % sign needing to change for different units, and please feel free to implement this. Please use the term "marks" instead of "points", both in the dropdown and for replacing the %.

  2. I've merged in #7697, which also contains a database migration. This is a bit tricky to resolve the merge correctly. Please do the following:

    1. Rollback your current migration.
    2. Update your branch from master.
    3. Perform the rails db:migrate command again. This will both run the migration from that PR, plus your own.
  • In the UI, the penalty type dropdown is a bit misaligned. It should be aligned with the other text under the option label, so that it looks like it's part of the option configuration.

Copy link
Collaborator

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@freyazjiner looking good! I just left a few comments. Since this is a new feature that is user-facing, you should also update the documentation repo (look for the page that describes setting late penalties for assignments).

# submission Result
return submission if submission.is_empty
result = submission.get_original_result
unit = case self.penalty_type
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary. The penalty_type validation should ensure that it's one of the expected values. You can just pass self.penalty_type directly to create the extra mark.

# submission Result
return submission if submission.is_empty
result = submission.get_original_result
unit = case self.penalty_type
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment below

accepts_nested_attributes_for :periods, allow_destroy: true
validates_associated :periods
validates :assignment, uniqueness: true
validates :penalty_type,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is okay, but please override this validation in the two penalty-based submission rules to disallow nil. For those two rules we should always expect a non-nil penalty type.

}
$("#penalty_type_selector_decay select, #penalty_type_selector_period select").on(
"change",
function () {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can look at the jQuery documentation, but this function should be taking arguments for the event, from which you can obtain the new value of the select input. This is cleaner than doing another jQuery call to find the select element again.

penalty_type: Penalty type
penalty_types:
marks: Marks
percentage: Percentage
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the label "Percentage of assignment total"

penalty_types:
marks: Marks
percentage: Percentage
percentage_of_mark: Percentage of mark
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here use "Percentage of earned mark"

Copy link
Collaborator

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@freyazjiner nice work! I just left a few small comments.

But also I realized that we should update the student-facing messages that appear in the assignment settings when you view the settings as a student.

Currently, each SubmissionRule type has its own student-facing messages (see config/locales/views/submission_rules/en.yml). But there's only one set of messages per rule, and for the penalty rules they assume a "percentage" penalty type. Now that we're generalizing this, we should update these messages as well!

<%= t('submission_rules.penalty_type') %>:
<%= rule.select :penalty_type,
[
[t('submission_rules.penalty_types.percentage'), 'percentage'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, please use the ExtraMark constants here as well (not the string literals). Keep in mind that this is embedded Ruby code, so you have access to all of the backend models here!

<%= t('submission_rules.penalty_type') %>:
<%= rule.select :penalty_type,
[
[t('submission_rules.penalty_types.percentage'), 'percentage'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above

Copy link
Collaborator

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@freyazjiner I left a few more comments and did some manual testing. There's currently a bug where an instructor cannot change the penalty_type for a submission rule (create an assignment with a particular penalty type, then try updating the assignment to change the penalty type). Please make sure to test this carefully and fix this issue.

var selector = isDecay ? "#penalty_decay_periods" : "#penalty_periods";

if ($(event.target).val() === "points") {
$(selector + " .deduction-unit").text("marks");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string "marks" should be internationalized

overtime_hours = calculate_overtime_hours_from(Time.current, grouping)
# Calculate the penalty that the grouping will suffer
potential_penalty = calculate_penalty(overtime_hours)
type = case penalty_type
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit more complicated than it needs to be. Write the _ right after overtime_message below, so that you can use #{penalty_type} directly in the interpolation string.

This comment applies to the other submission rule below.

[
[t('submission_rules.penalty_types.percentage'), ExtraMark::PERCENTAGE],
[t('submission_rules.penalty_types.marks'), ExtraMark::POINTS],
[t('submission_rules.penalty_types.percentage_of_mark'), ExtraMark::PERCENTAGE_OF_MARK]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List this option second, before the "Marks" option"

[t('submission_rules.penalty_types.marks'), ExtraMark::POINTS],
[t('submission_rules.penalty_types.percentage_of_mark'), ExtraMark::PERCENTAGE_OF_MARK]
],
{ selected: rule.object.penalty_type || 'percentage' } %>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ExtraMark::PERCENTAGE instead of the string literal

[
[t('submission_rules.penalty_types.percentage'), ExtraMark::PERCENTAGE],
[t('submission_rules.penalty_types.marks'), ExtraMark::POINTS],
[t('submission_rules.penalty_types.percentage_of_mark'), ExtraMark::PERCENTAGE_OF_MARK]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as above

details_message_other: Thereafter, a deduction of %{deduction}% will be applied every %{interval} hours up to a maximum of %{hours} hours.
extramark_description: Late submission (%{overtime_hours} hour(s)) resulted in automatic %{penalty_amount}% deduction.
overtime_message: The due date for this assignment has passed and you are now in a penalty period. You can make changes to your submission, but will have %{potential_penalty}% deducted from the final mark on this assignment.
overtime_message_percentage: The due date for this assignment has passed and you are now in a penalty period. You can make changes to your submission, but will have %{potential_penalty}% deducted from the final mark on this assignment.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After %{potential_penalty}% include the phrase "of the assignment total"

extramark_description: Late submission (%{overtime_hours} hour(s)) resulted in automatic %{penalty_amount}% deduction.
overtime_message: The due date for this assignment has passed and you are now in a penalty period. You can make changes to your submission, but will have %{potential_penalty}% deducted from the final mark on this assignment.
overtime_message_percentage: The due date for this assignment has passed and you are now in a penalty period. You can make changes to your submission, but will have %{potential_penalty}% deducted from the final mark on this assignment.
overtime_message_percentage_of_mark: The due date for this assignment has passed and you are now in a penalty period. You can make changes to your submission, but will have %{potential_penalty}% deducted from your earned mark on this assignment.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reword the last part to "%{potential_penalty}% of your earned mark deducted from the final mark on this assignment."

(This will align the wording better with the other two options

details_message: Up to %{hours} hours after the due date, your grade will be reduced by %{deduction}%
extramark_description: Late submission (%{overtime_hours} hour(s)) resulted in automatic %{penalty_amount}% deduction.
overtime_message: The due date for this assignment has passed and you are now in a penalty period. You can make changes to your submission, but will have %{potential_penalty}% deducted from the final mark on this assignment.
overtime_message_percentage: The due date for this assignment has passed and you are now in a penalty period. You can make changes to your submission, but will have %{potential_penalty}% deducted from the final mark on this assignment.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as above

apply_rule
rule_overtime_message = rule.overtime_message(grouping)
expected_overtime_message = I18n.t 'penalty_decay_period_submission_rules.overtime_message',
type = case rule.penalty_type
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above

apply_rule
rule_overtime_message = rule.overtime_message(grouping)
expected_overtime_message = I18n.t 'penalty_decay_period_submission_rules.overtime_message',
type = case rule.penalty_type
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above

@freyazjiner freyazjiner marked this pull request as draft November 5, 2025 02:53
@freyazjiner freyazjiner marked this pull request as ready for review November 5, 2025 06:25
Copy link
Collaborator

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@freyazjiner okay all of the code changes look good, but there are still student-facing messages that need to be updated. Make sure you login as a student to view exactly what they are seeing for the different late penalties. Update all of the messages to incorporate penalty type, and update your PR description with screenshots of each type so it's clear that you've changed all of the necessary messages.

@freyazjiner freyazjiner requested review from david-yz-liu and removed request for david-yz-liu November 6, 2025 18:04
Copy link
Collaborator

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@freyazjiner okay things are looking great. I left a few small comments on the message wording.

However, I noticed one other bug when testing: in the grading view, the Summary tab on the right side shows the "Bonuses/Deductions" table. This table isn't showing the correct mark deduction for percentage_of_mark penalty type. I do see that the "Total Extra Marks" total below it is correct, as well as the "Total Mark" calculation. So it seems that just the table is the problem.

details_message_percentage_of_mark: Up to %{hours} hours after the due date, your grade will be reduced by %{deduction}% of your earned mark from the final mark on this assignment.
details_message_points: Up to %{hours} hours after the due date, your grade will be reduced by %{deduction} marks from the final mark on this assignment.
extramark_description_percentage: Late submission (%{overtime_hours} hour(s)) resulted in automatic %{penalty_amount}% deduction from assignment total.
extramark_description_percentage_of_mark: Late submission (%{overtime_hours} hour(s)) resulted in automatic %{penalty_amount}% deduction from earned mark .
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete the space before the period

details_message_percentage: Up to %{hours} hours after the due date, your grade will be reduced by %{deduction}% of the assignment total from the final mark on this assignment.
details_message_percentage_of_mark: Up to %{hours} hours after the due date, your grade will be reduced by %{deduction}% of your earned mark from the final mark on this assignment.
details_message_points: Up to %{hours} hours after the due date, your grade will be reduced by %{deduction} marks from the final mark on this assignment.
extramark_description_percentage: Late submission (%{overtime_hours} hour(s)) resulted in automatic %{penalty_amount}% deduction from assignment total.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"from assignment total" -> "of the assignment total"

extramark_description_percentage: Late submission (%{overtime_hours} hour(s)) resulted in automatic %{penalty_amount}% deduction from assignment total.
extramark_description_percentage_of_mark: Late submission (%{overtime_hours} hour(s)) resulted in automatic %{penalty_amount}% deduction from earned mark .
extramark_description_points: Late submission (%{overtime_hours} hour(s)) resulted in automatic %{penalty_amount} marks deduction.
overtime_message_percentage: The due date for this assignment has passed and you are now in a penalty period. You can make changes to your submission, but will have %{potential_penalty}% of the assignment total deducted from the final mark on this assignment.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change "final mark" to "final grade"

extramark_description_percentage_of_mark: Late submission (%{overtime_hours} hour(s)) resulted in automatic %{penalty_amount}% deduction from earned mark .
extramark_description_points: Late submission (%{overtime_hours} hour(s)) resulted in automatic %{penalty_amount} marks deduction.
overtime_message_percentage: The due date for this assignment has passed and you are now in a penalty period. You can make changes to your submission, but will have %{potential_penalty}% of the assignment total deducted from the final mark on this assignment.
overtime_message_percentage_of_mark: The due date for this assignment has passed and you are now in a penalty period. You can make changes to your submission, but will have %{potential_penalty}% of your earned mark deducted from the final mark on this assignment.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change "final mark" to "final grade"

extramark_description_points: Late submission (%{overtime_hours} hour(s)) resulted in automatic %{penalty_amount} marks deduction.
overtime_message_percentage: The due date for this assignment has passed and you are now in a penalty period. You can make changes to your submission, but will have %{potential_penalty}% of the assignment total deducted from the final mark on this assignment.
overtime_message_percentage_of_mark: The due date for this assignment has passed and you are now in a penalty period. You can make changes to your submission, but will have %{potential_penalty}% of your earned mark deducted from the final mark on this assignment.
overtime_message_points: The due date for this assignment has passed and you are now in a penalty period. You can make changes to your submission, but will have %{potential_penalty} marks deducted from the final mark on this assignment.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change "final mark" to "final grade"

extramark_description_percentage: Late submission (%{overtime_hours} hour(s)) resulted in automatic %{penalty_amount}% deduction from assignment total.
extramark_description_percentage_of_mark: Late submission (%{overtime_hours} hour(s)) resulted in automatic %{penalty_amount}% deduction from earned mark.
extramark_description_points: Late submission (%{overtime_hours} hour(s)) resulted in automatic %{penalty_amount} marks deduction.
overtime_message_percentage: The due date for this assignment has passed and you are now in a penalty period. You can make changes to your submission, but will have %{potential_penalty}% of the assignment total deducted from the final mark on this assignment.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change "final mark" to "final grade"

extramark_description_percentage_of_mark: Late submission (%{overtime_hours} hour(s)) resulted in automatic %{penalty_amount}% deduction from earned mark.
extramark_description_points: Late submission (%{overtime_hours} hour(s)) resulted in automatic %{penalty_amount} marks deduction.
overtime_message_percentage: The due date for this assignment has passed and you are now in a penalty period. You can make changes to your submission, but will have %{potential_penalty}% of the assignment total deducted from the final mark on this assignment.
overtime_message_percentage_of_mark: The due date for this assignment has passed and you are now in a penalty period. You can make changes to your submission, but will have %{potential_penalty}% of your earned mark deducted from the final mark on this assignment.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change "final mark" to "final grade"

extramark_description_points: Late submission (%{overtime_hours} hour(s)) resulted in automatic %{penalty_amount} marks deduction.
overtime_message_percentage: The due date for this assignment has passed and you are now in a penalty period. You can make changes to your submission, but will have %{potential_penalty}% of the assignment total deducted from the final mark on this assignment.
overtime_message_percentage_of_mark: The due date for this assignment has passed and you are now in a penalty period. You can make changes to your submission, but will have %{potential_penalty}% of your earned mark deducted from the final mark on this assignment.
overtime_message_points: The due date for this assignment has passed and you are now in a penalty period. You can make changes to your submission, but will have %{potential_penalty} marks deducted from the final mark on this assignment.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change "final mark" to "final grade"

details_message_other_percentage: Thereafter, a deduction of %{deduction}% of the assignment total will be applied every %{interval} hours up to a maximum of %{hours} hours.
details_message_other_percentage_of_mark: Thereafter, a deduction of %{deduction}% of your earned mark will be applied every %{interval} hours up to a maximum of %{hours} hours.
details_message_other_points: Thereafter, a deduction of %{deduction}% marks will be applied every %{interval} hours up to a maximum of %{hours} hours.
extramark_description_percentage: Late submission (%{overtime_hours} hour(s)) resulted in automatic %{penalty_amount}% deduction from assignment total.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"from assignment total" -> "of the assignment total"

details_message_first_points: A deduction of %{deduction} marks will be applied every %{interval} hours up to %{hours} hours after the assignment is due.
details_message_other_percentage: Thereafter, a deduction of %{deduction}% of the assignment total will be applied every %{interval} hours up to a maximum of %{hours} hours.
details_message_other_percentage_of_mark: Thereafter, a deduction of %{deduction}% of your earned mark will be applied every %{interval} hours up to a maximum of %{hours} hours.
details_message_other_points: Thereafter, a deduction of %{deduction}% marks will be applied every %{interval} hours up to a maximum of %{hours} hours.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the % after %{deduction}

Copy link
Collaborator

@david-yz-liu david-yz-liu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, @freyazjiner!

@david-yz-liu david-yz-liu linked an issue Nov 10, 2025 that may be closed by this pull request
@david-yz-liu david-yz-liu merged commit 485c3b0 into MarkUsProject:master Nov 10, 2025
7 checks passed
@freyazjiner freyazjiner deleted the implement-late-penalties branch January 5, 2026 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Additional option for late penalty calculation

3 participants