Fix rubocop offenses

This commit is contained in:
Sebastian Serth
2020-10-25 16:10:51 +01:00
parent 0988e41f6d
commit 9fb3dd13e4

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'concurrent/future'
module SubmissionScoring
@ -9,24 +11,22 @@ module SubmissionScoring
assessor = Assessor.new(execution_environment: submission.execution_environment)
output = execute_test_file(file, submission)
assessment = assessor.assess(output)
passed = ((assessment[:passed] == assessment[:count]) and (assessment[:score] > 0))
passed = ((assessment[:passed] == assessment[:count]) and (assessment[:score]).positive?)
testrun_output = passed ? nil : 'message: ' + output[:message].to_s + "\n stdout: " + output[:stdout].to_s + "\n stderr: " + output[:stderr].to_s
unless testrun_output.blank?
submission.exercise.execution_environment.error_templates.each do |template|
pattern = Regexp.new(template.signature).freeze
if pattern.match(testrun_output)
StructuredError.create_from_template(template, testrun_output, submission)
end
StructuredError.create_from_template(template, testrun_output, submission) if pattern.match(testrun_output)
end
end
Testrun.new(
submission: submission,
cause: 'assess',
file: file,
passed: passed,
output: testrun_output,
container_execution_time: output[:container_execution_time],
waiting_for_container_time: output[:waiting_for_container_time]
submission: submission,
cause: 'assess', # Required to differ run and assess for RfC show
file: file, # Test file that was executed
passed: passed,
output: testrun_output,
container_execution_time: output[:container_execution_time],
waiting_for_container_time: output[:waiting_for_container_time]
).save
output.merge!(assessment)
output.merge!(filename: file.name_with_extension, message: feedback_message(file, output), weight: file.weight)
@ -60,22 +60,18 @@ module SubmissionScoring
score = 0.0
unless outputs.nil? || outputs.empty?
outputs.each do |output|
unless output.nil?
score += output[:score] * output[:weight]
end
score += output[:score] * output[:weight] unless output.nil?
if output.present? && output[:status] == :timeout
output[:stderr] += "\n\n#{t('exercises.editor.timeout', permitted_execution_time: submission.exercise.execution_environment.permitted_execution_time.to_s)}"
end
output[:stderr] += "\n\n#{t('exercises.editor.timeout', permitted_execution_time: submission.exercise.execution_environment.permitted_execution_time.to_s)}" if output.present? && output[:status] == :timeout
end
end
submission.update(score: score)
if submission.normalized_score == 1.0
Thread.new do
RequestForComment.where(exercise_id: submission.exercise_id, user_id: submission.user_id, user_type: submission.user_type).each { |rfc|
RequestForComment.where(exercise_id: submission.exercise_id, user_id: submission.user_id, user_type: submission.user_type).each do |rfc|
rfc.full_score_reached = true
rfc.save
}
end
ensure
ActiveRecord::Base.connection_pool.release_connection
end