lib/cs/collection/sensor_data_collection.rb
##
# Given array of sensor data it will group the data by sensor_id
# and construct payload for multiple sensor upload
Given array of sensor data it will group the data by sensor_id
and construct payload for multiple sensor upload
Given array of sensor data it will group the data by sensor_id and construct payload for multiple sensor upload
def process_batch(batch)
        sensors = {}
        batch.each do |point|
          next if point.nil? || point.sensor_id.nil?
          sensor_id = point.sensor_id
          if !sensors[sensor_id]
            sensors[sensor_id] = {
              sensor_id: sensor_id,
              data: []
            }
          end
          sensors[sensor_id][:data].push(point.to_cs_value)
        end
        retval = []
        sensors.each do |k, v|
          retval.push(v)
        end
        {sensors: retval}
      end
def process_batch ( batch ) sensors = { } batch . each do | point | next if point . nil? || point . sensor_id . nil? sensor_id = point . sensor_id if ! sensors [ sensor_id ] sensors [ sensor_id ] = { sensor_id : sensor_id , data : [ ] } end sensors [ sensor_id ] [ :data ] . push ( point . to_cs_value ) end retval = [ ] sensors . each do | k , v | retval . push ( v ) end { sensors : retval } end
Given array of sensor data it will group the data by sensor_id
and construct payload for multiple sensor upload
Given array of sensor data it will group the data by sensor_id and construct payload for multiple sensor upload
batch
<not_specific>