Class: Activecube::Processor::Optimizer

Inherits:
Object
  • Object
show all
Defined in:
lib/activecube/processor/optimizer.rb

Constant Summary collapse

UNLIM_COST =
9999
MAX_ITERATIONS =
3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cost_matrix) ⇒ Optimizer

Returns a new instance of Optimizer.



10
11
12
13
# File 'lib/activecube/processor/optimizer.rb', line 10

def initialize cost_matrix
  @cost_matrix = cost_matrix
  @cache = ActiveSupport::Cache::MemoryStore.new
end

Instance Attribute Details

#cost_matrixObject (readonly)

Returns the value of attribute cost_matrix.



8
9
10
# File 'lib/activecube/processor/optimizer.rb', line 8

def cost_matrix
  @cost_matrix
end

#metrics_countObject (readonly)

Returns the value of attribute metrics_count.



8
9
10
# File 'lib/activecube/processor/optimizer.rb', line 8

def metrics_count
  @metrics_count
end

#tables_countObject (readonly)

Returns the value of attribute tables_count.



8
9
10
# File 'lib/activecube/processor/optimizer.rb', line 8

def tables_count
  @tables_count
end

Instance Method Details

#optimizeObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/activecube/processor/optimizer.rb', line 15

def optimize

  @cache.fetch(cost_matrix, expires_in: 12.hours) do

    @tables_count = cost_matrix.map(&:count).max
    @metrics_count = cost_matrix.count

    (tables_count == 1 || metrics_count == 0) ? [0] * metrics_count : do_optimize

  end

end