Class: PlantWatchdog::Aggregation::Plant

Inherits:
Object
  • Object
show all
Includes:
RuleEvaluation
Defined in:
lib/plantwatchdog/aggregation.rb

Instance Method Summary collapse

Methods included from RuleEvaluation

#eval_rule

Constructor Details

#initialize(model_plant, device_aggregates) ⇒ Plant

Returns a new instance of Plant.



123
124
125
126
# File 'lib/plantwatchdog/aggregation.rb', line 123

def initialize model_plant, device_aggregates
  @model_plant = model_plant
  @device_aggregates = device_aggregates
end

Instance Method Details

#aggregateObject



128
129
130
131
132
133
134
135
136
137
# File 'lib/plantwatchdog/aggregation.rb', line 128

def aggregate
  result = {}
  logger.debug "Aggregating plant, aggrules: #{@model_plant.aggrules}"
  @model_plant.aggrules.each_pair do
    |agg_key, rule_array|
    result[agg_key] = eval_rule(rule_array,  @device_aggregates)
  end
  logger.debug "Aggregation results: " + result.to_s
  result
end

#loggerObject

TODO: better way to access logger



140
141
142
# File 'lib/plantwatchdog/aggregation.rb', line 140

def logger
  return ActiveRecord::Base.logger
end