Class: Course::Assessment::Answer::AutoGradingService

Inherits:
Object
  • Object
show all
Defined in:
app/services/course/assessment/answer/auto_grading_service.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.grade(answer) ⇒ Object

Picks the grader for the given answer, then grades into the given +Course::Assessment::Answer::AutoGrading+ object.

Parameters:


8
9
10
11
12
13
14
15
# File 'app/services/course/assessment/answer/auto_grading_service.rb', line 8

def grade(answer)
  answer = if answer.question.auto_gradable?
             pick_grader(answer.question).grade(answer)
           else
             assign_maximum_grade(answer)
           end
  answer.save!
end

Instance Method Details

#evaluate(_answer) ⇒ Integer

Evaluates and mark the answer as correct or not. This is supposed to be implemented by subclasses.

Parameters:

Returns:

  • (Integer)

    grade The grade of the answer.


70
71
72
# File 'app/services/course/assessment/answer/auto_grading_service.rb', line 70

def evaluate(_answer)
  raise 'Not Implemented'
end

#grade(answer) ⇒ Course::Assessment::Answer

Grades into the given +Course::Assessment::Answer::AutoGrading+ object. This assigns the grade and makes sure answer is in the correct state.

Parameters:

Returns:


53
54
55
56
57
58
59
60
61
62
63
# File 'app/services/course/assessment/answer/auto_grading_service.rb', line 53

def grade(answer)
  grade = evaluate(answer)
  answer.evaluate!

  if answer.submission.assessment.autograded?
    answer.publish!
    answer.grade = grade
    answer.grader = User.system
  end
  answer
end