5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-27 02:36:21 +00:00

Merge branch 'blazer' into panel.sutty.nl

This commit is contained in:
f 2022-04-30 14:40:43 -03:00
commit 7c9c6960aa
4 changed files with 35 additions and 45 deletions

View file

@ -46,6 +46,30 @@ module RecursiveRollup
end
end
# Reducir las estadísticas calculadas aplicando un rollup sobre el
# intervalo más amplio.
#
# @param :name [String]
# @param :beginning [Time]
# @param :operation [Symbol]
# @param :dimensions [Hash]
# @return [nil]
def reduce_rollup(name, beginning, operation, **dimensions)
Stat::INTERVALS.reduce do |previous, current|
recursive_rollup(name: name,
interval_previous: previous,
interval: current,
dimensions: dimensions,
beginning: beginning,
operation: operation)
# Devolver el intervalo actual
current
end
nil
end
# @param :dimensions [Hash]
# @return [Array]
def dimensions_to_jsonb_query(dimensions)

View file

@ -9,10 +9,8 @@ class StatCollectionJob < PeriodicJob
def perform(site_id:, once: true)
@site = Site.find site_id
# Registrar que se hicieron todas las recolecciones
stat = site.stats.create! name: STAT_NAME
beginning = beginning_of_interval
stat = site.stats.create! name: STAT_NAME
scope.rollup('builds', **options)
@ -24,16 +22,9 @@ class StatCollectionJob < PeriodicJob
rollup.average(:seconds)
end
# XXX: Es correcto promediar promedios?
Stat::INTERVALS.reduce do |previous, current|
opts = { interval_previous: previous, interval: current, beginning: beginning, dimensions: { site_id: site.id } }
recursive_rollup(name: 'builds', **opts)
recursive_rollup(name: 'space_used', operation: :average, **opts)
recursive_rollup(name: 'build_time', operation: :average, **opts)
current
end
reduce_rollup('builds', beginning, :sum, site_id: site_id)
reduce_rollup('space_used', beginning, :average, site_id: site_id)
reduce_rollup('build_time', beginning, :average, site_id: site_id)
stat.touch
run_again! unless once
@ -45,10 +36,7 @@ class StatCollectionJob < PeriodicJob
#
# @return [ActiveRecord::Relation]
def scope
@scope ||= site.build_stats
.jekyll
.where('created_at >= ?', beginning_of_interval)
.group(:site_id)
@scope ||= site.build_stats.jekyll.where('created_at >= ?', beginning_of_interval)
end
# Las opciones por defecto

View file

@ -52,7 +52,7 @@ class UriCollectionJob < PeriodicJob
dimensions = { host: host, uri: uri }
rollup(name, beginning, **dimensions)
reduce_rollup(name, beginning, **dimensions)
reduce_rollup(name, beginning, :sum, **dimensions)
columns.each_pair do |column, values|
# Obtener orígenes de visitas por host
@ -62,7 +62,7 @@ class UriCollectionJob < PeriodicJob
column_dimensions[column] = value
rollup(column_name, beginning, **column_dimensions)
reduce_rollup(column_name, beginning, **column_dimensions)
reduce_rollup(column_name, beginning, :sum, **column_dimensions)
end
end
end
@ -75,7 +75,7 @@ class UriCollectionJob < PeriodicJob
beginning: beginning)
# Acumular por mes y año
reduce_rollup('host', beginning, **host_dimensions)
reduce_rollup('host', beginning, :sum, **host_dimensions)
columns.each_key do |column|
square_rollup(name: "host|uri|#{column}",
@ -84,7 +84,7 @@ class UriCollectionJob < PeriodicJob
dimensions: host_dimensions,
beginning: beginning)
reduce_rollup("host|#{column}", beginning, **host_dimensions)
reduce_rollup("host|#{column}", beginning, :sum, **host_dimensions)
end
end
@ -110,28 +110,6 @@ class UriCollectionJob < PeriodicJob
.rollup(name, interval: starting_interval, update: true)
end
# Reducir las estadísticas calculadas aplicando un rollup sobre el
# intervalo más amplio.
#
# @param :name [String]
# @param :beginning [Time]
# @param :dimensions [Hash]
# @return [nil]
def reduce_rollup(name, beginning, **dimensions)
Stat::INTERVALS.reduce do |previous, current|
recursive_rollup(name: name,
interval_previous: previous,
interval: current,
dimensions: dimensions,
beginning: beginning)
# Devolver el intervalo actual
current
end
nil
end
def stat_name
STAT_NAME
end

View file

@ -6,8 +6,8 @@
%p
%small
= t('.last_update')
%time{ datetime: @last_stat.created_at }
#{time_ago_in_words @last_stat.created_at}.
%time{ datetime: @last_stat.updated_at }
#{time_ago_in_words @last_stat.updated_at}.
.mb-5
- Stat::INTERVALS.each do |interval|