Apply automatic rubocop fixes

This commit is contained in:
Sebastian Serth
2021-05-14 10:51:44 +02:00
parent fe4000916c
commit 6cbecb5b39
440 changed files with 2705 additions and 1853 deletions

View File

@ -1,9 +1,11 @@
# frozen_string_literal: true
class ExecutionEnvironmentsController < ApplicationController
include CommonBehavior
before_action :set_docker_images, only: [:create, :edit, :new, :update]
before_action :set_execution_environment, only: MEMBER_ACTIONS + [:execute_command, :shell, :statistics]
before_action :set_testing_framework_adapters, only: [:create, :edit, :new, :update]
before_action :set_docker_images, only: %i[create edit new update]
before_action :set_execution_environment, only: MEMBER_ACTIONS + %i[execute_command shell statistics]
before_action :set_testing_framework_adapters, only: %i[create edit new update]
def authorize!
authorize(@execution_environment || @execution_environments)
@ -20,17 +22,15 @@ class ExecutionEnvironmentsController < ApplicationController
destroy_and_respond(object: @execution_environment)
end
def edit
end
def edit; end
def execute_command
@docker_client = DockerClient.new(execution_environment: @execution_environment)
render(json: @docker_client.execute_arbitrary_command(params[:command]))
end
def working_time_query
"""
"
SELECT exercise_id, avg(working_time) as average_time, stddev_samp(extract('epoch' from working_time)) * interval '1 second' as stddev_time
FROM
(
@ -52,11 +52,11 @@ class ExecutionEnvironmentsController < ApplicationController
GROUP BY exercise_id, user_id, id) AS foo) AS bar
GROUP BY user_id, exercise_id
) AS baz GROUP BY exercise_id;
"""
"
end
def user_query
"""
"
SELECT
id AS exercise_id,
COUNT(DISTINCT user_id) AS users,
@ -79,7 +79,7 @@ class ExecutionEnvironmentsController < ApplicationController
GROUP BY e.id,
s.user_id) AS inner_query
GROUP BY id;
"""
"
end
def statistics
@ -87,21 +87,25 @@ class ExecutionEnvironmentsController < ApplicationController
user_statistics = {}
ApplicationRecord.connection.execute(working_time_query).each do |tuple|
working_time_statistics[tuple["exercise_id"].to_i] = tuple
working_time_statistics[tuple['exercise_id'].to_i] = tuple
end
ApplicationRecord.connection.execute(user_query).each do |tuple|
user_statistics[tuple["exercise_id"].to_i] = tuple
user_statistics[tuple['exercise_id'].to_i] = tuple
end
render locals: {
working_time_statistics: working_time_statistics,
user_statistics: user_statistics
user_statistics: user_statistics,
}
end
def execution_environment_params
params[:execution_environment].permit(:docker_image, :exposed_ports, :editor_mode, :file_extension, :file_type_id, :help, :indent_size, :memory_limit, :name, :network_enabled, :permitted_execution_time, :pool_size, :run_command, :test_command, :testing_framework).merge(user_id: current_user.id, user_type: current_user.class.name) if params[:execution_environment].present?
if params[:execution_environment].present?
params[:execution_environment].permit(:docker_image, :exposed_ports, :editor_mode, :file_extension, :file_type_id, :help, :indent_size, :memory_limit, :name, :network_enabled, :permitted_execution_time, :pool_size, :run_command, :test_command, :testing_framework).merge(
user_id: current_user.id, user_type: current_user.class.name
)
end
end
private :execution_environment_params
@ -118,10 +122,10 @@ class ExecutionEnvironmentsController < ApplicationController
def set_docker_images
DockerClient.check_availability!
@docker_images = DockerClient.image_tags.sort
rescue DockerClient::Error => error
rescue DockerClient::Error => e
@docker_images = []
flash[:warning] = error.message
Sentry.capture_exception(error)
flash[:warning] = e.message
Sentry.capture_exception(e)
end
private :set_docker_images
@ -139,8 +143,7 @@ class ExecutionEnvironmentsController < ApplicationController
end
private :set_testing_framework_adapters
def shell
end
def shell; end
def show
if @execution_environment.testing_framework?