Class: Judge0::Submission
- Inherits:
-
Object
- Object
- Judge0::Submission
- Defined in:
- lib/submission.rb
Instance Attribute Summary collapse
-
#compile_out ⇒ Object
readonly
Returns the value of attribute compile_out.
-
#cpu_extra_time ⇒ Object
Returns the value of attribute cpu_extra_time.
-
#cpu_time_limit ⇒ Object
Returns the value of attribute cpu_time_limit.
-
#enable_per_process_and_thread_memory_limit ⇒ Object
Returns the value of attribute enable_per_process_and_thread_memory_limit.
-
#enable_per_process_and_thread_time_limit ⇒ Object
Returns the value of attribute enable_per_process_and_thread_time_limit.
-
#expected_output ⇒ Object
Returns the value of attribute expected_output.
-
#language_id ⇒ Object
Returns the value of attribute language_id.
-
#max_file_size ⇒ Object
Returns the value of attribute max_file_size.
-
#max_processes_and_or_threads ⇒ Object
Returns the value of attribute max_processes_and_or_threads.
-
#memory ⇒ Object
readonly
Returns the value of attribute memory.
-
#memory_limit ⇒ Object
Returns the value of attribute memory_limit.
-
#number_of_runs ⇒ Object
Returns the value of attribute number_of_runs.
-
#source_code ⇒ Object
Returns the value of attribute source_code.
-
#stack_limit ⇒ Object
Returns the value of attribute stack_limit.
-
#status_description ⇒ Object
readonly
Returns the value of attribute status_description.
-
#status_id ⇒ Object
readonly
Returns the value of attribute status_id.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdin ⇒ Object
Returns the value of attribute stdin.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#token ⇒ Object
Returns the value of attribute token.
-
#wall_time_limit ⇒ Object
Returns the value of attribute wall_time_limit.
Instance Method Summary collapse
- #get_token ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ Submission
constructor
A new instance of Submission.
- #output ⇒ Object
- #result ⇒ Object
- #run ⇒ Object
- #tests_battery(tests) ⇒ Object
- #to_hash ⇒ Object
- #to_submission(response) ⇒ Object
- #wait_response ⇒ Object
- #wait_response! ⇒ Object
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Submission
Returns a new instance of Submission.
14 15 16 17 18 19 |
# File 'lib/submission.rb', line 14 def initialize( = {}) .each do |key, value| instance_variable_set("@#{key}", value) end yield(self) if block_given? end |
Instance Attribute Details
#compile_out ⇒ Object (readonly)
Returns the value of attribute compile_out.
11 12 13 |
# File 'lib/submission.rb', line 11 def compile_out @compile_out end |
#cpu_extra_time ⇒ Object
Returns the value of attribute cpu_extra_time.
3 4 5 |
# File 'lib/submission.rb', line 3 def cpu_extra_time @cpu_extra_time end |
#cpu_time_limit ⇒ Object
Returns the value of attribute cpu_time_limit.
3 4 5 |
# File 'lib/submission.rb', line 3 def cpu_time_limit @cpu_time_limit end |
#enable_per_process_and_thread_memory_limit ⇒ Object
Returns the value of attribute enable_per_process_and_thread_memory_limit.
3 4 5 |
# File 'lib/submission.rb', line 3 def enable_per_process_and_thread_memory_limit @enable_per_process_and_thread_memory_limit end |
#enable_per_process_and_thread_time_limit ⇒ Object
Returns the value of attribute enable_per_process_and_thread_time_limit.
3 4 5 |
# File 'lib/submission.rb', line 3 def enable_per_process_and_thread_time_limit @enable_per_process_and_thread_time_limit end |
#expected_output ⇒ Object
Returns the value of attribute expected_output.
3 4 5 |
# File 'lib/submission.rb', line 3 def expected_output @expected_output end |
#language_id ⇒ Object
Returns the value of attribute language_id.
3 4 5 |
# File 'lib/submission.rb', line 3 def language_id @language_id end |
#max_file_size ⇒ Object
Returns the value of attribute max_file_size.
3 4 5 |
# File 'lib/submission.rb', line 3 def max_file_size @max_file_size end |
#max_processes_and_or_threads ⇒ Object
Returns the value of attribute max_processes_and_or_threads.
3 4 5 |
# File 'lib/submission.rb', line 3 def max_processes_and_or_threads @max_processes_and_or_threads end |
#memory ⇒ Object (readonly)
Returns the value of attribute memory.
11 12 13 |
# File 'lib/submission.rb', line 11 def memory @memory end |
#memory_limit ⇒ Object
Returns the value of attribute memory_limit.
3 4 5 |
# File 'lib/submission.rb', line 3 def memory_limit @memory_limit end |
#number_of_runs ⇒ Object
Returns the value of attribute number_of_runs.
3 4 5 |
# File 'lib/submission.rb', line 3 def number_of_runs @number_of_runs end |
#source_code ⇒ Object
Returns the value of attribute source_code.
3 4 5 |
# File 'lib/submission.rb', line 3 def source_code @source_code end |
#stack_limit ⇒ Object
Returns the value of attribute stack_limit.
3 4 5 |
# File 'lib/submission.rb', line 3 def stack_limit @stack_limit end |
#status_description ⇒ Object (readonly)
Returns the value of attribute status_description.
11 12 13 |
# File 'lib/submission.rb', line 11 def status_description @status_description end |
#status_id ⇒ Object (readonly)
Returns the value of attribute status_id.
11 12 13 |
# File 'lib/submission.rb', line 11 def status_id @status_id end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
11 12 13 |
# File 'lib/submission.rb', line 11 def stderr @stderr end |
#stdin ⇒ Object
Returns the value of attribute stdin.
3 4 5 |
# File 'lib/submission.rb', line 3 def stdin @stdin end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
11 12 13 |
# File 'lib/submission.rb', line 11 def stdout @stdout end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
11 12 13 |
# File 'lib/submission.rb', line 11 def time @time end |
#token ⇒ Object
Returns the value of attribute token.
3 4 5 |
# File 'lib/submission.rb', line 3 def token @token end |
#wall_time_limit ⇒ Object
Returns the value of attribute wall_time_limit.
3 4 5 |
# File 'lib/submission.rb', line 3 def wall_time_limit @wall_time_limit end |
Instance Method Details
#get_token ⇒ Object
90 91 92 93 |
# File 'lib/submission.rb', line 90 def get_token resp = Faraday.post(Judge0.url('/submissions/?base64_encoded=false&wait=false'), to_hash) @token = JSON.parse(resp.body)['token'] end |
#output ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/submission.rb', line 61 def output msg = '' msg = @stdout if @stdout msg +="ERROR:\n#{@stderr}\n" if @stderr msg += "MESSAGE:\n#{@message}\n" if msg end |
#result ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/submission.rb', line 46 def result { stdout: @stdout, time: @time, memory: @memory, stderr: @stderr, compile_out: @compile_out, message: , status: { id: @status_id, description: @status_description } } end |
#run ⇒ Object
21 22 23 24 25 |
# File 'lib/submission.rb', line 21 def run get_token wait_response! end |
#tests_battery(tests) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/submission.rb', line 27 def tests_battery (tests) tests.map! do |test| if test.respond_to?(:input) && test.respond_to?(:output) @stdin = test.input @expected_output = test.output elsif test.include?(:input) && test.respond_to?(:output) @stdin = test[:input] @expected_output = test[:output] else @stdin = test[0] @expected_output = test[1] end get_token end tests.map do |test| wait_response end end |
#to_hash ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/submission.rb', line 69 def to_hash Hash[ instance_variables.map do |name| [name[1..-1].to_sym, instance_variable_get(name)] end ] end |
#to_submission(response) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/submission.rb', line 77 def to_submission(response) @stdout = response['stdout'] @time = response['time'].to_f @memory = response['memory'] @stderr = response['stderr'] @compile_out = response['compile_out'] = response['message'] @status_id = response['status']['id'] @status_description = response['status']['description'] result end |
#wait_response ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/submission.rb', line 95 def wait_response begin resp = Faraday.get(Judge0.url("/submissions/#{@token}")) body = JSON.parse(resp.body) puts "waiting: #{token} - #{body['status']['description']}" unless ENV['RAILS_ENV'] == 'test' end while body['status']['id'] <= 2 body end |
#wait_response! ⇒ Object
104 105 106 |
# File 'lib/submission.rb', line 104 def wait_response! to_submission(wait_response) end |