Class: Course::Assessment::Answer

Inherits:
ApplicationRecord show all
Includes:
Workflow
Defined in:
app/models/course/assessment/answer.rb

Defined Under Namespace

Modules: ProgrammingAbility, ProgrammingTestCaseHelper Classes: AutoGrading, AutoGradingJob, AutoGradingService, CommentNotifier, MultipleResponse, MultipleResponseAutoGradingService, MultipleResponseOption, Programming, ProgrammingAutoGrading, ProgrammingAutoGradingService, ProgrammingAutoGradingTestResult, ProgrammingFile, ProgrammingFileAnnotation, ReducePriorityAutoGradingJob, Scribing, ScribingScribble, TextResponse, TextResponseAutoGradingService, TextResponseComprehensionAutoGradingService, VoiceResponse

Instance Method Summary collapse

Instance Method Details

#assign_params(params) ⇒ Object


102
103
104
# File 'app/models/course/assessment/answer.rb', line 102

def assign_params(params)
  self.grade = params[:grade].to_f if params[:grade]
end

#auto_grade!(redirect_to_path: nil, reduce_priority: false) ⇒ Course::Assessment::Answer::AutoGradingJob|nil

Autogrades the answer. This saves the answer if there are pending changes.

Raises:


66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/models/course/assessment/answer.rb', line 66

def auto_grade!(redirect_to_path: nil, reduce_priority: false)
  raise IllegalStateError if attempting?

  ensure_auto_grading!
  if grade_inline?
    Course::Assessment::Answer::AutoGradingService.grade(self)
    nil
  else
    auto_grading_job_class(reduce_priority).
      perform_later(self, redirect_to_path).tap do |job|
        auto_grading.update_column(:job_id, job.job_id)
      end
  end
end

#finaliseObject (protected)


108
109
110
# File 'app/models/course/assessment/answer.rb', line 108

def finalise
  self. = Time.zone.now
end

#grade_inline?Boolean

Whether we should directly grade the answer in app server.


94
95
96
97
98
99
100
# File 'app/models/course/assessment/answer.rb', line 94

def grade_inline?
  if actable.self_respond_to?(:grade_inline?)
    actable.grade_inline?
  else
    true
  end
end

#publishObject (protected)


112
113
114
115
116
# File 'app/models/course/assessment/answer.rb', line 112

def publish
  self.grade ||= 0
  self.grader = User.stamper || User.system
  self.graded_at = Time.zone.now
end

#reset_answerCourse::Assessment::Answer

Resets the answer by modifying the answer to the default.

Raises:

  • (NotImplementedError)

    answer#reset_answer was not implemented.


86
87
88
89
# File 'app/models/course/assessment/answer.rb', line 86

def reset_answer
  raise NotImplementedError unless actable.self_respond_to?(:reset_answer)
  actable.reset_answer
end