Class: PlantWatchdog::Aggregation::Device
- Inherits:
-
Object
- Object
- PlantWatchdog::Aggregation::Device
- Includes:
- RuleEvaluation
- Defined in:
- lib/plantwatchdog/aggregation.rb
Instance Attribute Summary collapse
-
#model_device ⇒ Object
Returns the value of attribute model_device.
Class Method Summary collapse
Instance Method Summary collapse
-
#aggregate ⇒ Object
execute the aggregation rules of the device.
-
#aggregates ⇒ Object
return the dict with aggregated values.
-
#initialize(model_device, data) ⇒ Device
constructor
A new instance of Device.
-
#logger ⇒ Object
TODO: better way to access logger.
- #measurements ⇒ Object
- #meta ⇒ Object
-
#not_understand ⇒ Object
generic access to the fields of the underlying model_device.
- #persist ⇒ Object
Methods included from RuleEvaluation
Constructor Details
#initialize(model_device, data) ⇒ Device
Returns a new instance of Device.
73 74 75 76 77 |
# File 'lib/plantwatchdog/aggregation.rb', line 73 def initialize(model_device, data) @model_device = model_device @aggregates = {} @data = data end |
Instance Attribute Details
#model_device ⇒ Object
Returns the value of attribute model_device.
71 72 73 |
# File 'lib/plantwatchdog/aggregation.rb', line 71 def model_device @model_device end |
Class Method Details
.create(model_device, year, day) ⇒ Object
66 67 68 69 70 |
# File 'lib/plantwatchdog/aggregation.rb', line 66 def Device.create(model_device, year, day) # select data data = Model::MeasurementChunk.find(:first, :conditions => ["device_id=? and time_year=? and time_day_of_year=?", model_device.id, year, day]) Device.new(model_device, data) end |
Instance Method Details
#aggregate ⇒ Object
execute the aggregation rules of the device
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/plantwatchdog/aggregation.rb', line 98 def aggregate result = {} logger.debug "Aggregating device #{model_device.id}, aggrules: #{model_device.aggrules}" model_device.aggrules.each_pair do |agg_key, rule_array| result[agg_key] = eval_rule(rule_array, measurements) end logger.debug "Aggregation results: " + result.to_s result end |
#aggregates ⇒ Object
return the dict with aggregated values
93 94 95 |
# File 'lib/plantwatchdog/aggregation.rb', line 93 def aggregates end |
#logger ⇒ Object
TODO: better way to access logger
116 117 118 |
# File 'lib/plantwatchdog/aggregation.rb', line 116 def logger return ActiveRecord::Base.logger end |
#measurements ⇒ Object
84 85 86 |
# File 'lib/plantwatchdog/aggregation.rb', line 84 def measurements @data ? @data.measurements : [] end |
#meta ⇒ Object
88 89 90 |
# File 'lib/plantwatchdog/aggregation.rb', line 88 def model_device. end |
#not_understand ⇒ Object
generic access to the fields of the underlying model_device
80 81 82 |
# File 'lib/plantwatchdog/aggregation.rb', line 80 def not_understand # model_device end |
#persist ⇒ Object
109 110 111 112 113 |
# File 'lib/plantwatchdog/aggregation.rb', line 109 def persist dm = Model::DailyMeasurement.new() dm.description = JSON(aggregates) return dm end |