change code style in stats.erb to make @Jmaa and @ohayo-jacob happy

This commit is contained in:
Christoffer Müller Madsen 2017-05-08 23:14:37 +02:00
parent 9253f93c64
commit 85217081ba

View File

@ -19,32 +19,40 @@
<% <%
require 'filesize' require 'filesize'
class User class User
include Comparable attr_accessor :name, :count, :size
attr_accessor :name,:count,:size
def <=> (other) def <=> (other)
other.count <=> count other.count <=> count
end end
end end
usernames = ["christoffermadsen","jmaa","jacob","alexander"] usernames = ["christoffermadsen","jmaa","jacob","alexander"]
users = [] users = []
shot_dir = "/var/shots/" shot_dir = "/var/shots/"
usernames.each do |username| usernames.each do |username|
user = User.new user = User.new
user.name = username user.name = username
size = `du -B1 #{shot_dir}#{username}/ | awk {'print $1'} | head -n 1` size = `du -B1 #{shot_dir}#{username}/ | awk {'print $1'} | head -n 1`
count = `ls -1 #{shot_dir}#{username}/ | wc -l | head -n 1` count = `ls -1 #{shot_dir}#{username}/ | wc -l | head -n 1`
[size,count].each do |x| [size,count].each do |x|
x.delete! "\n" x.delete! "\n"
end end
user.size = size.to_i
user.size = size.to_i
user.count = count.to_i user.count = count.to_i
users << user users << user
end end
count = 0 count = 0
users.sort.each do |user| users.sort.each do |user|
count += 1 count += 1
%> %>
<%= "<tr><td>#{count}</td><td>#{user.name}</td><td class=\"right-align\">#{user.count}</td><td class=\"right-align\">#{Filesize.from(user.size.to_s + "B").pretty}</td></tr>" %> <%= %Q{
<tr>
<td>#{count}</td>
<td>#{user.name}</td>
<td class=\"right-align\">#{user.count}</td>
<td class=\"right-align\">#{Filesize.from(user.size.to_s + "B").pretty}</td>
</tr>}
%>
<% end %> <% end %>
</table> </table>
<h2>Charts</h2> <h2>Charts</h2>