mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-28 04:46:21 +00:00
Merge branch 'blazer' into panel.sutty.nl
This commit is contained in:
commit
4a436ee03d
2 changed files with 33 additions and 16 deletions
|
@ -15,14 +15,33 @@ module RecursiveRollup
|
||||||
# @param :interval [String]
|
# @param :interval [String]
|
||||||
# @param :operation [Symbol]
|
# @param :operation [Symbol]
|
||||||
# @param :dimensions [Hash]
|
# @param :dimensions [Hash]
|
||||||
# @param :new_name [String]
|
|
||||||
# @param :beginning [Time]
|
# @param :beginning [Time]
|
||||||
# @return [Rollup]
|
# @return [Rollup]
|
||||||
def recursive_rollup(name:, interval_previous:, interval:, dimensions:, beginning:, operation: :sum, new_name: nil)
|
def recursive_rollup(name:, interval_previous:, interval:, dimensions:, beginning:, operation: :sum)
|
||||||
Rollup.where(name: name, interval: interval_previous, dimensions: dimensions.to_json)
|
Rollup.where(name: name, interval: interval_previous, dimensions: dimensions)
|
||||||
.where('time >= ?', beginning.try(:"beginning_of_#{interval}"))
|
.where('time >= ?', beginning.try(:"beginning_of_#{interval}"))
|
||||||
.group(*dimensions_to_jsonb_query(dimensions))
|
.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)
|
rollup.try(operation, :value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -62,9 +62,8 @@ class UriCollectionJob < PeriodicJob
|
||||||
end
|
end
|
||||||
|
|
||||||
# Reducir todas las visitas a cantidad de visitas por host
|
# Reducir todas las visitas a cantidad de visitas por host
|
||||||
recursive_rollup(name: 'host|uri',
|
square_rollup(name: 'host|uri',
|
||||||
new_name: 'host',
|
new_name: 'host',
|
||||||
interval_previous: starting_interval,
|
|
||||||
interval: starting_interval,
|
interval: starting_interval,
|
||||||
dimensions: host_dimensions,
|
dimensions: host_dimensions,
|
||||||
beginning: beginning)
|
beginning: beginning)
|
||||||
|
@ -73,9 +72,8 @@ class UriCollectionJob < PeriodicJob
|
||||||
reduce_rollup('host', beginning, **host_dimensions)
|
reduce_rollup('host', beginning, **host_dimensions)
|
||||||
|
|
||||||
columns.each do |column|
|
columns.each do |column|
|
||||||
recursive_rollup(name: "host|uri|#{column}",
|
square_rollup(name: "host|uri|#{column}",
|
||||||
new_name: "host|#{column}",
|
new_name: "host|#{column}",
|
||||||
interval_previous: starting_interval,
|
|
||||||
interval: starting_interval,
|
interval: starting_interval,
|
||||||
dimensions: host_dimensions,
|
dimensions: host_dimensions,
|
||||||
beginning: beginning)
|
beginning: beginning)
|
||||||
|
|
Loading…
Reference in a new issue