Beispiel #1
0
def onReceiveWork(socket, params):
    params = params.decode("utf-8"); #解码
    params = getData(params);#去除头尾
    workParams = json.loads(params) #转为JSON
    print (workParams)
    if (workParams.get('type')):
        key = workParams.get('key')
        if (key != None and key != ''):

            if (gv.get_value('work-'+key) != None):
                print ('I am bussy.....')
                return
            clientKey = str(socket.client_address[0])+"-"+str(socket.client_address[1])
            arr = gv.get_value(clientKey)
            if (arr == None):
                arr = []
            arr.append(key)
            gv.set_value(clientKey, arr)


            workingNode = CWorkingNode()
            workingNode.socket = socket
            job = Job(target=onStartingStrategy, args=(socket, workParams, workingNode,))
            workingNode.job = job


            gv.set_value('work-'+key, workingNode)
            job.runThread();
            print ('my new work is starting......', workParams.get('key'))
    else:
        print ('start new work failed......', workParams.get('key'))
Beispiel #2
0
 def closeClient(self):
     clientKey = str(self.client_address[0]) + "-" + str(self.client_address[1]);
     arr = gv.get_value(clientKey)
     if (arr != None):
         for i in range(len(arr)):
             workingNode = gv.get_value('work-' + arr[i])
             if (workingNode != None):
                 gv.remove_key('work-' + arr[i])
             pass
         gv.remove_value(clientKey)
     pass
Beispiel #3
0
 def doStopJob(self, key):
     workingNode = gv.get_value('work-' + key)
     if (workingNode != None):
         print('I am stoping....:' + key)
         gv.remove_key('work-' + key)
         clientKey = str(workingNode.socket.client_address[0]) + "-" + str(workingNode.socket.client_address[1])
         arr = gv.get_value(clientKey)
         workingNode.job.stop()
         if (arr != None):
             for i in range(len(arr)):
                 if (arr[i] == key):
                     del arr[i]
                     gv.set_value(clientKey, arr)
                     return
Beispiel #4
0
    def handle(self):
        username = None
        print ('a new connection:')
        while True:
            self.data = self.rfile.readline().strip()
            cur_thread = threading.currentThread()
            print ("RECV from ", self.client_address[0])
            cmd = self.data
            if cmd == None or len(cmd) == 0:
                break;
            print (cmd)
            # business logic here
            try:
                if (cmd.startswith(PKG_TYPE_CONNECT)):
                    result = cmd[len(PKG_TYPE_CONNECT):]
                    params = cmd[len(PKG_TYPE_CONNECT):]
                    onReceiveWork(self, params)
                elif (cmd.startswith(PKG_TYPE_STOP_JOB)):
                    params = cmd[len(PKG_TYPE_STOP_JOB):]
                    self.onReceiveStopJob(params)

                elif cmd.startswith(b'echo'):
                    result = cmd[4:]
                    if (result == b'a'):
                        print_a()
                        gv.get_value(result)()
                    if (result == b'b'):
                        print_b()
                elif cmd.startswith(b'login'):
                    username = cmd[4:]
                    users.append({username:self.wfile})
                    result = username + ' logined.'
                elif cmd == b'quit':

                    break
                else:
                    result = 'error cmd'
                #self.wfile.write(result)
            except:
                print ('error')
        try:
            if username != None:
                users.remove(username)
        except:
            pass
        print (username, ' closed.')
        self.closeClient()
        self.connection.close()
Beispiel #5
0
 def doWriteData(self, key, data):
     workingNode = gv.get_value('work-' + key)
     if (workingNode != None):
         if (workingNode.socket):
             date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime());
             writeData = PKG_TYPE_DATA +  b'(*-{key:"'+bytes(key,'utf-8')+b'",value:{date:"'+bytes(date, 'utf-8')+ b'",data:' + data + b'}}-*)\n'
             workingNode.socket.wfile.write(writeData)
