def post_pb(self, client_id_str=None): """ return nothing to the client when receiving a heartbeat heart beat status { type: SUCCESS } data_requests { sensor_id: 0 provide_current_data: true } latest_request_id: 0 """ current_time = util.system_time() data_request = self.response_pb.data_requests.add() data_request.sensor_id = 0 data_request.provide_current_data = True self.response_pb.latest_request_id = 0 self.write_response() print('\n\nHeartBeatHandler request'); print(self.request_pb) print('\n\nHeartBeatHandler response'); print(self.response_pb)
def post_pb(self, client_id_str=None): """ Process event submitted by client. Parameters ---------- client_id_str : string String version of the client submitting the sensor's data. Notes ----- Logging of event data is done for future recoverability, but could be avoided by a number of strategies. One would be to encode more of the data in the submission URL. An example path might be:: /api/v1/event/client_id/sensor_id/1.2_2.3_3.4 Where the final path component is a _ delimited list of sensor reading(s) that triggered the event report. This has the advantage of mitigating the need for logging events but requires a more cumbersome url structure and data decoding process. """ #TODO: make this not so hacky global _raw_event_queue current_time = util.system_time() if self.request_pb.event.HasField('date'): event_date_str = self.request_pb.event.date else: event_date_str = self.request_pb.client_signature.date if self.request_pb.HasField('latitude'): event_location = (self.request_pb.latitude, self.request_pb.longitude) else: event_location = 'nul' event_date = util.parse_date(event_date_str) time_delta = round((current_time - event_date).total_seconds(), 3) time_delta_str = (str(time_delta) if abs(time_delta) < DISPLAY_TIME_AS_DELTA_THRESHOLD else api_handler.date_format(current_time)) readings_str = [ str(round(reading, 6)) for reading in self.request_pb.event.readings ] logging.info('EventT%s: %s -> %s at %s(%s)', self.request_pb.event.sensor_type, self.request_pb.event.sensor_id, readings_str, event_date_str, time_delta_str) self.write_response() """ self.request_pb.event instance holds the following data: sensor_id: 0 sensor_type: ACCELEROMETER_3_AXIS readings: 0.0 readings: 0.0 readings: 1.05895996094 date: "2014-04-13T19:36:43.205" event_count: 117 time_window: 600 self.request_pb.client_signature instance holds the following data: date: "2014-04-13T19:42:17.744" message_id: 678 signature: "f48d348f0862a281df95f3ef64ec2381f02818fb98a8b2df64b088ad5ba034fa" """ logging.info('Event data %s', self.request_pb) print(self.request_pb) print(SCALE_VS_MAGIC_LN) # _raw_event_queue.put(self.request_pb) sys.stdout.flush()
def post_pb(self, client_id_str=None): """ Process event submitted by client. Parameters ---------- client_id_str : string String version of the client submitting the sensor's data. Notes ----- Logging of event data is done for future recoverability, but could be avoided by a number of strategies. One would be to encode more of the data in the submission URL. An example path might be:: /api/v1/event/client_id/sensor_id/1.2_2.3_3.4 Where the final path component is a _ delimited list of sensor reading(s) that triggered the event report. This has the advantage of mitigating the need for logging events but requires a more cumbersome url structure and data decoding process. """ #TODO: make this not so hacky global _raw_event_queue current_time = util.system_time() if self.request_pb.event.HasField('date'): event_date_str = self.request_pb.event.date else: event_date_str = self.request_pb.client_signature.date if self.request_pb.HasField('latitude'): event_location = (self.request_pb.latitude, self.request_pb.longitude) else: event_location = 'nul' event_date = util.parse_date(event_date_str) time_delta = round((current_time - event_date).total_seconds(), 3) time_delta_str = (str(time_delta) if abs(time_delta) < DISPLAY_TIME_AS_DELTA_THRESHOLD else api_handler.date_format(current_time)) readings_str = [str(round(reading, 6)) for reading in self.request_pb.event.readings] logging.info('EventT%s: %s -> %s at %s(%s)', self.request_pb.event.sensor_type, self.request_pb.event.sensor_id, readings_str, event_date_str, time_delta_str) self.write_response() """ self.request_pb.event instance holds the following data: sensor_id: 0 sensor_type: ACCELEROMETER_3_AXIS readings: 0.0 readings: 0.0 readings: 1.05895996094 date: "2014-04-13T19:36:43.205" event_count: 117 time_window: 600 self.request_pb.client_signature instance holds the following data: date: "2014-04-13T19:42:17.744" message_id: 678 signature: "f48d348f0862a281df95f3ef64ec2381f02818fb98a8b2df64b088ad5ba034fa" """ logging.info('Event data %s', self.request_pb) print (self.request_pb) print (SCALE_VS_MAGIC_LN) # _raw_event_queue.put(self.request_pb) sys.stdout.flush()