Fix rubocop offenses - Requires Ruby 3.1+
This commit is contained in:
@@ -9,9 +9,9 @@ class AuthenticationToken < ApplicationRecord
|
||||
def self.generate!(user, study_group)
|
||||
create!(
|
||||
shared_secret: SecureRandom.hex(32),
|
||||
user: user,
|
||||
user:,
|
||||
expire_at: 7.days.from_now,
|
||||
study_group: study_group
|
||||
study_group:
|
||||
)
|
||||
end
|
||||
end
|
||||
|
@@ -40,7 +40,7 @@ module CodeOcean
|
||||
scope :visible, -> { where(hidden: false) }
|
||||
|
||||
ROLES.each do |role|
|
||||
scope :"#{role}s", -> { where(role: role) }
|
||||
scope :"#{role}s", -> { where(role:) }
|
||||
end
|
||||
scope :teacher_defined_assessments, -> { where(role: %w[teacher_defined_test teacher_defined_linter]) }
|
||||
|
||||
|
@@ -48,7 +48,7 @@ class ExecutionEnvironment < ApplicationRecord
|
||||
|
||||
def to_json(*_args)
|
||||
{
|
||||
id: id,
|
||||
id:,
|
||||
image: docker_image,
|
||||
prewarmingPoolSize: pool_size,
|
||||
cpuLimit: cpu_limit,
|
||||
|
@@ -79,7 +79,7 @@ class Exercise < ApplicationRecord
|
||||
end
|
||||
|
||||
def time_maximum_score(user)
|
||||
submissions.where(user: user).where("cause IN ('submit','assess')").where.not(score: nil).order('score DESC, created_at ASC').first.created_at
|
||||
submissions.where(user:).where("cause IN ('submit','assess')").where.not(score: nil).order('score DESC, created_at ASC').first.created_at
|
||||
rescue StandardError
|
||||
Time.zone.at(0)
|
||||
end
|
||||
@@ -251,7 +251,7 @@ class Exercise < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
{user_progress: user_progress, additional_user_data: additional_user_data}
|
||||
{user_progress:, additional_user_data:}
|
||||
end
|
||||
|
||||
def get_quantiles(quantiles)
|
||||
@@ -495,7 +495,7 @@ class Exercise < ApplicationRecord
|
||||
description = task_node.xpath('p:description/text()')[0].content
|
||||
self.attributes = {
|
||||
title: task_node.xpath('p:meta-data/p:title/text()')[0].content,
|
||||
description: description,
|
||||
description:,
|
||||
instructions: description,
|
||||
}
|
||||
task_node.xpath('p:files/p:file').all? do |file|
|
||||
@@ -508,7 +508,7 @@ class Exercise < ApplicationRecord
|
||||
content: file.xpath('text()').first.content,
|
||||
read_only: false,
|
||||
hidden: file_class == 'internal',
|
||||
role: role,
|
||||
role:,
|
||||
feedback_message: role == 'teacher_defined_test' ? feedback_message_nodes.first.content : nil,
|
||||
file_type: FileType.find_by(
|
||||
file_extension: ".#{file_name_split.second}"
|
||||
@@ -527,7 +527,7 @@ class Exercise < ApplicationRecord
|
||||
if user
|
||||
# FIXME: where(user: user) will not work here!
|
||||
begin
|
||||
submissions.where(user: user).where("cause IN ('submit','assess')").where.not(score: nil).order('score DESC').first.score || 0
|
||||
submissions.where(user:).where("cause IN ('submit','assess')").where.not(score: nil).order('score DESC').first.score || 0
|
||||
rescue StandardError
|
||||
0
|
||||
end
|
||||
|
@@ -14,7 +14,7 @@ class ExerciseTip < ApplicationRecord
|
||||
def tip_chain?
|
||||
# Ensure each referenced parent exercise tip is set for this exercise
|
||||
unless ExerciseTip.exists?(
|
||||
exercise: exercise, id: parent_exercise_tip
|
||||
exercise:, id: parent_exercise_tip
|
||||
)
|
||||
errors.add :parent_exercise_tip,
|
||||
I18n.t('activerecord.errors.messages.together',
|
||||
|
@@ -10,7 +10,7 @@ class Intervention < ApplicationRecord
|
||||
|
||||
def self.create_default_interventions
|
||||
%w[BreakIntervention QuestionIntervention].each do |name|
|
||||
Intervention.find_or_create_by(name: name)
|
||||
Intervention.find_or_create_by(name:)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -19,12 +19,12 @@ class LinterCheckRun < ApplicationRecord
|
||||
result: linter_result[:result],
|
||||
line: linter_result[:line],
|
||||
scope: linter_result[:scope],
|
||||
testrun: testrun,
|
||||
file: file
|
||||
testrun:,
|
||||
file:
|
||||
)
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
# Something bad happened. Probably, the RegEx in lib/py_lint_adapter.rb didn't work.
|
||||
Sentry.set_extras(testrun: testrun.inspect, linter_result: linter_result)
|
||||
Sentry.set_extras(testrun: testrun.inspect, linter_result:)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -42,7 +42,7 @@ class ProxyExercise < ApplicationRecord
|
||||
end
|
||||
|
||||
def get_matching_exercise(user)
|
||||
assigned_user_proxy_exercise = user_proxy_exercise_exercises.find_by(user: user)
|
||||
assigned_user_proxy_exercise = user_proxy_exercise_exercises.find_by(user:)
|
||||
if assigned_user_proxy_exercise
|
||||
Rails.logger.debug { "retrieved assigned exercise for user #{user.id}: Exercise #{assigned_user_proxy_exercise.exercise}" }
|
||||
assigned_user_proxy_exercise.exercise
|
||||
@@ -57,7 +57,7 @@ class ProxyExercise < ApplicationRecord
|
||||
@reason[:error] = "#{$ERROR_INFO}:\n\t#{e.backtrace.join("\n\t")}"
|
||||
exercises.where('expected_difficulty > 1').sample # difficulty should be > 1 to prevent dummy exercise from being chosen.
|
||||
end
|
||||
user.user_proxy_exercise_exercises << UserProxyExerciseExercise.create(user: user,
|
||||
user.user_proxy_exercise_exercises << UserProxyExerciseExercise.create(user:,
|
||||
exercise: matching_exercise, proxy_exercise: self, reason: @reason.to_json)
|
||||
matching_exercise
|
||||
end
|
||||
@@ -105,9 +105,9 @@ class ProxyExercise < ApplicationRecord
|
||||
relative_knowledge_improvement[potex] = 0.0
|
||||
Rails.logger.debug { "review potential exercise #{potex.id}" }
|
||||
tags.each do |tag|
|
||||
tag_ratio = potex.exercise_tags.find_by(tag: tag).factor.to_f / potex.exercise_tags.inject(0) do |sum, et|
|
||||
sum + et.factor
|
||||
end
|
||||
tag_ratio = potex.exercise_tags.find_by(tag:).factor.to_f / potex.exercise_tags.inject(0) do |sum, et|
|
||||
sum + et.factor
|
||||
end
|
||||
max_topic_knowledge_ratio = potex.expected_difficulty * tag_ratio
|
||||
old_relative_loss_tag = topic_knowledge_user[tag] / topic_knowledge_max[tag]
|
||||
new_relative_loss_tag = topic_knowledge_user[tag] / (topic_knowledge_max[tag] + max_topic_knowledge_ratio)
|
||||
|
@@ -31,9 +31,9 @@ class Runner < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.for(user, execution_environment)
|
||||
runner = find_by(user: user, execution_environment: execution_environment)
|
||||
runner = find_by(user:, execution_environment:)
|
||||
if runner.nil?
|
||||
runner = Runner.create(user: user, execution_environment: execution_environment)
|
||||
runner = Runner.create(user:, execution_environment:)
|
||||
# The `strategy` is added through the before_validation hook `:request_id`.
|
||||
raise Runner::Error::Unknown.new("Runner could not be saved: #{runner.errors.inspect}") unless runner.persisted?
|
||||
else
|
||||
@@ -52,8 +52,8 @@ class Runner < ApplicationRecord
|
||||
@strategy.copy_files(files)
|
||||
end
|
||||
|
||||
def download_file(path, **options, &block)
|
||||
@strategy.download_file(path, **options, &block)
|
||||
def download_file(path, **options, &)
|
||||
@strategy.download_file(path, **options, &)
|
||||
end
|
||||
|
||||
def retrieve_files(raise_exception: true, **options)
|
||||
@@ -93,7 +93,7 @@ class Runner < ApplicationRecord
|
||||
# initializing its Runner::Connection with the given event loop. The Runner::Connection class ensures that
|
||||
# this event loop is stopped after the socket was closed.
|
||||
event_loop = Runner::EventLoop.new
|
||||
socket = @strategy.attach_to_execution(command, event_loop, starting_time, privileged_execution: privileged_execution, &block)
|
||||
socket = @strategy.attach_to_execution(command, event_loop, starting_time, privileged_execution:, &block)
|
||||
event_loop.wait
|
||||
raise socket.error if socket.error.present?
|
||||
rescue Runner::Error => e
|
||||
@@ -120,7 +120,7 @@ class Runner < ApplicationRecord
|
||||
save
|
||||
end
|
||||
|
||||
execution_time = attach_to_execution(command, privileged_execution: privileged_execution) do |socket, starting_time|
|
||||
execution_time = attach_to_execution(command, privileged_execution:) do |socket, starting_time|
|
||||
socket.on :stderr do |data|
|
||||
output[:stderr] << data
|
||||
output[:messages].push({cmd: :write, stream: :stderr, log: data, timestamp: Time.zone.now - starting_time})
|
||||
|
@@ -7,7 +7,7 @@ class StructuredError < ApplicationRecord
|
||||
has_many :structured_error_attributes
|
||||
|
||||
def self.create_from_template(template, message_buffer, submission)
|
||||
instance = create(error_template: template, submission: submission)
|
||||
instance = create(error_template: template, submission:)
|
||||
template.error_template_attributes.each do |attribute|
|
||||
StructuredErrorAttribute.create_from_template(attribute, instance, message_buffer)
|
||||
end
|
||||
|
@@ -10,7 +10,7 @@ class StructuredErrorAttribute < ApplicationRecord
|
||||
if !result.nil? && result.captures.size.positive?
|
||||
value = result.captures[0]
|
||||
end
|
||||
create(structured_error: structured_error, error_template_attribute: attribute, value: value,
|
||||
create(structured_error:, error_template_attribute: attribute, value:,
|
||||
match: !result.nil?)
|
||||
end
|
||||
end
|
||||
|
@@ -88,7 +88,7 @@ class Submission < ApplicationRecord
|
||||
end
|
||||
|
||||
def siblings
|
||||
user.submissions.where(exercise_id: exercise_id)
|
||||
user.submissions.where(exercise_id:)
|
||||
end
|
||||
|
||||
def to_s
|
||||
@@ -129,7 +129,7 @@ class Submission < ApplicationRecord
|
||||
end
|
||||
|
||||
def own_unsolved_rfc
|
||||
RequestForComment.unsolved.find_by(exercise_id: exercise, user_id: user_id)
|
||||
RequestForComment.unsolved.find_by(exercise_id: exercise, user_id:)
|
||||
end
|
||||
|
||||
def unsolved_rfc
|
||||
@@ -162,11 +162,11 @@ class Submission < ApplicationRecord
|
||||
|
||||
# @raise [Runner::Error] if the code could not be run due to a failure with the runner.
|
||||
# See the specific type and message for more details.
|
||||
def run(file, &block)
|
||||
def run(file, &)
|
||||
run_command = command_for execution_environment.run_command, file.filepath
|
||||
durations = {}
|
||||
prepared_runner do |runner, waiting_duration|
|
||||
durations[:execution_duration] = runner.attach_to_execution(run_command, &block)
|
||||
durations[:execution_duration] = runner.attach_to_execution(run_command, &)
|
||||
durations[:waiting_duration] = waiting_duration
|
||||
rescue Runner::Error => e
|
||||
e.waiting_duration = waiting_duration
|
||||
@@ -237,13 +237,13 @@ class Submission < ApplicationRecord
|
||||
def command_substitutions(filename)
|
||||
{
|
||||
class_name: File.basename(filename, File.extname(filename)).upcase_first,
|
||||
filename: filename,
|
||||
filename:,
|
||||
module_name: File.basename(filename, File.extname(filename)).underscore,
|
||||
}
|
||||
end
|
||||
|
||||
def score_file(output, file)
|
||||
assessor = Assessor.new(execution_environment: execution_environment)
|
||||
assessor = Assessor.new(execution_environment:)
|
||||
assessment = assessor.assess(output)
|
||||
passed = ((assessment[:passed] == assessment[:count]) and (assessment[:score]).positive?)
|
||||
testrun_output = passed ? nil : "status: #{output[:status]}\n stdout: #{output[:stdout]}\n stderr: #{output[:stderr]}"
|
||||
@@ -256,8 +256,8 @@ class Submission < ApplicationRecord
|
||||
testrun = Testrun.create(
|
||||
submission: self,
|
||||
cause: 'assess', # Required to differ run and assess for RfC show
|
||||
file: file, # Test file that was executed
|
||||
passed: passed,
|
||||
file:, # Test file that was executed
|
||||
passed:,
|
||||
exit_code: output[:exit_code],
|
||||
status: output[:status],
|
||||
output: testrun_output.presence,
|
||||
@@ -265,7 +265,7 @@ class Submission < ApplicationRecord
|
||||
waiting_for_container_time: output[:waiting_for_container_time]
|
||||
)
|
||||
TestrunMessage.create_for(testrun, output[:messages])
|
||||
TestrunExecutionEnvironment.create(testrun: testrun, execution_environment: @used_execution_environment)
|
||||
TestrunExecutionEnvironment.create(testrun:, execution_environment: @used_execution_environment)
|
||||
|
||||
filename = file.filepath
|
||||
|
||||
@@ -278,7 +278,7 @@ class Submission < ApplicationRecord
|
||||
end
|
||||
|
||||
output.merge!(assessment)
|
||||
output.merge!(filename: filename, message: feedback_message(file, output), weight: file.weight)
|
||||
output.merge!(filename:, message: feedback_message(file, output), weight: file.weight)
|
||||
output.except!(:messages)
|
||||
end
|
||||
|
||||
@@ -308,7 +308,7 @@ class Submission < ApplicationRecord
|
||||
update(score: score.to_d)
|
||||
if normalized_score.to_d == BigDecimal('1.0')
|
||||
Thread.new do
|
||||
RequestForComment.where(exercise_id: exercise_id, user_id: user_id, user_type: user_type).find_each do |rfc|
|
||||
RequestForComment.where(exercise_id:, user_id:, user_type:).find_each do |rfc|
|
||||
rfc.full_score_reached = true
|
||||
rfc.save
|
||||
end
|
||||
|
@@ -73,7 +73,7 @@ class User < ApplicationRecord
|
||||
|
||||
def to_sentry_context
|
||||
{
|
||||
id: id,
|
||||
id:,
|
||||
type: self.class.name,
|
||||
username: displayname,
|
||||
consumer: consumer.name,
|
||||
|
@@ -17,7 +17,7 @@ class UserExerciseFeedback < ApplicationRecord
|
||||
end
|
||||
|
||||
def anomaly_notification
|
||||
AnomalyNotification.where({exercise_id: exercise.id, user_id: user_id, user_type: user_type})
|
||||
AnomalyNotification.where({exercise_id: exercise.id, user_id:, user_type:})
|
||||
.where('created_at < ?', created_at).order('created_at DESC').to_a.first
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user