def aggregate(self, data, sensordescription): """ this method is called when stream data has been annotated. :param data: :param sensordescription: :return: The aggregated data """ if not data.fields: return None result = [] try: aggregation_objs = self.aggregation_objs[sensordescription.uuid] for key, agg in aggregation_objs.items(): agg_result = agg.control(data[key]) if agg_result: g, start, end, size = agg_result r = JSONObject() r.graph = g r.field = sensordescription.field[key] r.sensorID = sensordescription.sensorID r.propertyName = sensordescription.field[key].propertyName r.category = sensordescription.sensorType r.aggregationMethod = sensordescription.field[key].aggregationMethod r.aggregationConfiguration = sensordescription.field[key].aggregationConfiguration r.start = start r.end = end r.size = size result.append(r) return result except Exception as e: Log.e("aggregation failed due to Exception", e) return None