Merge pull request #196 from openHPI/feature/improved-tag-stats
Feature/improved tag stats
This commit is contained in:
@ -7,12 +7,14 @@ $(function() {
|
|||||||
|
|
||||||
var buildTagContainer = function(tag) {
|
var buildTagContainer = function(tag) {
|
||||||
return '\
|
return '\
|
||||||
<div class="tag">\
|
<a href="' + location.href +'/statistics?tag=' + tag.id + '">\
|
||||||
<div class="name">' + tag.key + '</div>\
|
<div class="tag">\
|
||||||
<div class="progress">\
|
<div class="name">' + tag.key + '</div>\
|
||||||
<div class="progress-bar" role="progressbar" style="width:' + tag.value + '%">' + tag.value + '%</div>\
|
<div class="progress">\
|
||||||
|
<div class="progress-bar" role="progressbar" style="width:' + tag.value + '%">' + tag.value + '%</div>\
|
||||||
|
</div>\
|
||||||
</div>\
|
</div>\
|
||||||
</div>';
|
</a>';
|
||||||
};
|
};
|
||||||
|
|
||||||
var jqxhr = $.ajax(window.location.href + '/tag_statistics', {
|
var jqxhr = $.ajax(window.location.href + '/tag_statistics', {
|
||||||
|
@ -14,12 +14,12 @@ class ExternalUsersController < ApplicationController
|
|||||||
authorize!
|
authorize!
|
||||||
end
|
end
|
||||||
|
|
||||||
def working_time_query
|
def working_time_query(tag=nil)
|
||||||
"""
|
"""
|
||||||
SELECT user_id,
|
SELECT user_id,
|
||||||
exercise_id,
|
bar.exercise_id,
|
||||||
max(score) as maximum_score,
|
max(score) as maximum_score,
|
||||||
count(id) as runs,
|
count(bar.id) as runs,
|
||||||
sum(working_time_new) AS working_time
|
sum(working_time_new) AS working_time
|
||||||
FROM
|
FROM
|
||||||
(SELECT user_id,
|
(SELECT user_id,
|
||||||
@ -42,9 +42,12 @@ class ExternalUsersController < ApplicationController
|
|||||||
AND user_type = 'ExternalUser'
|
AND user_type = 'ExternalUser'
|
||||||
GROUP BY exercise_id,
|
GROUP BY exercise_id,
|
||||||
user_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,
|
GROUP BY user_id,
|
||||||
exercise_id;
|
bar.exercise_id;
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -54,7 +57,7 @@ class ExternalUsersController < ApplicationController
|
|||||||
|
|
||||||
statistics = {}
|
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
|
statistics[tuple["exercise_id"].to_i] = tuple
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -69,8 +72,8 @@ class ExternalUsersController < ApplicationController
|
|||||||
|
|
||||||
statistics = []
|
statistics = []
|
||||||
tags = ProxyExercise.new().get_user_knowledge_and_max_knowledge(@user, @user.participations.uniq.compact)
|
tags = ProxyExercise.new().get_user_knowledge_and_max_knowledge(@user, @user.participations.uniq.compact)
|
||||||
tags[:user_topic_knowledge].each_pair do |key, value|
|
tags[:user_topic_knowledge].each_pair do |tag, value|
|
||||||
statistics.append({:key => key.name.to_s, :value => (100.0 / tags[:max_topic_knowledge][key] * value).round})
|
statistics.append({key: tag.name.to_s, value: (100.0 / tags[:max_topic_knowledge][tag] * value).round, id: tag.id})
|
||||||
end
|
end
|
||||||
statistics.sort_by! {|item| -item[:value]}
|
statistics.sort_by! {|item| -item[:value]}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
h1 = t('.title')
|
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-responsive
|
||||||
table.table.table-striped.sortable
|
table.table.table-striped.sortable
|
||||||
@ -10,9 +10,10 @@ h1 = t('.title')
|
|||||||
th.header = t(title)
|
th.header = t(title)
|
||||||
tbody
|
tbody
|
||||||
- exercises.each do |exercise|
|
- exercises.each do |exercise|
|
||||||
- if statistics[exercise.id] then stats = statistics[exercise.id] else stats = {"working_time" => 0, "runs" => 0, "score" => 0}
|
- if statistics[exercise.id]
|
||||||
tr
|
- stats = statistics[exercise.id]
|
||||||
td = link_to exercise, controller: "exercises", action: "statistics", external_user_id: @user.id, id: exercise.id
|
tr
|
||||||
td = stats["maximum_score"] or 0
|
td = link_to exercise, controller: "exercises", action: "statistics", external_user_id: @user.id, id: exercise.id
|
||||||
td = stats["runs"] or 0
|
td = stats["maximum_score"] or 0
|
||||||
td = stats["working_time"] or 0
|
td = stats["runs"] or 0
|
||||||
|
td = stats["working_time"] or 0
|
||||||
|
Reference in New Issue
Block a user