First draft of bossfight page
This commit is contained in:
parent
462d47de61
commit
43c44cd087
3 changed files with 16 additions and 6 deletions
8
app.rb
8
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -29,11 +29,11 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @contributers.each do |contributer| %>
|
||||
<% @contributors.each do |contributor| %>
|
||||
<tr>
|
||||
<td><%= contributer[0]%></td>
|
||||
<td></td>
|
||||
<td><%= readable_number(contributer[1]) %></td>
|
||||
<td><%= contributor[:username] %></td>
|
||||
<td class="text-right"><%= contributor[:attacks] %></td>
|
||||
<td class="text-right"><%= readable_number(contributor[:lost]) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
|
Loading…
Reference in a new issue