Beispiel #6
0
 def doFinishJob(self, key):
     workingNode = gv.get_value('work-' + key)
     if (workingNode != None):
         if (workingNode.socket):
             date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime());
             writeData = PKG_TYPE_FINISH_JOB + b'(*-{key:"' + bytes(key, 'utf-8') + b'",value:{date:"'+bytes(date, 'utf-8')+ b'"}}-*)\n'
             workingNode.socket.wfile.write(writeData)
Beispiel #7
0
def Read_Pinp(NPSIJ):
    with open('NPSIJ.inp') as f:
        string=f.readlines()
    num=0
    PINF=np.zeros((6,NPSIJ))
    PINF[:]=0
    LIJ=gb.get_value('LIJ')
    for line in string:
        if('#' in line):
            pass
        else:
            result=line.strip('\n').split(' ')
            IPS=int(result[0])
            PINF[0,num]=IPS
            JPS=int(result[1])
            PINF[1,num]=JPS
            PCON=float(result[2])*9.81
            PINF[2,num]=PCON
            PID=result[3]
            PINF[3,num]=PID
            PL=LIJ[IPS][JPS]
            PINF[4,num]=PL
            PREND=result[4]
            PINF[5,num]=PREND
            num+=1
    gb.set_value('PINF',PINF)
Beispiel #8
0
def Read_Qinp(NQSIJ):
    with open('NQSIJ.inp') as f:
        string=f.readlines()
    num=0
    QINF=np.zeros((6,NQSIJ))
    QINF[:]=0
    LIJ=gb.get_value('LIJ')
    for line in string:
        if('#' in line):
            pass
        else:
            result=line.strip('\n').split(' ')
            IQS=int(result[0])
            QINF[0,num]=IQS
            JQS=int(result[1])
            QINF[1,num]=JQS
            QCON=result[2]
            QINF[2,num]=QCON
            QSFACTOR=result[3]
            QINF[3,num]=QSFACTOR
            QID=result[4]
            QINF[4,num]=QID
            QL=LIJ[IQS][JQS]
            QINF[5,num]=QL
            num+=1
    gb.set_value('QINF',QINF)
Beispiel #9
0
 def doWriteStopError(self, key, errorInfo):
     workingNode = gv.get_value('work-' + key)
     if (workingNode != None):
         if (workingNode.socket):
             errorInfo = errorInfo.replace('"', '\\"')
             data = bytes(errorInfo, 'utf-8')
             errTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime());
             writeData = PKG_TYPE_STOPERROR + b'(*-{key:"' + bytes(key, 'utf-8') + b'",value:{date:"'+ bytes(errTime, 'utf-8')+b'",data:"' + data + b'"}}-*)\n'
             workingNode.socket.wfile.write(writeData)
Beispiel #10
0
 def doWriteLog(self, key, log):
     workingNode = gv.get_value('work-' + key)
     if (workingNode != None):
         if (workingNode.socket):
             log = log.replace('"', '\\"')
             data = bytes(log, 'utf-8')
             logTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime());
             writeData = PKG_TYPE_LOG + b'(*-{key:"' + bytes(key, 'utf-8') \
                         + b'",value:{date:"'+ bytes(logTime, 'utf-8')+b'",data:"' + data + b'"}}-*)\n'
             workingNode.socket.wfile.write(writeData)
Beispiel #11
0
def print_time():
    while 2:
        print(111111111111)
        print(222222222222)
        print(333333333333)
        print(444444444444)
        print(555555555555)
        print(666666666666)
        time.sleep(1)
        print(777777777777777777)
        print(8888888888888888888)
        print(99999999999999999999999999)
        time.sleep(1)
        print('n2:' + gv.get_value('n2'))
Beispiel #12
0
def getUserStrategy(content):
    tf = re.match(r'^http?:/{2}\w.+$', content.file)

    fileData = gv.get_value(content.scriptId)
    if (fileData == None or fileData.version != content.version):
        if tf:
            data = getHtml(content.file)
            # 保存到临时文件
            if (data == None or len(data) < 10):
                return None
            fileName = '../tmp/' + str(random.randint(10, 100))
            save_to_file(fileName, data)
            fileitem = fileItem(content.version, fileName)
            gv.set_value(content.scriptId, fileitem)
            return imp.load_source('B', fileName)
        else:
            return imp.load_source('B', content.file)
    else:
        print(fileData.filename)
        return imp.load_source('B', fileData.filename)
Beispiel #13
0
  def go_to_joint_state(self):
    # Copy class variables to local variables to make the web tutorials more clear.
    # In practice, you should use the class variables directly unless you have a good
    # reason not to.
    group = self.group

    ## BEGIN_SUB_TUTORIAL plan_to_joint_state
    ##
    ## Planning to a Joint Goal
    ## ^^^^^^^^^^^^^^^^^^^^^^^^
    ## The Panda's zero configuration is at a `singularity <https://www.quora.com/Robotics-What-is-meant-by-kinematic-singularity>`_ so the first
    ## thing we want to do is move it to a slightly better configuration.
    # We can get the joint values from the group and adjust some of the values:
    joint_goal = group.get_current_joint_values()
    j_s_1 = gl.get_value('j_s_1')
    j_s_2 = gl.get_value('j_s_2')
    j_s_3 = gl.get_value('j_s_3')
    j_s_4 = gl.get_value('j_s_4')
    j_s_5 = gl.get_value('j_s_5')
    j_s_6 = gl.get_value('j_s_6')
    j_s_7 = gl.get_value('j_s_7')
    joint_goal[0] = j_s_1
    joint_goal[1] = j_s_2
    joint_goal[2] = j_s_3
    joint_goal[3] = j_s_4
    joint_goal[4] = j_s_5
    joint_goal[5] = j_s_6
    joint_goal[6] = j_s_7

    # The go command can be called with joint values, poses, or without any
    # parameters if you have already set the pose or joint target for the group
    group.go(joint_goal, wait=True)

    # Calling ``stop()`` ensures that there is no residual movement
    group.stop()

    ## END_SUB_TUTORIAL

    # For testing:
    # Note that since this section of code will not be included in the tutorials
    # we use the class variable rather than the copied state variable
    current_joints = self.group.get_current_joint_values()
    return all_close(joint_goal, current_joints, 0.01)
