Add bytes and count per contact

This commit is contained in:
Hugo Peixoto 2023-07-30 17:45:26 +01:00
parent fc7eb83800
commit aa8a920288
2 changed files with 10 additions and 0 deletions

View File

@ -88,6 +88,13 @@ $ PROCS=10 /caminho/para/o/saca-sapos download 1000 eu@exemplo.pt
<p>Tamanho total estimado: <%= h bytes_downloaded / videos_downloaded * videos_known %></p>
<p>Número de pessoas a descarregar vídeos: <%= users %></p>
<p>Tamanho descarregado por cada pessoa:</p>
<ol>
<% downloads_per_user.each_with_index do |downloads, index| %>
<li><%= h downloads["size"] %> (<%= downloads["total"] %> vídeos)</li>
<% end %>
</ol>
<footer>
<hr />

View File

@ -31,6 +31,7 @@ get '/' do
videos = ActiveRecord::Base.connection.execute("select count(1) AS total from videos;")[0]
users = ActiveRecord::Base.connection.execute("select count(distinct email) AS total from downloads;")[0]
downloads_per_user = ActiveRecord::Base.connection.execute("select SUM(size) AS size, COUNT(1) AS total FROM (select email, video_id, MAX(size) as size from downloads group by email, video_id) x GROUP BY email ORDER BY 1 DESC;")
stats = {
videos_known: videos["total"].to_i,
@ -38,6 +39,8 @@ get '/' do
bytes_downloaded: downloads["bytes"].to_i,
downloads_per_user: downloads_per_user,
users: users["total"],
}