diff --git a/app/assets/javascripts/external_users.js b/app/assets/javascripts/external_users.js
index 8e4ec52e..e262e5e5 100644
--- a/app/assets/javascripts/external_users.js
+++ b/app/assets/javascripts/external_users.js
@@ -7,12 +7,14 @@ $(function() {
var buildTagContainer = function(tag) {
return '\
-
\
-
' + tag.key + '
\
-
';
+ ';
};
var jqxhr = $.ajax(window.location.href + '/tag_statistics', {
diff --git a/app/controllers/external_users_controller.rb b/app/controllers/external_users_controller.rb
index 4ef53f6d..441edd67 100644
--- a/app/controllers/external_users_controller.rb
+++ b/app/controllers/external_users_controller.rb
@@ -14,12 +14,12 @@ class ExternalUsersController < ApplicationController
authorize!
end
- def working_time_query
+ def working_time_query(tag=nil)
"""
SELECT user_id,
- exercise_id,
+ bar.exercise_id,
max(score) as maximum_score,
- count(id) as runs,
+ count(bar.id) as runs,
sum(working_time_new) AS working_time
FROM
(SELECT user_id,
@@ -42,9 +42,12 @@ class ExternalUsersController < ApplicationController
AND user_type = 'ExternalUser'
GROUP BY exercise_id,
user_id,
- id) AS foo) AS bar
+ id
+ ) AS foo
+ ) AS bar
+ #{tag.nil? ? '' : ' JOIN exercise_tags et ON et.exercise_id = bar.exercise_id AND et.tag_id = ' + tag + ' '}
GROUP BY user_id,
- exercise_id;
+ bar.exercise_id;
"""
end
@@ -54,7 +57,7 @@ class ExternalUsersController < ApplicationController
statistics = {}
- ActiveRecord::Base.connection.execute(working_time_query).each do |tuple|
+ ActiveRecord::Base.connection.execute(working_time_query(params[:tag])).each do |tuple|
statistics[tuple["exercise_id"].to_i] = tuple
end
@@ -69,8 +72,8 @@ class ExternalUsersController < ApplicationController
statistics = []
tags = ProxyExercise.new().get_user_knowledge_and_max_knowledge(@user, @user.participations.uniq.compact)
- tags[:user_topic_knowledge].each_pair do |key, value|
- statistics.append({:key => key.name.to_s, :value => (100.0 / tags[:max_topic_knowledge][key] * value).round})
+ tags[:user_topic_knowledge].each_pair do |tag, value|
+ statistics.append({key: tag.name.to_s, value: (100.0 / tags[:max_topic_knowledge][tag] * value).round, id: tag.id})
end
statistics.sort_by! {|item| -item[:value]}
diff --git a/app/views/external_users/statistics.html.slim b/app/views/external_users/statistics.html.slim
index a1f78f73..b252c3a2 100644
--- a/app/views/external_users/statistics.html.slim
+++ b/app/views/external_users/statistics.html.slim
@@ -1,6 +1,6 @@
h1 = t('.title')
-- exercises = Exercise.where(:id => @user.submissions.group(:exercise_id).select(:exercise_id).distinct())
+- exercises = Exercise.where(:id => @user.submissions.group(:exercise_id).select(:exercise_id).distinct)
.table-responsive
table.table.table-striped.sortable
@@ -10,9 +10,10 @@ h1 = t('.title')
th.header = t(title)
tbody
- exercises.each do |exercise|
- - if statistics[exercise.id] then stats = statistics[exercise.id] else stats = {"working_time" => 0, "runs" => 0, "score" => 0}
- tr
- td = link_to exercise, controller: "exercises", action: "statistics", external_user_id: @user.id, id: exercise.id
- td = stats["maximum_score"] or 0
- td = stats["runs"] or 0
- td = stats["working_time"] or 0
+ - if statistics[exercise.id]
+ - stats = statistics[exercise.id]
+ tr
+ td = link_to exercise, controller: "exercises", action: "statistics", external_user_id: @user.id, id: exercise.id
+ td = stats["maximum_score"] or 0
+ td = stats["runs"] or 0
+ td = stats["working_time"] or 0