def load_real_data(): DataCommand = ice_con() pIDs = [] ycdata = [] for i in range(5): pIDs.append(i) structycdata = YCArea.DxDTYC(i, i + 1.1, i) ycdata.append(structycdata) print("........开始写入遥测数据.......") start = time.time() # 写入redis DataCommand.RPCSetRealtimeYCData(pIDs, ycdata) writeElapsed = time.time() - start print("write time use: %s " % writeElapsed) print("........开始读取遥测最新数据.......") start = time.time() ycstatus, ycdata = DataCommand.RPCGetRealtimeYCData(pIDs) readElapsed = time.time() - start print("read time use: %s " % readElapsed) # print(ycstatus) ycdatanum = len(ycdata) # print("总计读取遥测数据:%d " % ycdatanum) data0 = [writeElapsed, readElapsed, ycdatanum] data1 = [] for i in range(len(ycdata)): data1.append({'status': ycdata[i].status, 'value': ycdata[i].value, 'timetag': ycdata[i].timetag}) data = [data0, data1] return data
def hello(): status = 0 ic = None try: ic = Ice.initialize(sys.argv) base = ic.stringToProxy( "DataCommand:default -h 192.168.100.170 -p 10000") DataCommand = CommandArea.DataCommandPrx.checkedCast(base) if not DataCommand: raise RuntimeError("Invalid proxy") pIDs = [] pIDs.append(0) ycdata = [] for i in range(1000): structycdata = YCArea.DxDTYC(i, i + 1.1, i) ycdata.append(structycdata) # 写入redis #DataCommand.RPCSetRealtimeYCData (pIDs, ycdata) # 写入cassandra DataCommand.RPCSaveYCData(pIDs, ycdata) DataCommand.RPCGetRealtimeYCData(pIDs) ycdata.pop() pID = 0 datetime = "20190520" print("........开始获取遥测当天数据.......") start = time.time() ycstatus, ycdata = DataCommand.RPCGetDayYCData(datetime, pID) elapsed = (time.time() - start) print("time use: %s " % elapsed) print(ycstatus) print("总计读取遥测数据:%d " % len(ycdata)) """ for i in range(len(ycdata)): print(ycdata[i].status, ycdata[i].value, ycdata[i].timetag) """ #return "读取单点某天全部数据需要时间:" + str(elapsed) + "<br><br>" + "总共读取遥测数据:" + str(len(ycdata)) + "<br><br>" + "读取的遥测数据如下:" + "<br><br>" + str(ycdata) return render_template('ycdaydata_js.html', elapsed=elapsed, ycdatanum=len(ycdata), ycdataval=ycdata) except: traceback.print_exc() status = 1 if ic: try: ic.destroy() except: traceback.print_exc() status = 1 sys.exit(status)
def write_data(threadName): for i in range(2, 5): structycdata = YCArea.DxDTYC(i, i + 1.1, i) ycdata.append(structycdata) DataCommand.RPCSetRealtimeYCData(pIDs, ycdata) #DataCommand.RPCGetRealtimeYCData(pIDs) ycdata.pop() #DataCommand.RPCSetRealtimeYCData (pIDs, ycdata) print("%s执行了写数据" % threadName)
def background_thread(): # print("线程启动!") while True: socketio.sleep(2) ic = None ic = Ice.initialize(sys.argv) base = ic.stringToProxy( "DataCommand:default -h 192.168.100.170 -p 10000") DataCommand = CommandArea.DataCommandPrx.checkedCast(base) if not DataCommand: raise RuntimeError("Invalid proxy") pIDs = [] pIDs.append(0) ycdata = [] for i in range(1000): structycdata = YCArea.DxDTYC(i, i + 1.1, i) ycdata.append(structycdata) # 写入redis # DataCommand.RPCSetRealtimeYCData (pIDs, ycdata) # 写入cassandra DataCommand.RPCSaveYCData(pIDs, ycdata) DataCommand.RPCGetRealtimeYCData(pIDs) ycdata.pop() pID = 0 datetime = "20190524" print("........开始获取遥测当天数据.......") start = time.time() ycstatus, ycdata = DataCommand.RPCGetDayYCData(datetime, pID) elapsed = time.time() - start print("time use: %s " % elapsed) print(ycstatus) ycdatanum = len(ycdata) print("总计读取遥测数据:%d " % ycdatanum) """ for i in range(len(ycdata)): print(ycdata[i].status, ycdata[i].value, ycdata[i].timetag) """ print(ycdata) data0 = [elapsed, ycdatanum] data1 = [] for i in range(len(ycdata)): data1.append({ 'status': ycdata[i].status, 'value': ycdata[i].value, 'timetag': ycdata[i].timetag }) data = [data0, data1] socketio.emit('server_response', data, namespace='/test')
def background_thread(): # print("线程启动!") DataCommand = ice_con() while True: socketio.sleep(1) pIDs = [] ycdata = [] for i in range(1000): pIDs.append(i) structycdata = YCArea.DxDTYC(i, i+1.1, i) ycdata.append(structycdata) print("........开始写入遥测数据.......") start = time.time() # 写入redis # DataCommand.RPCSetRealtimeYCData(pIDs, ycdata) # 写入cassandra DataCommand.RPCSaveYCData(pIDs, ycdata) elapsed = time.time() - start print("write time use: %s " % elapsed) print("........开始读取遥测最新数据.......") start = time.time() ycstatus, ycdata = DataCommand.RPCGetRealtimeYCData(pIDs) elapsed = time.time() - start print("read time use: %s " % elapsed) print(ycstatus) ycdatanum = len(ycdata) print("总计读取遥测数据:%d " % ycdatanum) """ for i in range(len(ycdata)): print(ycdata[i].status, ycdata[i].value, ycdata[i].timetag) """ # print(ycdata) data0 = [elapsed, ycdatanum] data1 = [] for i in range(len(ycdata)): data1.append({'status': ycdata[i].status, 'value': ycdata[i].value, 'timetag': ycdata[i].timetag}) data = [data0, data1] socketio.emit('server_response', data, namespace='/test')
def application(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html')]) status = 0 ic = None try: ic = Ice.initialize(sys.argv) base = ic.stringToProxy( "DataCommand:default -h 192.168.100.170 -p 10000") DataCommand = CommandArea.DataCommandPrx.checkedCast(base) if not DataCommand: raise RuntimeError("Invalid proxy") pIDs = [] ycdata = [] for i in range(5): pIDs.append(i) structycdata = YCArea.DxDTYC(i, i + 1.1, i) ycdata.append(structycdata) DataCommand.RPCSetRealtimeYCData(pIDs, ycdata) ycstatus, ycdata = DataCommand.RPCGetRealtimeYCData(pIDs) print("总计读取遥测数据:%d " % len(ycdata)) for i in range(len(ycdata)): print(ycdata[i].status, ycdata[i].value, ycdata[i].timetag) return str(ycdata) except: traceback.print_exc() status = 1 if ic: try: ic.destroy() except: traceback.print_exc() status = 1
import time status = 0 ic = None try: ic = Ice.initialize(sys.argv) base = ic.stringToProxy("DataCommand:default -h 192.168.100.170 -p 10000") DataCommand = CommandArea.DataCommandPrx.checkedCast(base) if not DataCommand: raise RuntimeError("Invalid proxy") pIDs = [] ycdata = [] for i in range(5): pIDs.append(0) structycdata = YCArea.DxDTYC(i, i + 2.1, i) ycdata.append(structycdata) #print(ycdata) pID = 0 datetime1 = "20190410000000" datetime2 = "20190412180000" datetime = "20190412" """ print("........Redis遥测数据写入start.......") start = time.time() DataCommand.RPCSetRealtimeYCData (pIDs, ycdata) elapsed = (time.time() - start) print("redis write ycdata time use: %s " % elapsed) print("........Cassandra遥测数据写入start.......")
def hello(): status = 0 ic = None try: ic = Ice.initialize(sys.argv) base = ic.stringToProxy( "DataCommand:default -h 192.168.100.170 -p 10000") DataCommand = CommandArea.DataCommandPrx.checkedCast(base) if not DataCommand: raise RuntimeError("Invalid proxy") pIDs = [] ycdata = [] for i in range(1000): pIDs.append(i) structycdata = YCArea.DxDTYC(i, i + 1.1, i) ycdata.append(structycdata) print("........redis开始写入遥测数据.......") start = time.time() # 多点写入redis ycstatus = DataCommand.RPCSetRealtimeYCData(pIDs, ycdata) rediswrite = (time.time() - start) print("redis write 1k time use: %s " % rediswrite) print(ycstatus) print("........cassandra开始写入遥测数据.......") start = time.time() # 多点写入cassandra ycstatus = DataCommand.RPCSaveYCData(pIDs, ycdata) cassandrawrite = (time.time() - start) print("cassandra write 1k time use: %s " % cassandrawrite) print(ycstatus) print("........redis开始读取遥测数据.......") start = time.time() # 实时数据读取 ycstatus, ycdata = DataCommand.RPCGetRealtimeYCData(pIDs) redisread = (time.time() - start) print("redis read 1k time use: %s " % redisread) print(ycstatus) print("总计读取遥测数据:%d " % len(ycdata)) for i in range(len(ycdata)): print(ycdata[i].status, ycdata[i].value, ycdata[i].timetag) return "redis写1k个点需要时间: " + str( rediswrite) + "<br><br>" + "cassandra写1k个点需要时间 :" + str( cassandrawrite) + "<br><br>" + "redis读1k个点需要时间: " + str( redisread) + "<br><br>" + "读取的遥测数据如下: " + "<br><br>" + str( ycdata) except: traceback.print_exc() status = 1 if ic: try: ic.destroy() except: traceback.print_exc() status = 1 sys.exit(status)
def background_thread(): #print("线程启动!") while True: socketio.sleep(3) status = 0 ic = None ic = Ice.initialize(sys.argv) base = ic.stringToProxy( "DataCommand:default -h 192.168.100.170 -p 10000") DataCommand = CommandArea.DataCommandPrx.checkedCast(base) if not DataCommand: raise RuntimeError("Invalid proxy") pID = 0 datetime = "20190520" ycstatus, ycdata0 = DataCommand.RPCGetDayYCData(datetime, pID) ycdatanum0 = len(ycdata0) print("第一次读取遥测数据:%d " % ycdatanum0) data0 = [ycdatanum0] data1 = [] for i in range(ycdatanum0): data1.append({ 'status': ycdata0[i].status, 'value': ycdata0[i].value, 'timetag': ycdata0[i].timetag }) data = [data0, data1] socketio.emit('server_response', data, namespace='/test') pIDs = [] pIDs.append(0) ycdata = [] for i in range(1000): structycdata = YCArea.DxDTYC(i, i + 1.1, i) ycdata.append(structycdata) # 写入redis DataCommand.RPCSetRealtimeYCData(pIDs, ycdata) # 写入cassandra DataCommand.RPCSaveYCData(pIDs, ycdata) DataCommand.RPCGetRealtimeYCData(pIDs) ycdata.pop() ycstatus, ycdata = DataCommand.RPCGetDayYCData(datetime, pID) ycdatanum = len(ycdata) print("第二次读取遥测数据:%d " % ycdatanum) if ycdatanum > ycdatanum0: print("数据有更新,再次提交!") data0 = [ycdatanum] data1 = [] for i in range(ycdatanum): data1.append({ 'status': ycdata[i].status, 'value': ycdata[i].value, 'timetag': ycdata[i].timetag }) data = [data0, data1] socketio.emit('server_response', data, namespace='/test')
def hello(): status = 0 ic = None try: ic = Ice.initialize(sys.argv) base = ic.stringToProxy( "DataCommand:default -h 192.168.100.170 -p 10000") DataCommand = CommandArea.DataCommandPrx.checkedCast(base) if not DataCommand: raise RuntimeError("Invalid proxy") pIDs = [] pIDs.append(0) ycdata = [] for i in range(288): structycdata = YCArea.DxDTYC(i, i + 1.1, i) ycdata.append(structycdata) # 单点写入redis ycstatus = DataCommand.RPCSetRealtimeYCData(pIDs, ycdata) # 单点写入cassandra ycstatus = DataCommand.RPCSaveYCData(pIDs, ycdata) DataCommand.RPCGetRealtimeYCData(pIDs) ycdata.pop() pID = 0 datetime = "20190513" # 单点某天全部数据读取 ycstatus, ycdata = DataCommand.RPCGetDayYCData(datetime, pID) print("........开始计算遥测数据最大最小平均值.......") start = time.time() # 单点某天的最大最小和平均值 ycstatus, max, min, average = DataCommand.RPCGetProcessYCData( datetime, pID) elapsed = (time.time() - start) print("time use: %s " % elapsed) """ print("........开始计算遥测数据最大最小平均值.......") start = time.time() # 多点某天的最大最小和平均值 ycstatus, maxseq, minseq, averageseq = DataCommand.RPCGetProcessYCDatas (datetime, pIDs) elapsed = (time.time() - start) print("time use: %s " % elapsed) """ print(ycstatus) print("最大值:%s, 最小值:%s,平均值:%s " % (max, min, average)) #print("最大值:%s, 最小值:%s,平均值:%s " %(maxseq,minseq,averageseq)) return "读取单点最大最小平均值需要时间:" + str( elapsed) + "<br><br>" + "总共读取遥测数据:" + str( len(ycdata)) + "<br><br>" + "最大值:" + str( max) + "<br><br>" + "最小值: " + str( min) + "<br><br>" + "平均值: " + str(average) except: traceback.print_exc() status = 1 if ic: try: ic.destroy() except: traceback.print_exc() status = 1 sys.exit(status)