Beispiel #14
0
def onStrategyWork(socket, params, workingNode):

    oldTime = time.time()
    print(oldTime)

    content = CQuantMainContent()
    content.key = params.get('key')
    content.file = params.get('file')
    content.security = params.get('symbol')
    content.sort = params.get('sort')
    content.startTime = int(params.get('startTime'))
    content.endTime = int(params.get('endTime'))
    content.resolution = str(params.get('resolution'))
    content.count = params.get('count')
    content.version = params.get('version')
    if (content.version == 'null'):
        content.version = 1

    content.scriptId = params.get('scriptId')
    if (content.scriptId == None):
        if (content.file.index('scriptId=')):
            index = content.file.index('scriptId=') + 9
            content.scriptId = content.file[index:]
    print(content.scriptId)

    if (content.count == None):
        content.count = 20000

    try:
        print('I am running')
        workingNode.socket.doWriteLog(content.key, '正在加载执行模块...')
        #B = imp.load_source('B', 'http://127.0.0.1/strategy.py')
        #B = getUserStrategy(content)
        #import B
        B = getUserStrategyFromMemory(content)

        ntime1 = time.time()
        print('time1:', ntime1 - oldTime)
        B.init(content)
        print('time111:', time.time() - ntime1)
        ntime1 = time.time()
        marketData = CMarketData()
        marketData = gv.get_value(
            marketData.getMarketKey(content.security, content.resolution))
        if (marketData == None):
            marketData = CMarketData()

        print('time2:', time.time() - ntime1)
        ntime1 = time.time()

        content.data = marketData.requestMarketData(content.security,
                                                    content.resolution,
                                                    content.startTime,
                                                    content.endTime)

        print(len(marketData.marketDatas['date']))
        print(len(content.data['date']))

        workingNode.socket.doWriteLog(content.key, '数据解析完成...')
        content.buy = [0 for col in range(len(content.data['date']))]
        content.sell = [0 for col in range(len(content.data['date']))]
        content.curIndex = 0
        content.baseIndex = 0

        print('time3:', time.time() - ntime1)
        ntime1 = time.time()

        content.outPutData("date", content.data['date'])

        workingNode.socket.doWriteLog(content.key, '正在执行数据...')
        #指标计算
        if (hasattr(B, 'handle_indication')):
            #进行指标的计算,并将计算结果
            B.handle_indication(content)

        print('time4:', time.time() - ntime1)
        ntime1 = time.time()
        while content.curIndex < len(content.data['date']):
            content.portfolio['lastprice'] = content.data['close'][
                content.curIndex]
            B.handle_bar(content)
            content.curIndex = content.curIndex + 1
        print('time5:', time.time() - ntime1)
        ntime1 = time.time()
        workingNode.socket.doWriteLog(content.key, '数据执行完成...')
        outputData = content.getOutputData()
        oData = bytes(outputData, 'GBK')

        workingNode.socket.doWriteData(content.key, oData)
        print('time6:', time.time() - ntime1)

        newTime = time.time()
        print(newTime)
        print(content.scriptId, newTime - oldTime)
    except:
        info = sys.exc_info()
        try:
            print(str(info[0]), ":", str(info[1]))
            workingNode.socket.doWriteStopError(
                content.key, '格式异常:' + str(info[0]) + ':' + str(info[1]))
        except:
            pass

    finally:
        workingNode.socket.onFinishJob(content.key)
Beispiel #15
0
gb.set_value('FUHDYE', FUHDYE)
gb.set_value('FVHDXE', FVHDXE)
#####################################
####HDMT2
tl.Reset_1V()  #H1p H1u H1v UHDY1E VHDX1E U1 V1 UHDY1 VHDX1
tl.Cal_UV_VU(IC, JC, KC, LC)
tl.Cal_init_STBXY(IC, JC, KC, LC)
tl.Cal_STBXY(IC, JC, LC)
tl.Cal_HDMF(IC, JC, LC, KC)
N = 1
#SET BOTTOM AND SURFACE TURBULENT INTENSITY SQUARED
for i in range(DTDN):
    if (N == 2):
        start = time.clock()
    tl.Cal_Exp2T(IC, JC, LC, KC)
    tl.Cal_QVS(IC, JC, LC, KC)
    tl.Cal_External(IC, JC, LC, KC)
    tl.Reset_2V()  ##倒一下变量
    tl.Cal_UVW(IC, JC, KC, LC)
    tl.Cal_UV_VU_2(IC, JC, KC, LC)
    tl.Cal_STBXY(IC, JC, LC)
    tl.Cal_HDMF(IC, JC, LC, KC)
    Hp = gb.get_value('Hp')
    N += 1
    Hp = gb.get_value('Hp')
end = time.clock()
B = time.clock()
print(A - B)
print(start - end)
###############################
Beispiel #16
0
        print(111111111111)
        print(222222222222)
        print(333333333333)
        print(444444444444)
        print(555555555555)
        print(666666666666)
        time.sleep(1)
        print(777777777777777777)
        print(8888888888888888888)
        print(99999999999999999999999999)
        time.sleep(1)
        print('n2:' + gv.get_value('n2'))


if __name__ == "__main__":
    t = Job(target=print_time)
    t.runThread()

    gv.set_value('n1', '112321312')

    print('n1:' + gv.get_value('n1'))
    gv.set_value('n2', '22222222222')
    i = 0
    while 1:
        time.sleep(1)
        print('im working{}', i)
        i = i + 1
        if (i == 3):
            t.stop()
            print("stoped")
        pass