Class: Activecube::Processor::Optimizer
- Inherits:
-
Object
- Object
- Activecube::Processor::Optimizer
- Defined in:
- lib/activecube/processor/optimizer.rb
Constant Summary collapse
- UNLIM_COST =
9999
- MAX_ITERATIONS =
3
Instance Attribute Summary collapse
-
#cost_matrix ⇒ Object
readonly
Returns the value of attribute cost_matrix.
-
#metrics_count ⇒ Object
readonly
Returns the value of attribute metrics_count.
-
#tables_count ⇒ Object
readonly
Returns the value of attribute tables_count.
Instance Method Summary collapse
-
#initialize(cost_matrix) ⇒ Optimizer
constructor
A new instance of Optimizer.
- #optimize ⇒ Object
Constructor Details
#initialize(cost_matrix) ⇒ Optimizer
Returns a new instance of Optimizer.
9 10 11 12 |
# File 'lib/activecube/processor/optimizer.rb', line 9 def initialize cost_matrix @cost_matrix = cost_matrix @cache = ActiveSupport::Cache::MemoryStore.new end |
Instance Attribute Details
#cost_matrix ⇒ Object (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_count ⇒ Object (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_count ⇒ Object (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
#optimize ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/activecube/processor/optimizer.rb', line 14 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 ? [0]*metrics_count : do_optimize end end |