def on_push_location_request(self, request): redis_data_key = str(request['device_id'])+'-location' for ts, data in request['package'].items(): data_t = get_location_to_save(request, ts, data) producer.set_redis(data_t, redis_data_key) producer.insert_into_redis(data_t, REDIS_LOC_KEY) self.stream.write(str.encode(get_reply_json(self.json_request)), callback = stack_context.wrap(self.wait_new_request))
def on_push_data_request(self, request): # add the redis part redis_data_key = str(request['device_id'])+'-data' for ts, data in request['package'].items(): data_t = get_data_to_save(request, ts, data) logging.info(data_t) producer.set_redis(data_t, redis_data_key) producer.insert_into_redis(data_t, REDIS_LIST_KEY) self.stream.write(str.encode(get_reply_json(self.json_request)), callback = stack_context.wrap(self.wait_new_request))
async def on_image_upload_complete(self, data): try: filepath = check_device_img_file(self.json_request['device_id']) url = get_image_url_local(filepath, self.json_request['ts']) save_image_local(data, url) self.json_request['image_info'] = { self.json_request['key']: { 'value': url } } tmp_data = get_image_info_to_save(self.json_request) producer.set_redis(tmp_data, str(self.json_request['device_id']) + '-image') if producer.insert_into_redis(tmp_data, REDIS_LIST_KEY): response = get_reply_string(self.json_request) if isinstance(response, str): response = response.encode('utf-8') print("<<<<<< SEND", response, sep='\n') await self.stream.write(response) self.close() else: await self.on_error_request() except Exception as e: logging.info(e) await self.on_error_request() raise e
async def on_push_data_request(self, request): try: if self.validate_push_data_request(request): # add the redis part device_id = int(request['device_id']) redis_data_key = f"{device_id}-data" for ts, data in request['package'].items(): data_t = get_data_to_save(request, ts, data) logging.info(data_t) producer.set_redis(data_t, redis_data_key) producer.insert_into_redis(data_t, REDIS_LIST_KEY) reply = get_reply_json(self.json_request) if isinstance(reply, str): reply = reply.encode("utf-8") print("<<<<<< SEND", reply, sep='\n') await self.stream.write(reply) self.close() else: await self.on_error_request() except: traceback.print_exc() await self.on_error_request()
def on_image_upload_complete(self, data): logging.info('here in on_image_upload_complete') try: filepath = check_device_img_file(self.json_request['device_id']) url = get_image_url_local(filepath, self.json_request['ts']) # url = get_image_url_local(filepath, self.json_request['acquisition_time']) save_image_local(data, url) self.json_request['image_info'] = {self.json_request['key']:{'value':url}} tmp_data = get_image_info_to_save(self.json_request) producer.set_redis(tmp_data,str(self.json_request['device_id'])+'-image') if producer.insert_into_redis(tmp_data, REDIS_LIST_KEY): self.stream.write(str.encode(get_reply_string(self.json_request)), callback=stack_context.wrap(self.wait_new_request)) else: self.on_error_request() except Exception as e: logging.info(e) self.on_error_request() raise e