def video_feed(): #print(reader_dict) topic_path = "persistent://" + request.args['tenant'] + '/' + request.args['namespace'] + '/' + request.args['topic'] #print(topic_path) if(request.args['namespace'] == 'raw-video'): topic_frame = Frame elif(request.args['namespace'] == 'processed-video'): topic_frame = YOLOFrame elif(request.args['namespace'] == 'text'): topic_frame = TextFrame if(request.args['cursor'] == 'latest'): topic_cursor = MessageId.latest elif(request.args['cursor'] == 'earliest'): topic_cursor = MessageId.earliest else: print(request.args['cursor']) #result = influx_client.query("SELECT * FROM amount_of_people WHERE time >= '{}' LIMIT 1".format(request.args['cursor'])) #print(result) #result = list(result)[0][0] #print(result) #cursor_string = result['cursor'] #print(result['time']) #print(cursor_string) #print(bytes.fromhex(cursor_string)) #print(MessageId.deserialize(bytes.fromhex(cursor_string))) topic_cursor = MessageId.deserialize(bytes.fromhex(request.args['cursor'])) #print(topic_cursor) reader = None username = request.args['username'] if(username in reader_dict.keys() and reader_dict[username]['topic']==topic_path and reader_dict[username]['cursor_name']==request.args['cursor']): #print("reader {} {}".format(reader_dict[username]['cursor_name'],reader_dict[username]['topic'])) reader = reader_dict[username]['reader'] else: print("create reader {} {} {}".format(request.args['cursor'],request.args['namespace'],request.args['topic'])) if(reader): reader.close() print("close reader") del reader_dict[username] time.sleep(10) reader_obj = {} reader_obj['topic'] = topic_path reader_obj['cursor_name'] = request.args['cursor'] reader_obj['cursor'] = topic_cursor reader = client.create_reader(topic=topic_path, start_message_id=topic_cursor, receiver_queue_size=5000, schema=AvroSchema(topic_frame) ) reader_obj['reader'] = reader reader_dict[username] = reader_obj return get_video_stream(username,request.args['namespace'])
def test_message_id(self): s = MessageId.earliest.serialize() self.assertEqual(MessageId.deserialize(s), MessageId.earliest) s = MessageId.latest.serialize() self.assertEqual(MessageId.deserialize(s), MessageId.latest)