def newMessageData(tag_info): # 图层 emapArr = ['egms_map' , 'egms_461253' , 'egms_090836' ]; mqMessageData = {}; mqMessageData['cls'] = "tag" mqMessageData['id'] = tag_info['i_id']; # 随机获取图层 layer_name = RandomUtils.getRamdonByArr(emapArr); mqMessageData['layer_name'] = layer_name mqMessageData['time'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') mqMessageData['key'] = "coordinate" # 随机坐标 x = RandomUtils.getRandomBetweenNumbers( 0 , 200 ); y = RandomUtils.getRandomBetweenNumbers( -120 , 0 ); mqMessageData['val'] = str(x) + "," + str(y); # key = RandomUtils.getRandomBetweenNumbers(0 , 10); # if key == 1 : # mqMessageData['key'] = "online" # mqMessageData['val'] = "0" # 自定义人数 # personArr = [ 131 ,601 , 378 , 420 , 592] # mqMessageData['id'] = RandomUtils.getRamdonByArr(personArr); # mqMessageData['id'] = 300; # 321 130 128 300 601 # mqMessageData['layer_name'] = 'egms_110' # 直接定义图层 # mqMessageData['layer_name'] = 'egms_090836' # mqMessageData['key'] = "online" # mqMessageData['val'] = "0" # mqMessageData['key'] = "coordinate" # mqMessageData['val'] = str(328) + "," + str(10); return mqMessageData;
def newMessageData(tag_info): emapArr = ['egms_map', 'egms_461253', 'egms_090836'] mqMessageData = {} mqMessageData['cls'] = "tag" mqMessageData['id'] = tag_info['i_id'] layer_name = RandomUtils.getRamdonByArr(emapArr) mqMessageData['layer_name'] = layer_name time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') print('time : ', time) mqMessageData['time'] = time # mqMessageData['time'] = '2017-08-18 20:40:29' mqMessageData['key'] = "coordinate" x = RandomUtils.getRandomBetweenNumbers(0, 200) y = RandomUtils.getRandomBetweenNumbers(-150, 0) mqMessageData['val'] = str(x) + "," + str(y) # key = RandomUtils.getRandomBetweenNumbers(0 , 10); # if key == 1 : # mqMessageData['key'] = "online" # mqMessageData['val'] = "0" # personArr = [ 131 ,601 , 378 , 420 , 592] # mqMessageData['id'] = RandomUtils.getRamdonByArr(personArr); # mqMessageData['id'] = 500; # 321 130 128 300 601 # mqMessageData['id'] = 321; # 321 130 128 300 601 mqMessageData['id'] = 503 # 321 130 128 300 601 # mqMessageData['id'] = 368; # 321 130 128 300 601 # mqMessageData['id'] = 365; # 321 130 128 300 601 # mqMessageData['id'] = 558; # 321 130 128 300 601 # mqMessageData['id'] = 59; # 321 130 128 300 601 # mqMessageData['id'] = 25; # 321 130 128 300 601 # mqMessageData['id'] = 476; # 321 130 128 300 601 # mqMessageData['id'] = 106; # 321 130 128 300 601 # mqMessageData['id'] = 152; # 321 130 128 300 601 # mqMessageData['id'] = 417; # 321 130 128 300 601 mqMessageData['layer_name'] = 'egms_458647' # mqMessageData['layer_name'] = 'egms_297556' print(' layer_name : ', layer_name) mqMessageData['key'] = "online" mqMessageData['val'] = "0" # mqMessageData['key'] = "power" # mqMessageData['val'] = RandomUtils.getRandomBetweenNumbers( 20 , 80 ); # mqMessageData['key'] = "coordinate" # mqMessageData['val'] = str(328) + "," + str(-50); mqMessageData['anchorid'] = "1,2,3" return mqMessageData
def newPowerMessageData(tag_info): mqMessageData = {} mqMessageData['cls'] = "tag" # mqMessageData['id'] = tag_info['i_id']; mqMessageData['id'] = 592 # 321 personArr = [131, 601, 378, 420, 592] mqMessageData['id'] = RandomUtils.getRamdonByArr(personArr) mqMessageData['layer_name'] = "egms_110" mqMessageData['time'] = datetime.datetime.now().strftime( '%Y-%m-%d %H:%M:%S') mqMessageData['key'] = "power" mqMessageData['val'] = RandomUtils.getRandomBetweenNumbers(20, 80) return mqMessageData
def sendLocationData(tagid): print('发送上线消息') levelName = RandomUtils.getRamdonByArr(emapList) mqMessageData = {} mqMessageData['cls'] = "tag" mqMessageData['id'] = tagid mqMessageData['time'] = datetime.datetime.now().strftime( '%Y-%m-%d %H:%M:%S') mqMessageData['key'] = "coordinate" x = RandomUtils.getRandomBetweenNumbers(100, 40000) y = RandomUtils.getRandomBetweenNumbers(-20000, -100) mqMessageData['val'] = str(x) + "," + str(y) mqMessageData['layer_name'] = levelName mqMessageData['anchorid'] = '1111,1131' message = str(mqMessageData) print('message : ', message) conn.sendTopic(message, 'testtopic') return mqMessageData
def newSinglePersonMessageData(tag_info): emapArr = ['egms_map', 'egms_461253', 'egms_090836'] mqMessageData = {} mqMessageData['cls'] = "tag" mqMessageData['id'] = tag_info['i_id'] layer_name = RandomUtils.getRamdonByArr(emapArr) mqMessageData['layer_name'] = layer_name mqMessageData['time'] = datetime.datetime.now().strftime( '%Y-%m-%d %H:%M:%S') mqMessageData['key'] = "coordinate" x = RandomUtils.getRandomBetweenNumbers(0, 200) y = RandomUtils.getRandomBetweenNumbers(-120, 0) mqMessageData['val'] = str(x) + "," + str(y) key = RandomUtils.getRandomBetweenNumbers(0, 10) # if key == 1 : # mqMessageData['key'] = "online" # mqMessageData['val'] = "0" mqMessageData['id'] = 1 # 321 130 128 300 601 # mqMessageData['layer_name'] = 'egms_090836' mqMessageData['layer_name'] = 'egms_270291' # print(' layer_name : ' , layer_name) # mqMessageData['time'] = '2017-08-02 11:31:13' # mqMessageData['time'] = '2017-08-02 11:33:05' # mqMessageData['key'] = "online" # mqMessageData['val'] = "0" # mqMessageData['key'] = "power" # mqMessageData['val'] = 50; # mqMessageData['key'] = "sos" # mqMessageData['val'] = 1 # mqMessageData['key'] = "coordinate" # mqMessageData['val'] = str(328) + "," + str(-30); return mqMessageData
def createNewMessage(count): allMsg = ''; for i in range(count) : # 数据库查询 tag_info = PG_Client.query('select i_id from tag_info ORDER BY RANDOM() LIMIT 1 ', None); print(' rows : ', tag_info); # 获取当前时间戳 dtime = datetime.datetime.now() ans_time = int(time.mktime(dtime.timetuple())) * 1000; id = tag_info['i_id']; # id = 1111; # 图层 emapArr = ['egms_369857' , 'egms_130738']; layer_name = RandomUtils.getRamdonByArr(emapArr); key = "coordinate" # 随机坐标 x = RandomUtils.getRandomBetweenNumbers(0, 61); y = RandomUtils.getRandomBetweenNumbers(-46, 0); val = str(x) + "," + str(y); msg = '{"cls":"tag","id":%(id)d,"layer_name":"%(layer_name)s","time":%(time)d,"key":"%(key)s","val":"%(val)s"}\n'; msg = msg % { 'id' : id , 'layer_name' : layer_name , 'time' : ans_time , 'key' : key , 'val' : val } allMsg += msg; print(' msg : ' , allMsg) with open('E:\projects\五系统一中心\mq_test\Win32\Win32\\001', 'w+') as f: f.write(allMsg)
def sendOnlineMessage(tagid): print('发送上线消息') levelName = RandomUtils.getRamdonByArr(emapList) mqMessageData = {} mqMessageData['cls'] = "tag" mqMessageData['id'] = tagid mqMessageData['time'] = datetime.datetime.now().strftime( '%Y-%m-%d %H:%M:%S') mqMessageData['key'] = "coordinate" mqMessageData['val'] = str(10) + "," + str(-10) mqMessageData['layer_name'] = 'egms_532733' mqMessageData['anchorid'] = '1,3' message = str(mqMessageData) print('message : ', message) conn.sendTopic(message, 'testtopic') return mqMessageData
def testHash(): for i in range(0, 3000): mStr = RandomUtils.getRandomStr(datasize) print(' str : ', mStr) rs_client.redisClient.hset("delMap", str(i), mStr)
def testList(): key = 'testKey_:_list' for i in range(0, 30000): mStr = RandomUtils.getRandomStr(1024) # print(' str : ' , mStr); rs_client.redisClient.lpush(key, mStr)
def testString(): for i in range(0, 300000): mStr = RandomUtils.getRandomStr(1024 * 100) key = 'testKey_:_' + str(i) # print(' str : ' , mStr); rs_client.redisClient.set(key, mStr)