Class: Assignment
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Assignment
- Includes:
- WithMessages, WithStatus
- Defined in:
- app/models/assignment.rb
Class Method Summary collapse
Instance Method Summary collapse
- #as_platform_json ⇒ Object
- #content=(content) ⇒ Object
- #evaluate_manually!(teacher_evaluation) ⇒ Object
- #expectation_results_visible? ⇒ Boolean
- #extension ⇒ Object
- #extra ⇒ Object
- #feedback_html ⇒ Object
- #notify! ⇒ Object
- #notify_to_accessible_organizations! ⇒ Object
- #persist_submission!(submission) ⇒ Object
- #queries_with_results ⇒ Object
- #result_html ⇒ Object
- #result_preview ⇒ Object
- #results_visible? ⇒ Boolean
- #single_visual_result? ⇒ Boolean
- #single_visual_result_html ⇒ Object
- #visible_expectation_results ⇒ Object
Methods included from WithMessages
#build_message, #has_messages?, #pending_messages?, #receive_answer!, #send_question!
Methods included from WithStatus
#aborted?, #errored!, #passed!, #passed?, #run_update!, #running!
Methods inherited from ApplicationRecord
aggregate_of, all_except, defaults, name_model_as, numbered, #save, #save_and_notify!, #save_and_notify_changes!, #update_and_notify!, update_or_create!
Class Method Details
.evaluate_manually!(teacher_evaluation) ⇒ Object
96 97 98 |
# File 'app/models/assignment.rb', line 96 def self.evaluate_manually!(teacher_evaluation) Assignment.find_by(submission_id: teacher_evaluation[:submission_id])&.evaluate_manually! teacher_evaluation end |
Instance Method Details
#as_platform_json ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'app/models/assignment.rb', line 115 def as_platform_json navigable_parent = exercise.navigable_parent as_json(except: [:exercise_id, :submission_id, :id, :submitter_id, :solution, :created_at, :updated_at], include: { guide: { only: [:slug, :name], include: { lesson: {only: [:number]}, language: {only: [:name]}}, }, exercise: {only: [:name, :number]}, submitter: {only: [:email, :image_url, :social_id, :uid], methods: [:name]}}). deep_merge( 'organization' => Organization.current.name, 'sid' => submission_id, 'created_at' => updated_at, 'content' => solution, '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 |
#content=(content) ⇒ Object
100 101 102 103 104 |
# File 'app/models/assignment.rb', line 100 def content=(content) if content.present? self.solution = exercise.single_choice? ? exercise.choices.index(content) : content end end |
#evaluate_manually!(teacher_evaluation) ⇒ Object
36 37 38 |
# File 'app/models/assignment.rb', line 36 def evaluate_manually!(teacher_evaluation) update! status: teacher_evaluation[:status], manual_evaluation_comment: teacher_evaluation[:manual_evaluation] end |
#expectation_results_visible? ⇒ Boolean
64 65 66 |
# File 'app/models/assignment.rb', line 64 def expectation_results_visible? visible_expectation_results.present? end |
#extension ⇒ Object
81 82 83 |
# File 'app/models/assignment.rb', line 81 def extension exercise.language.extension end |
#extra ⇒ Object
106 107 108 |
# File 'app/models/assignment.rb', line 106 def extra exercise.extra_for submitter end |
#feedback_html ⇒ Object
60 61 62 |
# File 'app/models/assignment.rb', line 60 def feedback_html output_content_type.to_html(feedback) end |
#notify! ⇒ Object
85 86 87 |
# File 'app/models/assignment.rb', line 85 def notify! Mumukit::Nuntius.notify! 'submissions', as_platform_json unless Organization.current.silent? end |
#notify_to_accessible_organizations! ⇒ Object
89 90 91 92 93 94 |
# File 'app/models/assignment.rb', line 89 def notify_to_accessible_organizations! submitter.accessible_organizations.each do |organization| organization.switch! notify! end end |
#persist_submission!(submission) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'app/models/assignment.rb', line 72 def persist_submission!(submission) transaction do .destroy_all update! submission_id: submission.id update_submissions_count! update_last_submission! end end |
#queries_with_results ⇒ Object
30 31 32 33 34 |
# File 'app/models/assignment.rb', line 30 def queries_with_results queries.zip(query_results).map do |query, result| {query: query, status: result&.dig(:status).defaulting(:pending), result: result&.dig(:result)} end end |
#result_html ⇒ Object
56 57 58 |
# File 'app/models/assignment.rb', line 56 def result_html output_content_type.to_html(result) end |
#result_preview ⇒ Object
52 53 54 |
# File 'app/models/assignment.rb', line 52 def result_preview result.truncate(100) if should_retry? end |
#results_visible? ⇒ Boolean
48 49 50 |
# File 'app/models/assignment.rb', line 48 def results_visible? (visible_success_output? || should_retry?) && !exercise.choices? end |
#single_visual_result? ⇒ Boolean
40 41 42 |
# File 'app/models/assignment.rb', line 40 def single_visual_result? test_results.size == 1 && test_results.first[:title].blank? && visible_success_output? end |
#single_visual_result_html ⇒ Object
44 45 46 |
# File 'app/models/assignment.rb', line 44 def single_visual_result_html output_content_type.to_html test_results.first[:result] end |
#visible_expectation_results ⇒ Object
68 69 70 |
# File 'app/models/assignment.rb', line 68 def visible_expectation_results StatusRenderingVerbosity.visible_expectation_results(status, expectation_results || []) end |