Add execution environment statistics
This commit is contained in:
@@ -2,7 +2,7 @@ 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]
|
||||
before_action :set_execution_environment, only: MEMBER_ACTIONS + [:execute_command, :shell, :statistics]
|
||||
before_action :set_testing_framework_adapters, only: [:create, :edit, :new, :update]
|
||||
|
||||
def authorize!
|
||||
@@ -28,6 +28,9 @@ class ExecutionEnvironmentsController < ApplicationController
|
||||
render(json: @docker_client.execute_arbitrary_command(params[:command]))
|
||||
end
|
||||
|
||||
def 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)
|
||||
end
|
||||
|
@@ -4,7 +4,7 @@ class ExecutionEnvironmentPolicy < AdminOrAuthorPolicy
|
||||
end
|
||||
private :author?
|
||||
|
||||
[:execute_command?, :shell?].each do |action|
|
||||
[:execute_command?, :shell?, :statistics?].each do |action|
|
||||
define_method(action) { admin? || author? }
|
||||
end
|
||||
end
|
||||
|
@@ -9,7 +9,7 @@ h1 = ExecutionEnvironment.model_name.human(count: 2)
|
||||
th = t('activerecord.attributes.execution_environment.memory_limit')
|
||||
th = t('activerecord.attributes.execution_environment.network_enabled')
|
||||
th = t('activerecord.attributes.execution_environment.permitted_execution_time')
|
||||
th colspan=4 = t('shared.actions')
|
||||
th colspan=5 = t('shared.actions')
|
||||
th colspan=2 = t('shared.resources')
|
||||
tbody
|
||||
- @execution_environments.each do |execution_environment|
|
||||
@@ -23,6 +23,7 @@ h1 = ExecutionEnvironment.model_name.human(count: 2)
|
||||
td = link_to(t('shared.edit'), edit_execution_environment_path(execution_environment))
|
||||
td = link_to(t('shared.destroy'), execution_environment, data: {confirm: t('shared.confirm_destroy')}, method: :delete)
|
||||
td = link_to(t('.shell'), shell_execution_environment_path(execution_environment))
|
||||
td = link_to(t('shared.statistics'), statistics_execution_environment_path(execution_environment))
|
||||
td = link_to(t('activerecord.models.error.other'), execution_environment_errors_path(execution_environment.id))
|
||||
td = link_to(t('activerecord.models.hint.other'), execution_environment_hints_path(execution_environment.id))
|
||||
|
||||
|
23
app/views/execution_environments/statistics.html.slim
Normal file
23
app/views/execution_environments/statistics.html.slim
Normal file
@@ -0,0 +1,23 @@
|
||||
h1 = @execution_environment
|
||||
|
||||
.table-responsive
|
||||
table.table
|
||||
thead
|
||||
tr
|
||||
- ['.exercise', '.score', '.runs', '.worktime'].each do |title|
|
||||
th.header = t(title)
|
||||
tbody
|
||||
- @execution_environment.exercises.each do |exercise|
|
||||
tr
|
||||
- submissions = exercise.submissions
|
||||
td = exercise.title
|
||||
td = submissions.average(:score)
|
||||
td = submissions.count()
|
||||
- minima = submissions.group(:user_id).minimum(:created_at)
|
||||
- maxima = submissions.group(:user_id).maximum(:created_at)
|
||||
- result = 0
|
||||
- results = {}
|
||||
- maxima.each {|key, value| results[key] = value - minima[key]}
|
||||
- results.values.map {|value| result += value}
|
||||
- result /= results.size if results.size > 0
|
||||
td = distance_of_time_in_words(result)
|
Reference in New Issue
Block a user