Skip to content

Conversation

freyazjiner
Copy link
Member

@freyazjiner freyazjiner commented Oct 13, 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.)

Screenshots of your changes (if applicable)
Associated documentation repository pull request (if applicable)

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.)

@coveralls
Copy link
Collaborator

coveralls commented Oct 13, 2025

Pull Request Test Coverage Report for Build 18566832127

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

  • 60 of 61 (98.36%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 91.53%

Changes Missing Coverage Covered Lines Changed/Added Lines %
app/models/assignment.rb 3 4 75.0%
Totals Coverage Status
Change from base Build 18541419932: 0.01%
Covered Lines: 42562
Relevant Lines: 45715

💛 - Coveralls

Changelog.md Outdated
- Added new loading spinner icon for tables (#7602)
- Update message and page displaying cannot create new course via external LTI tool (#7669)
- Provide file viewer the option to render Microsoft files (#7676)
- Added percentage_of_score type to ExtraMark model (#7702)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would reword this to be more user-facing. Think about how you would explain this change to an instructor.

Also, please do a merge from master; we've just released 2.8.2, so it's important to make sure your entry still appears in the "unreleased" section.

result_data = Result.joins(:extra_marks, submission: [grouping: :assignment])
.where(id: result_ids)
.pluck(:id, :extra_mark, :unit, 'assessments.id')
subtotals = Result.get_subtotals(result_ids, user_visibility: user_visibility)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay, so overall this is the right calculation, but this has the potential to make this method run a fair amount more slowly. I suggest adding subtotals as an optional argument (default nil), so that if get_subtotals was previously computed for result_ids, then it can be passed in and not recomputed here.

After making the change to this function, you should then review every place it's called and see how to make use of the get_subtotals method. This will require some deep investigation of other existing code, but it'll be worth it if we can avoid doing unnecessary work.

unit { 'points' }
extra_mark { 1 }
end
factory :extra_mark_percentage_of_score, class: 'ExtraMark' do
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 refactor all three factories to use a common parent factory and then has three child factories, one for each type. (You'll need to research how to create parent-child relationships with factories using FactoryBot.)

extra_marks_hash = Result.get_total_extra_marks(result_ids, max_mark: max_mark)
subtotals = Result.get_subtotals(result_ids)
extra_marks_hash = Result.get_total_extra_marks(result_ids, max_mark: max_mark, subtotals: subtotals)
total_marks_hash = subtotals.merge(extra_marks_hash) do |_result_id, subtotal, extra|
Copy link
Collaborator

Choose a reason for hiding this comment

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

Overall we should try to avoid duplicating logic where possible. In a similar vein as what I suggested earlier, please modify the Result.get_total_marks method to optionally take in both subtotals and extra_marks hashes (default nil), and reuse those to compute the result.

This will allow you to keep the total_marks_hash = Result.get_total_marks(result_ids) call, just with extra arguments.

assignment_max_mark = max_mark_hash[assessment_id]
end
extra_marks_hash[id] += (extra_mark * assignment_max_mark / 100).round(2)
elsif unit == 'percentage_of_score'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yikes, it's not great that we were using the hardcoded strings here. Please replace this (and the other two) with the constants from ExtraMark.

extra_mark { 1 }
end

factory :extra_mark_percentage_of_score do
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just noting here to rename this as well, and the test labels/variables/etc.

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.

3 participants