• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MarkUsProject / Markus / 18858326141

27 Oct 2025 10:57PM UTC coverage: 91.58% (+0.006%) from 91.574%
18858326141

Pull #7709

github

web-flow
Merge 32a8bed78 into 00f1c5817
Pull Request #7709: Add penalty_type option to submission rules for percentage_of_mark penalties

787 of 1638 branches covered (48.05%)

Branch coverage included in aggregate %.

43 of 43 new or added lines in 5 files covered. (100.0%)

2 existing lines in 2 files now uncovered.

42786 of 45941 relevant lines covered (93.13%)

121.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.43
/app/models/penalty_period_submission_rule.rb
1
class PenaltyPeriodSubmissionRule < SubmissionRule
1✔
2
  # This message will be dislayed to Students on viewing their file manager
3
  # after the due date has passed, but before the calculated collection date.
4
  validates :penalty_type,
1✔
5
            inclusion: { in: [ExtraMark::PERCENTAGE, ExtraMark::POINTS, ExtraMark::PERCENTAGE_OF_MARK] }
6

7
  def overtime_message(grouping)
1✔
8
    # How far are we into overtime?
9
    overtime_hours = calculate_overtime_hours_from(Time.current, grouping)
5✔
10
    # Calculate the penalty that the grouping will suffer
11
    potential_penalty = calculate_penalty(overtime_hours)
5✔
12

13
    I18n.t 'penalty_period_submission_rules.overtime_message', potential_penalty: potential_penalty
5✔
14
  end
15

16
  def apply_submission_rule(submission)
1✔
17
    # Calculate the appropriate penalty, and attach the ExtraMark to the
18
    # submission Result
19
    return submission if submission.is_empty
13✔
20
    result = submission.get_original_result
12✔
21
    overtime_hours = calculate_overtime_hours_from(submission.revision_timestamp, submission.grouping)
12✔
22
    penalty_amount = calculate_penalty(overtime_hours)
12✔
23
    if penalty_amount.positive?
12✔
24
      ExtraMark.create(result: result,
10✔
25
                       extra_mark: -penalty_amount,
26
                       unit: self.penalty_type,
27
                       description: I18n.t('penalty_period_submission_rules.extramark_description',
28
                                           overtime_hours: overtime_hours, penalty_amount: penalty_amount))
29
    end
30

31
    submission
12✔
32
  end
33

34
  private
1✔
35

36
  def hours_sum
1✔
37
    periods.sum('hours')
15✔
38
  end
39

40
  # Given a number of overtime_hours, calculate the penalty percentage that
41
  # a student should get
42
  def calculate_penalty(overtime_hours)
1✔
43
    return 0 if overtime_hours <= 0
17✔
44
    total_penalty = 0
14✔
45
    periods.each do |period|
14✔
46
      deduction = period.deduction
21✔
47
      if deduction < 0
21✔
UNCOV
48
        deduction = -deduction
×
49
      end
50
      total_penalty += deduction
21✔
51
      overtime_hours -= period.hours
21✔
52
      break if overtime_hours <= 0
21✔
53
    end
54
    total_penalty
14✔
55
  end
56
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc