Class: Assignment
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Gamified
#award_experience_points!, #net_experience
#build_message, #has_messages?, #pending_messages?, #receive_answer!, #send_question!
#affable_expectation_results, #affable_test_results, #affable_tips, #expectation_results_visible?, #failed_expectation_results, #feedback_html, #first_test_result, #first_test_result_html, #humanized_expectation_results, #iconize, #queries_with_results, #result_html, #results_body_hidden?, #sanitized_affable_test_results, #single_visible_test_result?, #single_visual_result?, #single_visual_result_html, #test_result_html, #visible_expectation_results
Methods inherited from Progress
#dirty_parent_by_submission!, #parent
aggregate_of, all_except, defaults, #delete, #destroy!, numbered, organic_on, resource_fields, #save, #save_and_notify!, #save_and_notify_changes!, serialize_symbolized_hash_array, teaser_on, #update_and_notify!, update_or_create!, whitelist_attributes
Class Method Details
.evaluate_manually!(teacher_evaluation) ⇒ Object
124
125
126
|
# File 'app/models/assignment.rb', line 124
def self.evaluate_manually!(teacher_evaluation)
Assignment.find_by(submission_id: teacher_evaluation[:submission_id])&.evaluate_manually! teacher_evaluation
end
|
Instance Method Details
#attempts_left ⇒ Object
228
229
230
|
# File 'app/models/assignment.rb', line 228
def attempts_left
navigable_parent.attempts_left_for(self)
end
|
#attempts_left? ⇒ Boolean
Tells whether the submitter of this assignment can keep on sending submissions which is true for non limited or for assignments that have not reached their submissions limit
236
237
238
|
# File 'app/models/assignment.rb', line 236
def attempts_left?
!limited? || attempts_left > 0
end
|
#completed_before_last_save? ⇒ Boolean
71
72
73
|
# File 'app/models/assignment.rb', line 71
def completed_before_last_save?
status_before_last_save.completed?
end
|
#completion_changed? ⇒ Boolean
67
68
69
|
# File 'app/models/assignment.rb', line 67
def completion_changed?
completed_before_last_save? != completed?
end
|
#content=(content) ⇒ Object
128
129
130
131
132
|
# File 'app/models/assignment.rb', line 128
def content=(content)
if exercise.solvable?
self.solution = exercise.single_choice? ? exercise.choice_index_for(content) : content
end
end
|
#current_content ⇒ Object
240
241
242
|
# File 'app/models/assignment.rb', line 240
def current_content
solution || default_content
end
|
#current_content_at(index) ⇒ Object
244
245
246
|
# File 'app/models/assignment.rb', line 244
def current_content_at(index)
exercise.sibling_at(index).assignment_for(submitter).current_content
end
|
#current_notification_contexts ⇒ Object
108
109
110
|
# File 'app/models/assignment.rb', line 108
def current_notification_contexts
[Organization.current, submitter.current_immersive_context_at(exercise)].uniq
end
|
#default_content ⇒ Object
248
249
250
|
# File 'app/models/assignment.rb', line 248
def default_content
@default_content ||= language.interpolate_references_for(self, exercise.default_content)
end
|
#errored!(message) ⇒ Object
176
177
178
|
# File 'app/models/assignment.rb', line 176
def errored!(message)
update! result: message, submission_status: :errored
end
|
#evaluate_manually!(teacher_evaluation) ⇒ Object
75
76
77
|
# File 'app/models/assignment.rb', line 75
def evaluate_manually!(teacher_evaluation)
update! status: teacher_evaluation[:status], manual_evaluation_comment: teacher_evaluation[:manual_evaluation]
end
|
#extension ⇒ Object
97
98
99
|
# File 'app/models/assignment.rb', line 97
def extension
exercise.language.extension
end
|
138
139
140
|
# File 'app/models/assignment.rb', line 138
def
exercise. && language.interpolate_references_for(self, exercise.)
end
|
142
143
144
|
# File 'app/models/assignment.rb', line 142
def
Mumukit::ContentType::Markdown.highlighted_code(language.name, )
end
|
#files ⇒ Object
252
253
254
|
# File 'app/models/assignment.rb', line 252
def files
exercise.files_for(current_content)
end
|
#increment_attempts! ⇒ Object
224
225
226
|
# File 'app/models/assignment.rb', line 224
def increment_attempts!
self.attempts_count += 1 if should_retry?
end
|
#manual_evaluation_pending! ⇒ Object
156
157
158
|
# File 'app/models/assignment.rb', line 156
def manual_evaluation_pending!
update! submission_status: :manual_evaluation_pending
end
|
#notify! ⇒ Object
101
102
103
104
105
106
|
# File 'app/models/assignment.rb', line 101
def notify!
unless Organization.silenced?
update_misplaced!(current_notification_contexts.size > 1)
Mumukit::Nuntius.notify! 'submissions', to_resource_h
end
end
|
#notify_to_accessible_organizations! ⇒ Object
112
113
114
115
|
# File 'app/models/assignment.rb', line 112
def notify_to_accessible_organizations!
warn "Don't use notify_to_accessible_organizations!. Use notify_to_student_granted_organizations! instead"
notify_to_student_granted_organizations!
end
|
#notify_to_student_granted_organizations! ⇒ Object
117
118
119
120
121
122
|
# File 'app/models/assignment.rb', line 117
def notify_to_student_granted_organizations!
submitter.student_granted_organizations.each do |organization|
organization.switch!
notify!
end
end
|
#passed! ⇒ Object
160
161
162
|
# File 'app/models/assignment.rb', line 160
def passed!
update! submission_status: :passed
end
|
#persist_submission!(submission) ⇒ Object
87
88
89
90
91
92
93
94
95
|
# File 'app/models/assignment.rb', line 87
def persist_submission!(submission)
transaction do
messages.destroy_all if submission_id.present?
update! submission_id: submission.id
update! submitted_at: DateTime.current
update_submissions_count!
update_last_submission!
end
end
|
#recontextualize!(new_organization = Organization.current) ⇒ Object
55
56
57
58
59
60
61
|
# File 'app/models/assignment.rb', line 55
def recontextualize!(new_organization = Organization.current)
if organization != new_organization
dirty_parent_by_submission! if organization.present? && exercise.used_in?(organization)
self.organization = new_organization
self.parent_id = nil
end
end
|
#run_tests!(params) ⇒ Object
185
186
187
|
# File 'app/models/assignment.rb', line 185
def run_tests!(params)
exercise.run_tests! params.merge(extra: , test: test, settings: settings)
end
|
#run_update! ⇒ Object
146
147
148
149
150
151
152
153
154
|
# File 'app/models/assignment.rb', line 146
def run_update!
running!
begin
update! yield
rescue => e
errored! e.message
raise e
end
end
|
#running! ⇒ Object
168
169
170
171
172
173
174
|
# File 'app/models/assignment.rb', line 168
def running!
update! submission_status: :running,
result: nil,
test_results: nil,
expectation_results: [],
manual_evaluation_comment: nil
end
|
#set_current_organization! ⇒ Object
TODO: Momentary as some assignments may not have an associated organization
51
52
53
|
# File 'app/models/assignment.rb', line 51
def set_current_organization!
self.organization = Organization.current
end
|
#set_default_top_submission_status ⇒ Object
63
64
65
|
# File 'app/models/assignment.rb', line 63
def set_default_top_submission_status
self.top_submission_status ||= 0
end
|
#skipped! ⇒ Object
164
165
166
|
# File 'app/models/assignment.rb', line 164
def skipped!
update! submission_status: :skipped
end
|
#test ⇒ Object
134
135
136
|
# File 'app/models/assignment.rb', line 134
def test
exercise.test && language.interpolate_references_for(self, exercise.test)
end
|
#tips ⇒ Object
220
221
222
|
# File 'app/models/assignment.rb', line 220
def tips
@tips ||= exercise.assist_with(self)
end
|
#to_resource_h ⇒ Object
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
# File 'app/models/assignment.rb', line 189
def to_resource_h
excluded_fields = %i(created_at exercise_id id organization_id parent_id solution submission_id
submission_status submitted_at submitter_id top_submission_status updated_at misplaced)
as_json(except: excluded_fields,
include: {
guide: {
only: [:slug, :name],
include: {
lesson: {only: [:number]},
language: {only: [:name]}},
},
exercise: {only: [:name, :number]},
submitter: {only: [:email, :social_id, :uid], methods: [:name, :profile_picture]}}).
deep_merge(
'organization' => Organization.current.name,
'sid' => submission_id,
'created_at' => submitted_at || updated_at,
'content' => solution,
'status' => submission_status,
'exercise' => {
'eid' => exercise.bibliotheca_id
},
'guide' => {'parent' => {
'type' => navigable_parent.class.to_s,
'name' => navigable_parent.name,
'position' => navigable_parent.try(:number),
'chapter' => guide.chapter.as_json(only: [:id], methods: [:name])
}})
end
|
#update_misplaced!(value) ⇒ Object
260
261
262
|
# File 'app/models/assignment.rb', line 260
def update_misplaced!(value)
update! misplaced: value if value != misplaced?
end
|
#update_top_submission! ⇒ Object
256
257
258
|
# File 'app/models/assignment.rb', line 256
def update_top_submission!
self.top_submission_status = submission_status unless submission_status.improved_by?(top_submission_status)
end
|
#visible_status ⇒ Object
79
80
81
82
83
84
85
|
# File 'app/models/assignment.rb', line 79
def visible_status
if results_hidden? && !pending?
:manual_evaluation_pending.to_submission_status
else
super
end
end
|