First draft of bossfight page

This commit is contained in:
Andrew Tomaka 2015-04-28 11:36:17 -04:00
parent 462d47de61
commit 43c44cd087
3 changed files with 16 additions and 6 deletions

8
app.rb
View file

@ -36,7 +36,13 @@ get '/bossfight' do
user_raids = Raid.for_user(@username) user_raids = Raid.for_user(@username)
@first_negative = user_raids.first_negative @first_negative = user_raids.first_negative
@soldiers_killed = user_raids.soldiers_lost_to_date(@first_negative.created_at) @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 erb :bossfight
end end

View file

@ -21,7 +21,11 @@ class Raid < ActiveRecord::Base
where('created_at <= ?', date).sum(:soldiers) where('created_at <= ?', date).sum(:soldiers)
end 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) where('created_at <= ?', date).group(:attacker).sum(:soldiers)
end end
end end

View file

@ -29,11 +29,11 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<% @contributers.each do |contributer| %> <% @contributors.each do |contributor| %>
<tr> <tr>
<td><%= contributer[0]%></td> <td><%= contributor[:username] %></td>
<td></td> <td class="text-right"><%= contributor[:attacks] %></td>
<td><%= readable_number(contributer[1]) %></td> <td class="text-right"><%= readable_number(contributor[:lost]) %></td>
</tr> </tr>
<% end %> <% end %>
</tbody> </tbody>