Commit 4cb40a31a331ba15f953fc9525ccfd3e69696a56

Authored by Victor Costa
1 parent 7cc2f467

Improve ranking calculation

Showing 1 changed file with 4 additions and 3 deletions   Show diff stats
lib/ext/profile.rb
... ... @@ -6,10 +6,11 @@ class Profile
6 6  
7 7 def gamification_plugin_calculate_level
8 8 settings = GamificationPlugin.settings(environment)
  9 + score = self.points
9 10 last_level = 0
10   - (settings.get_setting(:rank_rules) || []).sort_by {|r| r[:points] }.each do |rule|
11   - return last_level if points < rule[:points]
12   - last_level = rule[:level]
  11 + (settings.get_setting(:rank_rules) || []).sort_by {|r| r[:points] }.each_with_index do |rule, i|
  12 + return last_level if score < rule[:points].to_i
  13 + last_level = rule[:level] || i+1
13 14 end
14 15 last_level
15 16 end
... ...