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>Count</th>
<th>Size</th>
<th>Average size</th>
</tr>
<% order = 0
users.sort.each do |user|
@ -26,6 +27,7 @@
<td>#{user.name}</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.avgsize.to_s + "B").pretty}</td>
</tr>}
%>
<% end %>

View File

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