Module: PlantWatchdog::Aggregation::RuleEvaluation

Included in:
Device, Plant
Defined in:
lib/plantwatchdog/aggregation.rb

Instance Method Summary collapse

Instance Method Details

#eval_rule(rule_array, data) ⇒ Object

data is an array of dictionaries, e.g. retrieved via Measurements.from_csv



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/plantwatchdog/aggregation.rb', line 47

def eval_rule rule_array, data
  return 0 if rule_array.empty?
  method_name = rule_array.first
  arg_desc = rule_array[1, rule_array.size] # the column names for which we need to create time series
  args = arg_desc.collect { |arg_desc|
    if arg_desc.is_a? Numeric then
      arg_desc
    elsif arg_desc.is_a? Array
      eval_rule(arg_desc, data)
    else
      data.collect { |d| d[arg_desc] }
    end
  }
  return Methods.call(method_name, *args)
end