mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 18:46:22 +00:00
mostrar un período por defecto
todavía no hay interfaz para cambiarlos
This commit is contained in:
parent
f72d27c308
commit
7c7ae2f750
1 changed files with 24 additions and 6 deletions
|
@ -24,6 +24,13 @@ class StatsController < ApplicationController
|
|||
policy.script_src :self, :unsafe_inline
|
||||
end
|
||||
|
||||
# Parámetros por defecto
|
||||
#
|
||||
# @return [Hash]
|
||||
def default_url_options
|
||||
{ interval: 'day', period_start: Date.today.beginning_of_year, period_end: Date.today }
|
||||
end
|
||||
|
||||
def index
|
||||
breadcrumb I18n.t('stats.index.title'), ''
|
||||
|
||||
|
@ -36,9 +43,9 @@ class StatsController < ApplicationController
|
|||
|
||||
# Genera un gráfico de visitas por dominio asociado a este sitio
|
||||
def host
|
||||
return unless stale? [last_stat, hostnames, interval]
|
||||
return unless stale? [last_stat, hostnames, interval, period]
|
||||
|
||||
stats = Rollup.where_dimensions(host: hostnames).multi_series('host', interval: interval).tap do |series|
|
||||
stats = rollup_scope.where_dimensions(host: hostnames).multi_series('host', interval: interval).tap do |series|
|
||||
series.each do |serie|
|
||||
serie[:name] = serie.dig(:dimensions, 'host')
|
||||
serie[:data].transform_values! do |value|
|
||||
|
@ -51,7 +58,7 @@ class StatsController < ApplicationController
|
|||
end
|
||||
|
||||
def resources
|
||||
return unless stale? [last_stat, interval, resource]
|
||||
return unless stale? [last_stat, interval, resource, period]
|
||||
|
||||
options = {
|
||||
interval: interval,
|
||||
|
@ -60,14 +67,14 @@ class StatsController < ApplicationController
|
|||
}
|
||||
}
|
||||
|
||||
render json: Rollup.series(resource, **options)
|
||||
render json: rollup_scope.series(resource, **options)
|
||||
end
|
||||
|
||||
def uris
|
||||
return unless stale? [last_stat, hostnames, interval, normalized_urls]
|
||||
return unless stale? [last_stat, hostnames, interval, normalized_urls, period]
|
||||
|
||||
options = { host: hostnames, uri: normalized_paths }
|
||||
stats = Rollup.where_dimensions(**options).multi_series('host|uri', interval: interval).tap do |series|
|
||||
stats = rollup_scope.where_dimensions(**options).multi_series('host|uri', interval: interval).tap do |series|
|
||||
series.each do |serie|
|
||||
serie[:name] = serie[:dimensions].slice('host', 'uri').values.join.sub('/index.html', '/')
|
||||
serie[:data].transform_values! do |value|
|
||||
|
@ -81,6 +88,10 @@ class StatsController < ApplicationController
|
|||
|
||||
private
|
||||
|
||||
def rollup_scope
|
||||
Rollup.where(time: period)
|
||||
end
|
||||
|
||||
def last_stat
|
||||
@last_stat ||= Stat.last
|
||||
end
|
||||
|
@ -171,4 +182,11 @@ class StatsController < ApplicationController
|
|||
def nodes
|
||||
@nodes ||= ENV.fetch('NODES', 1).to_i
|
||||
end
|
||||
|
||||
def period
|
||||
@period ||= begin
|
||||
p = params.permit(:period_start, :period_end)
|
||||
p[:period_start]..p[:period_end]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue