class PenaltyDecayPeriodSubmissionRule

Public Instance Methods

after_collection_message() click to toggle source
# File app/models/penalty_decay_period_submission_rule.rb, line 10
def after_collection_message
  I18n.t 'submission_rules.penalty_decay_period_submission_rule.after_collection_message'
end
apply_submission_rule(submission) click to toggle source
# File app/models/penalty_decay_period_submission_rule.rb, line 25
def apply_submission_rule(submission)
  # Calculate the appropriate penalty, and attach the ExtraMark to the
  # submission Result
  result = submission.get_original_result
  overtime_hours = calculate_overtime_hours_from(submission.revision_timestamp)
  penalty_amount = calculate_penalty(overtime_hours)
  if penalty_amount > 0
    penalty = ExtraMark.new
    penalty.result = result
    penalty.extra_mark = -penalty_amount
    penalty.unit = ExtraMark::UNITS[:percentage]

    penalty.description = I18n.t 'submission_rules.penalty_decay_period_submission_rule.extramark_description', :overtime_hours => overtime_hours, :penalty_amount => penalty_amount
    penalty.save
  end

  submission
end
calculate_penalty(overtime_hours) click to toggle source

Given a number of overtime_hours, calculate the penalty percentage that a student should get

# File app/models/penalty_decay_period_submission_rule.rb, line 62
def calculate_penalty(overtime_hours)
  return 0 if overtime_hours <= 0
  total_penalty = 0
  periods.each do |period|
    deduction = period.deduction
    if deduction < 0
      deduction = -deduction
    end
    interval = period.interval
    if overtime_hours / interval < 1
      total_penalty = total_penalty + deduction
    else
      total_penalty = total_penalty + (overtime_hours/interval).to_i * deduction
    end
    overtime_hours = overtime_hours - period.hours
    break if overtime_hours <= 0
  end
  total_penalty
end
commit_after_collection_message() click to toggle source

When Students commit code after the collection time, MarkUs should warn the Students with a message saying that the due date has passed, and the work they’re submitting will probably not be graded

# File app/models/penalty_decay_period_submission_rule.rb, line 6
def commit_after_collection_message
  I18n.t 'submission_rules.penalty_decay_period_submission_rule.commit_after_collection_message'
end
description_of_rule() click to toggle source
# File app/models/penalty_decay_period_submission_rule.rb, line 44
def description_of_rule
  I18n.t 'submission_rules.penalty_decy_period_submission_rule.description'
end
grader_tab_partial() click to toggle source
# File app/models/penalty_decay_period_submission_rule.rb, line 48
def grader_tab_partial
  'submission_rules/penalty_decay_period/grader_tab'
end
hours_sum() click to toggle source
# File app/models/penalty_decay_period_submission_rule.rb, line 52
def hours_sum
  periods.sum('hours')
end
maximum_penalty() click to toggle source
# File app/models/penalty_decay_period_submission_rule.rb, line 56
def maximum_penalty
  periods.sum('deduction')
end
overtime_message(grouping) click to toggle source

This message will be dislayed to Students on viewing their file manager after the due date has passed, but before the calculated collection date.

# File app/models/penalty_decay_period_submission_rule.rb, line 16
def overtime_message(grouping)
  # How far are we into overtime?
  overtime_hours = calculate_overtime_hours_from(Time.zone.now)
  # Calculate the penalty that the grouping will suffer
  potential_penalty = calculate_penalty(overtime_hours)

  I18n.t 'submission_rules.penalty_decay_period_submission_rule.overtime_message', :potential_penalty => potential_penalty
end