5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-16 14:41:41 +00:00

mostrar la cantidad de visitas por origen y pais

This commit is contained in:
f 2022-04-30 17:55:53 -03:00
parent fb34823ce3
commit e00780c7f0
6 changed files with 66 additions and 1 deletions

View file

@ -39,6 +39,20 @@ class StatsController < ApplicationController
last_stat
chart_options
normalized_urls
expires_in = Time.now.try(:"end_of_#{Stat.default_interval}") - Time.now
@columns = {}
Stat::COLUMNS.each do |column|
@columns[column] =
Rails.cache.fetch("stats/#{column}/#{site.id}", expires_in: expires_in) do
Rollup.where(interval: interval, name: "host|#{column}")
.where_dimensions(host: hostnames)
.group("dimensions->>'#{column}'")
.sum(:value)
.transform_values(&:to_i)
end
end
end
# Genera un gráfico de visitas por dominio asociado a este sitio

View file

@ -26,7 +26,7 @@ class UriCollectionJob < PeriodicJob
# Recordar la última vez que se corrió la tarea
stat = site.stats.create! name: STAT_NAME
# Columnas a agrupar
columns = %i[http_referer geoip2_data_country_name].zip([nil]).to_h
columns = Stat::COLUMNS.zip([nil]).to_h
# Recorremos todos los hostnames y uris posibles y luego agrupamos
# recursivamente para no tener que recalcular, asumiendo que es más

View file

@ -5,6 +5,14 @@ class Stat < ApplicationRecord
# XXX: Los intervalos van en orden de mayor especificidad a menor
INTERVALS = %i[day month year].freeze
RESOURCES = %i[builds space_used build_time].freeze
COLUMNS = %i[http_referer geoip2_data_country_name].freeze
belongs_to :site
# El intervalo por defecto
#
# @return [Symbol]
def self.default_interval
INTERVALS.first
end
end

View file

@ -32,6 +32,27 @@
- if @normalized_urls.present?
= line_chart site_stats_uris_path(urls: @normalized_urls, **@chart_params), **@chart_options
.row.mb-5.row-cols-1.row-cols-md-2
- @columns.each_pair do |column, values|
- next if values.blank?
.col.mb-5
%h2= t(".columns.#{column}.title")
%p.lead= t(".columns.#{column}.description")
%table.table
%colgroup
%col
%col
%thead
%tr.sticky-top.background-white
%th{ scope: 'col' }= t(".columns.#{column}.column")
%th{ scope: 'col' }= t('.columns.visits')
%tfoot
%tbody
- values.each_pair do |col, val|
%tr
%th{ scope: 'row', style: 'word-break: break-all' }= col.blank? ? t('.columns.empty') : col
%td= val
.mb-5
%h2= t('.resources.title')
%p.lead= t('.resources.description')

View file

@ -284,6 +284,17 @@ en:
build_time:
title: 'Publication time'
description: 'Average time your site takes to build.'
columns:
visits: "Visits"
empty: "(nothing)"
http_referer:
title: "Referers"
description: "Visits by origin"
column: "Referer"
geoip2_data_country_name:
title: "Countries"
description: "Visits by country"
column: "Country"
sites:
donations:
url: 'https://donaciones.sutty.nl/en/'

View file

@ -289,6 +289,17 @@ es:
build_time:
title: 'Tiempo de publicación'
description: 'Tiempo promedio que toma en publicarse tu sitio.'
columns:
visits: "Visitas"
empty: "(nada)"
http_referer:
title: "Referencias"
description: "Orígenes de las visitas"
column: "Referencia"
geoip2_data_country_name:
title: "Países"
description: "Cantidad de visitas por país"
column: "País"
sites:
donations:
url: 'https://donaciones.sutty.nl/'