Class: XQueueSubmission

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/xqueue_ruby/xqueue_submission.rb

Defined Under Namespace

Classes: InvalidSubmissionError

Constant Summary collapse

DEFAULTS =
{correct: false, score: 0, message: '', errors: ''}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ XQueueSubmission

Returns a new instance of XQueueSubmission.



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/xqueue_ruby/xqueue_submission.rb', line 31

def initialize(hash)
  begin
    fields_hash = DEFAULTS.merge(hash)
    fields_hash.each {|key, value| instance_variable_set("@#{key}", value)}
  rescue NoMethodError => e
    if e.message == "undefined method `[]' for nil:NilClass"
      raise InvalidSubmissionError, "Missing element(s) in JSON: #{hash}"
    end
    raise StandardError 'yoloswag'
  end
end

Instance Attribute Details

#correctObject

String: textual feedback from autograder



23
24
25
# File 'lib/xqueue_ruby/xqueue_submission.rb', line 23

def correct
  @correct
end

#filesObject

XQueue-server-supplied nonce that will be needed to post back a grade for this submission



14
15
16
# File 'lib/xqueue_ruby/xqueue_submission.rb', line 14

def files
  @files
end

#messageObject

Numeric: score reported by autograder



21
22
23
# File 'lib/xqueue_ruby/xqueue_submission.rb', line 21

def message
  @message
end

#queueObject (readonly)

Returns the value of attribute queue.



10
11
12
# File 'lib/xqueue_ruby/xqueue_submission.rb', line 10

def queue
  @queue
end

#scoreObject

one-way hash of edX student ID



19
20
21
# File 'lib/xqueue_ruby/xqueue_submission.rb', line 19

def score
  @score
end

#secretObject (readonly)

The XQueue from which this assignment was retrieved (and to which the grade should be posted back)



12
13
14
# File 'lib/xqueue_ruby/xqueue_submission.rb', line 12

def secret
  @secret
end

#student_idObject (readonly)

When student submitted assignment via edX (a Time object)



17
18
19
# File 'lib/xqueue_ruby/xqueue_submission.rb', line 17

def student_id
  @student_id
end

#submission_timeObject (readonly)

Returns the value of attribute submission_time.



15
16
17
# File 'lib/xqueue_ruby/xqueue_submission.rb', line 15

def submission_time
  @submission_time
end

Class Method Details

.parse_JSON(xqueue, json_response) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/xqueue_ruby/xqueue_submission.rb', line 47

def self.parse_JSON(xqueue, json_response)
  parsed = JSON.parse(json_response)
  header, files, body = parsed['xqueue_header'], parsed['xqueue_files'], parsed['xqueue_body']
  grader_payload = body['grader_payload']
  anonymous_student_id, submission_time = body['student_info']['anonymous_student_id'], Time.parse(body['student_info']['submission_time'])
  XQueueSubmission.new({queue: xqueue, secret: header, files: files, student_id: anonymous_student_id, submission_time: submission_time })
end

Instance Method Details

#expand_filesObject



55
56
57
58
59
60
# File 'lib/xqueue_ruby/xqueue_submission.rb', line 55

def expand_files
  # @files = @files.map each do 
  #   do something
  # end
  # self
end

#post_backObject



43
44
45
# File 'lib/xqueue_ruby/xqueue_submission.rb', line 43

def post_back()
  @queue.put_result(@secret, @score, @correct, @message)
end