| Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
|---|---|---|---|---|
| app/models/grace_period_submission_rule.rb | 146 | 90 | 85.62%
|
81.11%
|
Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.
1 class GracePeriodSubmissionRule < SubmissionRule |
2 |
3 # When Students commit code after the collection time, MarkUs should warn |
4 # the Students with a message saying that the due date has passed, and the |
5 # work they're submitting will probably not be graded |
6 def commit_after_collection_message(grouping) |
7 I18n.t 'submission_rules.grace_period_submission_rule.commit_after_collection_message' |
8 end |
9 |
10 def after_collection_message(grouping) |
11 I18n.t 'submission_rules.grace_period_submission_rule.after_collection_message' |
12 end |
13 |
14 # This message will be dislayed to Students on viewing their file manager |
15 # after the due date has passed, but before the calculated collection date. |
16 def overtime_message(grouping) |
17 |
18 # We need to know how many grace credits this grouping has left... |
19 grace_credits_remaining = grouping.available_grace_credits |
20 # How far are we into overtime? |
21 overtime_hours = calculate_overtime_hours_from(Time.now) |
22 grace_credits_to_use = calculate_deduction_amount(overtime_hours) |
23 if grace_credits_remaining < grace_credits_to_use |
24 # This grouping is out of grace credits. |
25 return I18n.t 'submission_rules.grace_period_submission_rule.overtime_message_without_days_left' |
26 else |
27 # This grouping still has some grace credits to spend. |
28 return I18n.t 'submission_rules.grace_period_submission_rule.overtime_message_with_days_left', :grace_credits_remaining => grace_credits_remaining, :grace_credits_to_use => grace_credits_to_use |
29 end |
30 end |
31 |
32 # GracePeriodSubmissionRule works with all Assignments |
33 def assignment_valid? |
34 return !assignment.nil? |
35 end |
36 |
37 def apply_submission_rule(submission) |
38 |
39 # If we aren't overtime, we don't need to apply a rule |
40 return submission if submission.revision_timestamp <= assignment.due_date |
41 |
42 # So we're overtime. How far are we overtime? |
43 collection_time = submission.revision_timestamp |
44 due_date = assignment.due_date |
45 |
46 |
47 overtime_hours = calculate_overtime_hours_from(collection_time) |
48 # Now we need to figure out how many Grace Credits to deduct |
49 deduction_amount = calculate_deduction_amount(overtime_hours) |
50 |
51 #Get rid of any previous deductions for this assignment, so as not to |
52 #give duplicate deductions upon multiple calls to this method |
53 remove_deductions(submission) |
54 |
55 # And how many grace credits are available to this grouping |
56 available_grace_credits = submission.grouping.available_grace_credits |
57 |
58 # If the available_grace_creidts <= 0, simply get the submission |
59 # from the due date. |
60 # If the deduction_amount is greater than the amount of grace |
61 # credits available to this grouping, then we need to destroy |
62 # this submission, find the date of the last valid commit, and |
63 # use that as a submission, and return it. |
64 |
65 if available_grace_credits <= 0 |
66 grouping = submission.grouping |
67 submission.destroy |
68 submission = Submission.create_by_timestamp(grouping, due_date.localtime) |
69 return submission |
70 elsif available_grace_credits < deduction_amount |
71 grouping = submission.grouping |
72 submission.destroy |
73 collection_time = calculate_collection_date_from_credits(available_grace_credits) |
74 submission = Submission.create_by_timestamp(grouping, collection_time.localtime) |
75 # And now, a little recursion... |
76 return assignment.submission_rule.apply_submission_rule(submission) |
77 end |
78 |
79 # Deduct Grace Credits from every member of the Grouping |
80 student_memberships = submission.grouping.accepted_student_memberships |
81 |
82 student_memberships.each do |student_membership| |
83 deduction = GracePeriodDeduction.new |
84 deduction.membership = student_membership |
85 deduction.deduction = deduction_amount |
86 deduction.save |
87 end |
88 |
89 return submission |
90 end |
91 |
92 def description_of_rule |
93 I18n.t 'submission_rules.grace_period_submission_rule.description' |
94 end |
95 |
96 def grader_tab_partial |
97 return 'submission_rules/grace_period/grader_tab' |
98 end |
99 |
100 #Remove all deductions for this assignment from all accepted members of |
101 #submission, so that any new deductions for the assignemnt will not be duplicates |
102 def remove_deductions(submission) |
103 student_memberships = submission.grouping.accepted_student_memberships |
104 |
105 student_memberships.each do |student_membership| |
106 deductions = student_membership.user.grace_period_deductions |
107 deductions.each do |deduction| |
108 if deduction.membership.grouping.assignment.id == assignment.id |
109 student_membership.grace_period_deductions.delete(deduction) |
110 deduction.destroy |
111 end |
112 end |
113 end |
114 end |
115 |
116 private |
117 |
118 def hours_sum |
119 return periods.sum('hours') |
120 end |
121 |
122 # Given a certain number of hours into the grace periods, calculate how many credits to |
123 # deduct |
124 def calculate_deduction_amount(overtime_hours) |
125 total_deduction = 0 |
126 periods.each do |period| |
127 total_deduction = total_deduction + 1 |
128 overtime_hours = overtime_hours - period.hours |
129 break if overtime_hours <= 0 |
130 end |
131 return total_deduction |
132 end |
133 |
134 # Given the number of credits remaining, calculate the collection_date |
135 # for a Submission |
136 def calculate_collection_date_from_credits(grace_credits) |
137 hours_after_due_date = 0 |
138 periods.each do |period| |
139 hours_after_due_date = hours_after_due_date + period.hours |
140 grace_credits = grace_credits - 1 |
141 break if grace_credits == 0 |
142 end |
143 return assignment.due_date + hours_after_due_date.hours |
144 end |
145 |
146 end |
Generated on Tue Feb 07 00:07:36 -0500 2012 with rcov 0.9.10