mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 12:51:42 +00:00
no se puede renombrar un rollup usando dimensiones exactas
además era un método que hacía dos cosas distintas según un parámetro
This commit is contained in:
parent
595a8759a4
commit
121d4f49e2
2 changed files with 33 additions and 16 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue