display popular sites

This commit is contained in:
Kyle Drake 2015-09-02 03:09:02 -07:00
parent caa702c964
commit 84b4d98e35
3 changed files with 33 additions and 3 deletions

View file

@ -36,8 +36,14 @@ get '/admin/usage' do
stats.collect {|s| s == 0}.uniq
unless stats.select {|k,v| v == 0}.length == stats.keys.length
@monthly_stats.push stats.merge(date: month)
if stats[:views] != 0 && stats[:hits] != 0 && stats[:bandwidth] != 0
popular_sites = DB[
'select sum(bandwidth) as bandwidth,username from stats left join sites on sites.id=stats.site_id where stats.created_at >= ? and stats.created_at < ? group by username order by bandwidth desc limit 50',
month,
month.next_month
].all
@monthly_stats.push stats.merge(date: month).merge(popular_sites: popular_sites)
end
month = month.prev_month

View file

@ -9,7 +9,8 @@
<div class="row">
<div class="col col-100">
<a href="/admin/reports">Site Reports</a>
<a href="/admin/reports">Site Reports</a><br>
<a href="/admin/usage">Site Bandwidth Usage</a>
</div>
</div>

View file

@ -28,4 +28,27 @@
</div>
</div>
<div class="row">
<div class="col col-100">
<h1>Popular Sites</h1>
<% @monthly_stats.each do |monthly_stat| %>
<h2><%= monthly_stat[:date].strftime('%Y %B') %></h2>
<table class="table">
<tr>
<th>Username</th>
<th>Profile</th>
<th>Bandwidth</th>
</tr>
<% monthly_stat[:popular_sites].each do |s| %>
<tr>
<td style="text-align: left"><a href="http://<%= s[:username] %>.neocities.org"><%= s[:username] %></a></td>
<td><a href="/site/<%= s[:username] %>">link</a></td>
<td style="text-align: left"><%= s[:bandwidth].to_bytes_pretty %></td>
</tr>
<% end %>
</table
<% end %>
</div>
</div>
</div>