Skip to content

Implement early submission bonuses - #1560

Open
reppuli92 wants to merge 5 commits into
apluslms:masterfrom
reppuli92:master
Open

reppuli92 wants to merge 5 commits into
apluslms:masterfrom
reppuli92:master

Conversation

@reppuli92

Copy link
Copy Markdown
Contributor

Description

What?

Implement early submission bonus functionality in a-plus. This adds the possibility of adding early submission bonuses to modules and their corresponding deadlines, as well as bonus tapering.

Why?

This is a feature request, issue #1401

How?

Using the previously added four new database fields, implement the bonus functionality. The bonus can be edited both via module RST and the 'Edit course' page, which contains explanatory tooltips for especially the rather complex bonus tapering functionality. Information about the bonus is also shown to students in the affected exercises, if the bonus is currently available.

Testing

Remember to add or update unit tests for new features and changes.

What type of test did you run?

  • Accessibility test using the WAVE extension.
  • Django unit tests.
  • Playwright tests.
  • Other test. (Add a description below)
  • Manual testing.

Tested manually both the 'normal' early bonus and tapering steps via manual course editing and submitting questionnaire exercises.

Did you test the changes in

  • Chrome
  • Firefox
  • This pull request cannot be tested in the browser.

Think of what is affected by these changes and could become broken

Translation

Programming style

  • Did you follow our style guides?
  • Did you use Python type hinting in all functions that you added or edited? (type hints for function parameters and return values)

Have you updated the README or other relevant documentation?

  • documents inside the doc directory.
  • README.md.
  • Aplus Manual.
  • Other documentation (mention below which documentation).

Aplus-manual edits in another PR

Is it Done?

  • Reviewer has finished the code review
  • After the review, the developer has made changes accordingly
  • Customer/Teacher has accepted the implementation of the feature

Clean up your git commit history before submitting the pull request!

@jkotimak jkotimak moved this from Todo to In progress in A+ sprints Oct 26, 2026
@jkotimak jkotimak moved this from In progress to Under review in A+ sprints Oct 26, 2026
@ihalaij1 ihalaij1 self-assigned this Oct 26, 2026
@ihalaij1
ihalaij1 self-requested a review October 26, 2026 12:56
@ihalaij1
ihalaij1 force-pushed the master branch 3 times, most recently from eac2f66 to c4a1eea Compare October 27, 2026 08:14
@reppuli92

Copy link
Copy Markdown
Contributor Author

The e2e test fix I just implemented was accidentally on this branch so I removed it, sorry for the confusion. I'll create a separate PR for it

@ihalaij1 ihalaij1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here is what an AI review found:

Bugs

1. Fuzzy translation entries will show raw msgids to users (verified)
MODULE_ERROR_EARLY_SUBMISSION_DL_BEFORE_OPENING_TIME is marked #, fuzzy in both locale/en/LC_MESSAGES/django.po (line 815) and locale/fi/LC_MESSAGES/django.po (line 820), with the msgstr copied from the AFTER_CLOSING_TIME variant. I compiled and inspected the .mo catalog: fuzzy entries are excluded by msgfmt, so at runtime gettext returns the raw msgid. When a teacher sets an early deadline before the opening time, the form will literally display MODULE_ERROR_EARLY_SUBMISSION_DL_BEFORE_OPENING_TIME instead of a sentence. The Finnish msgstr is also semantically wrong ("tulee olla ennen moduulin sulkeutumisaikaa" — should say the deadline must be after the opening time). Fix: remove the #, fuzzy + #| lines and correct both msgstrs.

2. Unrelated behavior change: scale_grade_to no longer caps at max points
exercise/submission_models.py removed self.grade = min(self.grade, self.exercise.max_points) from scale_grade_to(). This is needed to keep bonus grades intact when scaling to 100% (and is tested), but it is an undocumented, unrelated change bundled into the PR. It also changes the behavior of the scale_grade_to management command (course/management/commands/scale_grade_to.py): previously scaling could never push a grade above exercise.max_points; now grades already above max (bonus grades) stay above it after any scaling. This should at least be called out in the PR description, and ideally separated into its own commit/PR.

3. configure.py unconditionally resets early_submission_bonus_in_use
In edit_course/operations/configure.py:

