add average size to index page

This commit is contained in:
Christoffer Müller Madsen 2017-05-09 12:41:33 +02:00
parent 9df423a720
commit e1b5259ba6
2 changed files with 12 additions and 9 deletions

View File

@ -15,6 +15,7 @@
<th>Name</th> <th>Name</th>
<th>Count</th> <th>Count</th>
<th>Size</th> <th>Size</th>
<th>Average size</th>
</tr> </tr>
<% order = 0 <% order = 0
users.sort.each do |user| users.sort.each do |user|
@ -26,6 +27,7 @@
<td>#{user.name}</td> <td>#{user.name}</td>
<td class=\"right-align\">#{user.count}</td> <td class=\"right-align\">#{user.count}</td>
<td class=\"right-align\">#{Filesize.from(user.size.to_s + "B").pretty}</td> <td class=\"right-align\">#{Filesize.from(user.size.to_s + "B").pretty}</td>
<td class=\"right-align\">#{Filesize.from(user.avgsize.to_s + "B").pretty}</td>
</tr>} </tr>}
%> %>
<% end %> <% end %>

View File

@ -8,7 +8,7 @@ erb_file = "dcav-index.erb"
html_file = "/var/shots/html/index.html" html_file = "/var/shots/html/index.html"
class User class User
attr_accessor :name, :count, :size attr_accessor :name, :count, :size, :avgsize
def <=> other def <=> other
other.count <=> count other.count <=> count
end end
@ -16,14 +16,15 @@ end
users = [] users = []
usernames.each do |username| usernames.each do |username|
user = User.new user = User.new
user.name = username user.name = username
user.size = `du -B1 #{shot_dir}#{username}/ | awk {'print $1'} | head -n 1` user.size = `du -B1 #{shot_dir}#{username}/ | awk {'print $1'} | head -n 1`
.delete("\n") .delete("\n")
.to_i .to_i
user.count = `ls -1 #{shot_dir}#{username}/ | wc -l | head -n 1` user.count = `ls -1 #{shot_dir}#{username}/ | wc -l | head -n 1`
.delete("\n") .delete("\n")
.to_i .to_i
user.avgsize = user.size / user.count
users << user users << user
end end