Class: Course::Assessment::Question::Programming

Inherits:
ApplicationRecord
  • Object
show all
Includes:
DuplicationStateTrackingConcern
Defined in:
app/models/course/assessment/question/programming.rb

Defined Under Namespace

Classes: LanguagePackageService, ProgrammingPackageService

Constant Summary collapse

CPU_TIMEOUT =

Maximum CPU time a programming question can allow before the evaluation gets killed.

30.seconds
MEMORY_LIMIT =

Maximum memory (in MB) the programming question can allow. Do NOT change this to num.megabytes as the ProgramingEvaluationService expects it in MB. Currently set to nil as Java evaluations do not work with a ulimit below 3 GB. Docker container memory limits will keep the evaluation in check.

nil

Instance Method Summary collapse

Methods included from DuplicationStateTrackingConcern

#clear_duplication_flag, #duplicating?, #set_duplication_flag

Instance Method Details

#attempt(submission, last_attempt = nil) ⇒ Object


48
49
50
51
52
53
54
55
56
57
58
# File 'app/models/course/assessment/question/programming.rb', line 48

def attempt(submission, last_attempt = nil)
  answer = Course::Assessment::Answer::Programming.new(submission: submission, question: question)
  if last_attempt
    last_attempt.files.each do |file|
      answer.files.build(filename: file.filename, content: file.content)
    end
  else
    copy_template_files_to(answer)
  end
  answer.acting_as
end

#auto_gradable?Boolean

Returns:

  • (Boolean)

36
37
38
# File 'app/models/course/assessment/question/programming.rb', line 36

def auto_gradable?
  !test_cases.empty?
end

#auto_graderObject


44
45
46
# File 'app/models/course/assessment/question/programming.rb', line 44

def auto_grader
  Course::Assessment::Answer::ProgrammingAutoGradingService.new
end

#copy_template_files_to(answer) ⇒ Object

Copies the template files from this question to the specified answer.

to.

Parameters:


76
77
78
79
80
# File 'app/models/course/assessment/question/programming.rb', line 76

def copy_template_files_to(answer)
  template_files.each do |template_file|
    template_file.copy_template_to(answer)
  end
end

#downloadable?Boolean

Returns:

  • (Boolean)

90
91
92
# File 'app/models/course/assessment/question/programming.rb', line 90

def downloadable?
  true
end

#edit_online?Boolean

Returns:

  • (Boolean)

40
41
42
# File 'app/models/course/assessment/question/programming.rb', line 40

def edit_online?
  package_type == 'online_editor'
end

#imported_attachment=(attachment) ⇒ Object

This specifies the attachment which was imported.

Using this to assign the attachment when you do not want to run the evaluation callbacks when the record is saved.


67
68
69
70
# File 'app/models/course/assessment/question/programming.rb', line 67

def imported_attachment=(attachment)
  self.attachment = attachment
  clear_attachment_change
end

#initialize_duplicate(duplicator, other) ⇒ Object


94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/models/course/assessment/question/programming.rb', line 94

def initialize_duplicate(duplicator, other)
  copy_attributes(other)
  associate_duplicated_skills(duplicator, other)

  # TODO: check if there are any side effects from this
  self.import_job_id = nil
  self.template_files = duplicator.duplicate(other.template_files)
  self.test_cases = duplicator.duplicate(other.test_cases)
  self.imported_attachment = duplicator.duplicate(other.attachment)

  set_duplication_flag
end

#non_autograded_template_files=(template_files) ⇒ Object

This specifies the template files generated from the online editor.

This is used by the +Course::Assessment::Question::Programming::ProgrammingPackageService+ to set the template files for a non-autograded programming question.


111
112
113
114
115
# File 'app/models/course/assessment/question/programming.rb', line 111

def non_autograded_template_files=(template_files)
  self.template_files.clear
  self.template_files = template_files
  test_cases.clear
end

#question_typeObject

returns the type of question i.e. Programming


118
119
120
# File 'app/models/course/assessment/question/programming.rb', line 118

def question_type
  I18n.t('course.assessment.question.programming.question_type')
end

#test_cases_by_typeHash

Groups test cases by test case type. Each key returns an array of all the test cases of that type.

Returns:

  • (Hash)

    A hash of the test cases keyed by test case type.


86
87
88
# File 'app/models/course/assessment/question/programming.rb', line 86

def test_cases_by_type
  test_cases.group_by(&:test_case_type)
end

#to_partial_pathObject


60
61
62
# File 'app/models/course/assessment/question/programming.rb', line 60

def to_partial_path
  'course/assessment/question/programming/programming'
end