module.early_submission_bonus_in_use = parse_bool(m.get("early_bonus_in_use", False))

Unlike every other field in that block (only set if "key" in m), this always overwrites the flag. Consequence: if a teacher configures the bonus via the Edit course UI and someone later re-runs course configuration from a YAML that doesn't contain early_bonus_in_use (older config, hand-edited YAML, another tool), the bonus is silently disabled while early_submission_deadline, early_submission_bonus and bonus_time_step_hours are all preserved. That asymmetry (values persist, flag resets) is surprising and is a data-loss gotcha. The test test_early_submission_bonus actually codifies this behavior, so if it's intentional it should be documented; otherwise it should follow the same if "early_bonus_in_use" in m: pattern as the neighbors.

4. percent filter truncation can misdisplay the bonus
The notice uses {{ module.early_submission_bonus|percent }} where percent() is int(decimal * 100). Floating point makes e.g. 0.29 * 100 = 28.999999999999996 → the exercise page would advertise "28% more points" for a 0.29 bonus. Pre-existing filter, but the new feature is exposed to it. (The tooltip code in course_forms.py correctly uses f'{x:.2f}' rounding instead.)

Design / consistency concerns

5. Bonus notice ignores personal deadline deviations. exercise_plain.html shows "X% more points if submitted before {{ module.early_submission_deadline }}" — the module-wide deadline. The adjacent deadline display carefully handles summary.personal_deadline, but the bonus notice doesn't. A student with an extension sees a bonus cutoff that doesn't reflect their situation (students with extensions submitting after module closing_time get no bonus at all, since the tier is 0 past closing — reasonable, but undocumented and untested).

6. Tooltip math is duplicated and can go stale. CourseModuleForm.__init__ re-implements the taper calculation (full_steps, decrease per step) that also lives in CourseModule.get_early_submission_bonus_tier. If the model math changes, the tooltip drifts. Also, the tooltip is computed from the saved instance, so on a validation-error re-render it describes the old DB values, not what the teacher just typed. Consider a model helper (e.g. returning taper info) reused by the form.

7. Required early_submission_deadline even when the bonus is off. The model field is blank=False (only a default), so the ModelForm field is always required in the SCHEDULE fieldset. It's pre-filled so it passes, but teachers who don't use the bonus still must submit a value for a field that is ignored. A form clean() making it optional when early_submission_bonus_in_use is unchecked would be cleaner.

8. Minor wording in the taper tooltip. "The bonus decreases by 5 percentage points per step from 15% to 0%" — the first tapered step is actually 10% (the full 15% only applies before the early deadline). The range 15→0 describes the decrease, but reads as if the first step gives 15%.

Style / process

  • configure() still doesn't catch ValidationError from module.full_clean() (pre-existing), but the new fields add new ways to crash it: an out-of-range early_bonus or negative bonus_time_step_hours coming from a non-RST source (hand-written YAML / gitmanager) raises an unhandled ValidationError instead of landing in the errors list. The RST side validates (nonnegative_int), the JSON side doesn't.

@reppuli92

Copy link
Copy Markdown
Contributor Author

Added new commit to address the above-mentioned issues. Here's a breakdown:

  1. Fixed the translation issues and removed the fuzzy markers
  2. This is an intentional change, so nothing done here. Should I add a mention of this somewhere?
  3. Added an if statement here to match other fields' behavior
  4. exercise/templatetags/exercise.py now uses round() instead of int() and rounds correctly
  5. This is again intended behavior, so no changes here. Early bonuses shouldn't be affected by personal DL deviations.
  6. Re-factored the step calculation to be in one place: get_early_submission_bonus_taper_steps() in course/models.py
  7. Currently early-submission-deadline is treated the same way as existing late-submission-deadline - they are automatically filled with a default value if they are not filled in the RST. I don't see any issue with this behaviour, so no changes made. I can of course change both, if that's indeed required.
  8. I disagree with this as well :) the wording is clear to me

@reppuli92

Copy link
Copy Markdown
Contributor Author

Fixed unit and e2e tests that were failing due to recent changes. Also fixed a bug in which module edits couldn't be saved in the UI if a late submission penalty is configured without an early submission bonus. Also changed the minimum increment for the bonus/penalty from 0.1 to 0.01.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Under review

Development

Successfully merging this pull request may close these issues.

3 participants