Reduce precision and sort in descending order

This commit is contained in:
Maximilian Grundke
2018-07-03 14:10:23 +02:00
parent 804e70ea3b
commit ab2d936165

View File

@ -70,9 +70,9 @@ 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 |key, value|
statistics.append({:key => key.name.to_s, :value => (100.0 / tags[:max_topic_knowledge][key] * value).round(2)}) statistics.append({:key => key.name.to_s, :value => (100.0 / tags[:max_topic_knowledge][key] * value).round})
end end
statistics.sort_by! {|item| item[:value]} statistics.sort_by! {|item| -item[:value]}
respond_to do |format| respond_to do |format|
format.json { render(json: statistics) } format.json { render(json: statistics) }