From 78422647fe40b007b3942cd142b9936193c4b0a8 Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Thu, 29 Oct 2015 14:19:31 +0100 Subject: [PATCH] Add execution environment statistics --- Gemfile.lock | 3 --- .../execution_environments_controller.rb | 5 +++- app/policies/execution_environment_policy.rb | 2 +- .../execution_environments/index.html.slim | 3 ++- .../statistics.html.slim | 23 +++++++++++++++++++ config/locales/de.yml | 5 ++++ config/locales/en.yml | 13 +++++++---- config/routes.rb | 1 + .../execution_environments_controller_spec.rb | 8 +++++++ 9 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 app/views/execution_environments/statistics.html.slim diff --git a/Gemfile.lock b/Gemfile.lock index d27789ea..0492a3e1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -392,6 +392,3 @@ DEPENDENCIES uglifier (>= 1.3.0) web-console (~> 2.0) will_paginate (~> 3.0) - -BUNDLED WITH - 1.10.6 diff --git a/app/controllers/execution_environments_controller.rb b/app/controllers/execution_environments_controller.rb index 5e69f8fc..574aaed7 100644 --- a/app/controllers/execution_environments_controller.rb +++ b/app/controllers/execution_environments_controller.rb @@ -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 diff --git a/app/policies/execution_environment_policy.rb b/app/policies/execution_environment_policy.rb index 3766f714..bccc9a07 100644 --- a/app/policies/execution_environment_policy.rb +++ b/app/policies/execution_environment_policy.rb @@ -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 diff --git a/app/views/execution_environments/index.html.slim b/app/views/execution_environments/index.html.slim index 7ed2cebb..0ccb880c 100644 --- a/app/views/execution_environments/index.html.slim +++ b/app/views/execution_environments/index.html.slim @@ -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)) diff --git a/app/views/execution_environments/statistics.html.slim b/app/views/execution_environments/statistics.html.slim new file mode 100644 index 00000000..111c6d29 --- /dev/null +++ b/app/views/execution_environments/statistics.html.slim @@ -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) diff --git a/config/locales/de.yml b/config/locales/de.yml index 9716a9a0..12b3df92 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -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? diff --git a/config/locales/en.yml b/config/locales/en.yml index 164082df..771d5a00 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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: diff --git a/config/routes.rb b/config/routes.rb index 1616d9b8..7bb17297 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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] diff --git a/spec/controllers/execution_environments_controller_spec.rb b/spec/controllers/execution_environments_controller_spec.rb index 331c3ec7..2abf59ef 100644 --- a/spec/controllers/execution_environments_controller_spec.rb +++ b/spec/controllers/execution_environments_controller_spec.rb @@ -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 }