From 1a738a2a06a0ad6fbe3997f24db25a203c31896a Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Wed, 16 Dec 2015 14:00:51 +0100 Subject: [PATCH 1/6] Refine working time query --- app/models/exercise.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 192c4513..a6b5b8a8 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -53,7 +53,7 @@ class Exercise < ActiveRecord::Base (SELECT user_id, id, (created_at - lag(created_at) over (PARTITION BY user_id - ORDER BY id)) AS working_time + ORDER BY created_at)) AS working_time FROM submissions WHERE exercise_id=#{id}) AS foo) AS bar GROUP BY user_id From 0a779e4ed1174bed2047a7ed3e76d878538d4092 Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Wed, 16 Dec 2015 15:40:31 +0100 Subject: [PATCH 2/6] Implement exercise statistics for specific (external) users --- app/views/external_users/statistics.html.slim | 20 +++++++++++++++++-- config/locales/de.yml | 7 +++++++ config/locales/en.yml | 7 +++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/views/external_users/statistics.html.slim b/app/views/external_users/statistics.html.slim index 6c49b967..42a88a8d 100644 --- a/app/views/external_users/statistics.html.slim +++ b/app/views/external_users/statistics.html.slim @@ -1,2 +1,18 @@ -h1 = @user -H2 = 'Hallo' \ No newline at end of file +h1 = t('.title') + +- exercises = Exercise.where(:id => @user.submissions.group(:exercise_id).select(:exercise_id).distinct()) + +.table-responsive + table.table + thead + tr + - ['.exercise', '.score', '.runs', '.worktime'].each do |title| + th.header = t(title) + tbody + - exercises.each do |exercise| + - submissions = @user.submissions.where(:exercise_id => exercise.id, :cause => ['submit', 'run']) + tr + td = link_to exercise.title, exercise + td = submissions.maximum(:score) or 0 + td = submissions.count + td = exercise.average_working_time_for(@user.id) or 0 diff --git a/config/locales/de.yml b/config/locales/de.yml index d96e6927..40b745ad 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -259,6 +259,13 @@ de: time: Zeit cause: Grund score: Punktzahl + external_users: + statistics: + title: Statistiken für Externe Benutzer + exercise: Übung + score: Bewertung + runs: Versuche + worktime: Arbeitszeit files: roles: main_file: Hauptdatei diff --git a/config/locales/en.yml b/config/locales/en.yml index dc63e3dd..501fe745 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -259,6 +259,13 @@ en: time: Time cause: Cause score: Score + external_users: + statistics: + title: External User Statistics + exercise: Exercise + score: Score + runs: Runs + worktime: Working Time files: roles: main_file: Main File From 71e3d81d5f4332909389758cbbf1b667f3b1735d Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Wed, 16 Dec 2015 15:45:32 +0100 Subject: [PATCH 3/6] Link to the user statistics details page for this exercise --- app/views/external_users/statistics.html.slim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/external_users/statistics.html.slim b/app/views/external_users/statistics.html.slim index 42a88a8d..4a4c1e70 100644 --- a/app/views/external_users/statistics.html.slim +++ b/app/views/external_users/statistics.html.slim @@ -12,7 +12,7 @@ h1 = t('.title') - exercises.each do |exercise| - submissions = @user.submissions.where(:exercise_id => exercise.id, :cause => ['submit', 'run']) tr - td = link_to exercise.title, exercise + td = link_to exercise, controller: "exercises", action: "statistics", external_user_id: @user.id, id: exercise.id td = submissions.maximum(:score) or 0 td = submissions.count td = exercise.average_working_time_for(@user.id) or 0 From 6609a5d1ec1e3ab5e33f9031093697ec17ba0310 Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Wed, 16 Dec 2015 15:51:47 +0100 Subject: [PATCH 4/6] Add play button --- app/assets/stylesheets/statistics.css.scss | 16 ++++++++++++++++ .../external_users/statistics.html.slim | 19 +++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/statistics.css.scss b/app/assets/stylesheets/statistics.css.scss index d148f782..631de920 100644 --- a/app/assets/stylesheets/statistics.css.scss +++ b/app/assets/stylesheets/statistics.css.scss @@ -10,3 +10,19 @@ .clickable { cursor: pointer; } + +.flex-container { + display: flex; +} + +.flex-item { + flex-grow: 1; +} + +#play-button { + height: 40px; + width: 40px; + margin-right: 15px; + margin-top: auto; + margin-bottom: auto; +} diff --git a/app/views/exercises/external_users/statistics.html.slim b/app/views/exercises/external_users/statistics.html.slim index ca5142cc..bf2ab0c4 100644 --- a/app/views/exercises/external_users/statistics.html.slim +++ b/app/views/exercises/external_users/statistics.html.slim @@ -21,14 +21,17 @@ h1 = "#{@exercise} (external user #{@external_user})" div class=(@exercise.hide_file_tree ? 'col-sm-12' : 'col-sm-9') #current-file.editor - #submissions-slider - input type='range' orient='horizontal' list='datapoints' min=0 max=submissions.length-1 value=0 - datalist#datapoints - - index=0 - - submissions.each do |submission| - option data-submission=submission - =index - - index += 1 + .flex-container + button.btn.btn-default id='play-button' + span.glyphicon.glyphicon-play + #submissions-slider.flex-item + input type='range' orient='horizontal' list='datapoints' min=0 max=submissions.length-1 value=0 + datalist#datapoints + - index=0 + - submissions.each do |submission| + option data-submission=submission + =index + - index += 1 #timeline .table-responsive From d36e6fd99155b9c83e3be1d3b9a4c699e5935053 Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Wed, 16 Dec 2015 16:14:28 +0100 Subject: [PATCH 5/6] Implement play button behavior --- .../javascripts/submission_statistics.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/assets/javascripts/submission_statistics.js b/app/assets/javascripts/submission_statistics.js index 75fe42cd..5bf5e76c 100644 --- a/app/assets/javascripts/submission_statistics.js +++ b/app/assets/javascripts/submission_statistics.js @@ -55,6 +55,8 @@ $(function() { var submissions = $('#data').data('submissions'); var files = $('#data').data('files'); var filetypes = $('#data').data('file-types'); + var playButton = $('#play-button'); + var playInterval = undefined; editor = ace.edit('current-file'); editor.setShowPrintMargin(false); @@ -88,6 +90,23 @@ $(function() { showActiveFile(); }); + playButton.on('click', function(event) { + if (playInterval == undefined) { + playInterval = setInterval(function() { + if ($.isController('exercises') && $('#timeline').isPresent() && slider.val() < submissions.length - 1) { + slider.val(parseInt(slider.val()) + 1); + slider.change() + } else { + clearInterval(playInterval); + } + }, 5000); + playButton.find('span.glyphicon').removeClass('glyphicon-play').addClass('glyphicon-pause') + } else { + clearInterval(playInterval); + playButton.find('span.glyphicon').removeClass('glyphicon-pause').addClass('glyphicon-play') + } + }); + active_file = files[0][0] initializeFileTree(); showActiveFile(); From 4cd8a501b13b6fd0d99024fbaa03793bb212dcb7 Mon Sep 17 00:00:00 2001 From: Maximilian Grundke Date: Wed, 16 Dec 2015 16:34:13 +0100 Subject: [PATCH 6/6] Switch to fontawesome icons --- app/assets/javascripts/submission_statistics.js | 4 ++-- app/views/exercises/external_users/statistics.html.slim | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/submission_statistics.js b/app/assets/javascripts/submission_statistics.js index 5bf5e76c..9cb820a0 100644 --- a/app/assets/javascripts/submission_statistics.js +++ b/app/assets/javascripts/submission_statistics.js @@ -100,10 +100,10 @@ $(function() { clearInterval(playInterval); } }, 5000); - playButton.find('span.glyphicon').removeClass('glyphicon-play').addClass('glyphicon-pause') + playButton.find('span.fa').removeClass('fa-play').addClass('fa-pause') } else { clearInterval(playInterval); - playButton.find('span.glyphicon').removeClass('glyphicon-pause').addClass('glyphicon-play') + playButton.find('span.fa').removeClass('fa-pause').addClass('fa-play') } }); diff --git a/app/views/exercises/external_users/statistics.html.slim b/app/views/exercises/external_users/statistics.html.slim index bf2ab0c4..fd66ca26 100644 --- a/app/views/exercises/external_users/statistics.html.slim +++ b/app/views/exercises/external_users/statistics.html.slim @@ -23,7 +23,7 @@ h1 = "#{@exercise} (external user #{@external_user})" .flex-container button.btn.btn-default id='play-button' - span.glyphicon.glyphicon-play + span.fa.fa-play #submissions-slider.flex-item input type='range' orient='horizontal' list='datapoints' min=0 max=submissions.length-1 value=0 datalist#datapoints