diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 0eae584b..d41573e2 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -9,6 +9,7 @@ class StatsController < ApplicationController before_action :authorize_stats INTERVALS = %i[hour day week month year].freeze + RESOURCES = %i[builds space_used build_time].freeze # XXX: Permitir a Chart.js inyectar su propio CSS content_security_policy only: :index do |policy| @@ -34,9 +35,22 @@ class StatsController < ApplicationController end end end - end - render json: stats + render json: stats + end + end + + def resources + if stale? [last_stat, interval, resource] + options = { + interval: interval, + dimensions: { + deploy_id: @site.deploys.where(type: 'DeployLocal').pluck(:id).first + } + } + + render json: Rollup.series(resource, **options) + end end private @@ -86,6 +100,13 @@ class StatsController < ApplicationController end end + def resource + @resource ||= begin + r = params[:resource].to_sym + RESOURCES.include?(r) ? r : :builds + end + end + # Obtiene la cantidad de nodos de Sutty, para poder calcular la # cantidad de visitas. # diff --git a/app/views/stats/index.haml b/app/views/stats/index.haml index 63aa76cd..0251955e 100644 --- a/app/views/stats/index.haml +++ b/app/views/stats/index.haml @@ -13,5 +13,12 @@ = link_to t(".#{interval}"), site_stats_path(interval: interval), class: "btn #{'btn-primary active' if params[:interval].to_sym == interval}" .mb-3 - %h2= t('.host', count: @hostnames.size) - = line_chart site_stats_host_path(@chart_params), locale: 'es' + %h2= t('.host.title', count: @hostnames.size) + %p.lead= t('.host.description') + = line_chart site_stats_host_path(@chart_params), **@chart_options + + - StatsController::RESOURCES.each do |resource| + .mb-3 + %h2= t(".resources.#{resource}.title") + %p.lead= t(".resources.#{resource}.description") + = line_chart site_stats_resources_path(resource: resource, **@chart_params), **@chart_options diff --git a/config/locales/en.yml b/config/locales/en.yml index 58e0e726..08313a03 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -261,9 +261,21 @@ en: month: 'Monthly' year: 'Yearly' host: - zero: 'Site visits' - one: 'Site visits' - other: 'Visits by site name' + title: + zero: 'Site visits' + one: 'Site visits' + other: 'Visits by site name' + description: 'Counts visited pages on your site, grouped by domain names in use.' + resources: + builds: + title: 'Site publication' + description: 'Times you published your site.' + space_used: + title: 'Server disk usage' + description: 'Average storage space used by your site.' + build_time: + title: 'Publication time' + description: 'Average time your site takes to build.' sites: donations: url: 'https://donaciones.sutty.nl/en/' diff --git a/config/locales/es.yml b/config/locales/es.yml index 8df68896..b1161287 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -266,9 +266,21 @@ es: month: 'Mensuales' year: 'Anuales' host: - zero: 'Visitas del sitio' - one: 'Visitas del sitio' - other: 'Visitas por nombre del sitio' + title: + zero: 'Visitas del sitio' + one: 'Visitas del sitio' + other: 'Visitas por nombre del sitio' + description: 'Cuenta la cantidad de pĆ”ginas visitadas en tu sitio, dividida por los nombres de dominio en uso.' + resources: + builds: + title: 'Publicaciones del sitio' + description: 'Cantidad de veces que publicaste tu sitio.' + space_used: + title: 'Espacio utilizado en el servidor' + description: 'Espacio en disco que ocupa en promedio tu sitio.' + build_time: + title: 'Tiempo de publicaciĆ³n' + description: 'Tiempo promedio que toma en publicarse tu sitio.' sites: donations: url: 'https://donaciones.sutty.nl/'