Add execution environment statistics

This commit is contained in:
Maximilian Grundke
2015-10-29 14:19:31 +01:00
parent 22da25be60
commit 78422647fe
9 changed files with 53 additions and 10 deletions

View File

@ -392,6 +392,3 @@ DEPENDENCIES
uglifier (>= 1.3.0)
web-console (~> 2.0)
will_paginate (~> 3.0)
BUNDLED WITH
1.10.6

View File

@ -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

View File

@ -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

View File

@ -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))

View 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)

View File

@ -167,6 +167,11 @@ de:
shell:
command: Befehl
headline: Shell
statistics:
exercise: Übung
score: Durchschnittliche Punktzahl
runs: Durchschnittliche Anzahl von Versuchen
worktime: Durchschnittliche Arbeitszeit
exercises:
editor:
confirm_start_over: Wollen Sie wirklich von vorne anfangen?

View File

@ -167,6 +167,11 @@ en:
shell:
command: Command
headline: Shell
statistics:
exercise: Exercise
score: Average Score
runs: Average Number of Runs
worktime: Average Worktime
exercises:
editor:
confirm_start_over: Do you really want to start over?
@ -239,10 +244,10 @@ en:
intermediate_submissions: Intermediate Submissions
participants: Participating Users
users: '%{count} distinct users'
user: 'User'
score: 'Score'
runs: 'Runs'
worktime: 'Worktime'
user: User
score: Score
runs: Runs
worktime: Worktime
submit:
failure: An error occured while transmitting your score. Please try again later.
files:

View File

@ -26,6 +26,7 @@ Rails.application.routes.draw do
member do
get :shell
post 'shell', as: :execute_command, to: :execute_command
get :statistics
end
resources :errors, only: [:create, :index, :show]

View File

@ -130,6 +130,14 @@ describe ExecutionEnvironmentsController do
expect_template(:shell)
end
describe 'GET #statistics' do
before(:each) { get :statistics, id: execution_environment.id }
expect_assigns(execution_environment: :execution_environment)
expect_status(200)
expect_template(:statistics)
end
describe 'GET #show' do
before(:each) { get :show, id: execution_environment.id }