5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-28 00:26:22 +00:00

Merge branch 'blazer' into panel.sutty.nl

This commit is contained in:
f 2022-04-30 09:58:10 -03:00
commit 4a436ee03d
2 changed files with 33 additions and 16 deletions

View file

@ -15,14 +15,33 @@ module RecursiveRollup
# @param :interval [String]
# @param :operation [Symbol]
# @param :dimensions [Hash]
# @param :new_name [String]
# @param :beginning [Time]
# @return [Rollup]
def recursive_rollup(name:, interval_previous:, interval:, dimensions:, beginning:, operation: :sum, new_name: nil)
Rollup.where(name: name, interval: interval_previous, dimensions: dimensions.to_json)
def recursive_rollup(name:, interval_previous:, interval:, dimensions:, beginning:, operation: :sum)
Rollup.where(name: name, interval: interval_previous, dimensions: dimensions)
.where('time >= ?', beginning.try(:"beginning_of_#{interval}"))
.group(*dimensions_to_jsonb_query(dimensions))
.rollup(new_name || name, interval: interval, update: true) do |rollup|
.rollup(name, interval: interval, update: true) do |rollup|
rollup.try(operation, :value)
end
end
# Genera un nuevo rollup a partir de uno anterior.
#
# @param :name [String]
# @param :new_name [String]
# @param :interval_previous [String]
# @param :interval [String]
# @param :operation [Symbol]
# @param :dimensions [Hash]
# @param :beginning [Time]
# @return [Rollup]
def square_rollup(name:, new_name:, interval:, dimensions:, beginning:, operation: :sum)
Rollup.where(name: name, interval: interval_previous)
.where_dimensions(**dimensions)
.where('time >= ?', beginning.try(:"beginning_of_#{interval}"))
.group(*dimensions_to_jsonb_query(dimensions))
.rollup(new_name, interval: interval, update: true) do |rollup|
rollup.try(operation, :value)
end
end

View file

@ -62,23 +62,21 @@ class UriCollectionJob < PeriodicJob
end
# Reducir todas las visitas a cantidad de visitas por host
recursive_rollup(name: 'host|uri',
new_name: 'host',
interval_previous: starting_interval,
interval: starting_interval,
dimensions: host_dimensions,
beginning: beginning)
square_rollup(name: 'host|uri',
new_name: 'host',
interval: starting_interval,
dimensions: host_dimensions,
beginning: beginning)
# Acumular por mes y año
reduce_rollup('host', beginning, **host_dimensions)
columns.each do |column|
recursive_rollup(name: "host|uri|#{column}",
new_name: "host|#{column}",
interval_previous: starting_interval,
interval: starting_interval,
dimensions: host_dimensions,
beginning: beginning)
square_rollup(name: "host|uri|#{column}",
new_name: "host|#{column}",
interval: starting_interval,
dimensions: host_dimensions,
beginning: beginning)
reduce_rollup("host|#{column}", beginning, **host_dimensions)
end