diff --git a/app.rb b/app.rb index bb91e4b..0402737 100644 --- a/app.rb +++ b/app.rb @@ -36,7 +36,13 @@ get '/bossfight' do user_raids = Raid.for_user(@username) @first_negative = user_raids.first_negative @soldiers_killed = user_raids.soldiers_lost_to_date(@first_negative.created_at) - @contributers = user_raids.contributors(@first_negative.created_at) + @contributor_attacks = user_raids.contributor_attacks(@first_negative.created_at) + @contributor_soldiers = user_raids.contributor_soldiers(@first_negative.created_at) + + @contributors = [] + @contributor_attacks.each do |k, v| + @contributors << { username: k, attacks: v, lost: @contributor_soldiers[k] } + end erb :bossfight end diff --git a/models/raid.rb b/models/raid.rb index 276e23d..d0169c9 100644 --- a/models/raid.rb +++ b/models/raid.rb @@ -21,7 +21,11 @@ class Raid < ActiveRecord::Base where('created_at <= ?', date).sum(:soldiers) end - def self.contributors(date) + def self.contributor_attacks(date) + where('created_at <= ?', date).group(:attacker).count(:id) + end + + def self.contributor_soldiers(date) where('created_at <= ?', date).group(:attacker).sum(:soldiers) end end diff --git a/views/bossfight.erb b/views/bossfight.erb index 015c051..eb86608 100644 --- a/views/bossfight.erb +++ b/views/bossfight.erb @@ -29,11 +29,11 @@
- <% @contributers.each do |contributer| %> + <% @contributors.each do |contributor| %>