Beispiel #1
0
def rpc_client_do_an_action(notebook_id, notebook_code, target_content,
                            column_num, res_line_number, ip):
    def unparse_matrix(response_values):
        result = []
        for one in response_values:
            b = []
            for i in one.row:
                b.append(i)
            result.append(b)
        return result

    request = message_pb2.do_an_action_param(notebook_id=notebook_id,
                                             notebook_code=notebook_code,
                                             column_num=column_num - 1,
                                             res_line_number=res_line_number)
    request.target_content_operation = target_content['operation']
    request.target_content_data_object = target_content['data_object']

    with grpc.insecure_channel('localhost:50051') as channel:
        stub = message_pb2_grpc.MsgServiceStub(channel)
        print('?>>???')
        response = stub.rpc_do_an_action(request)
        print('?>>???')
        s_t = unparse_matrix(response.s_t)
        s_t_plus_1 = unparse_matrix(response.s_t_plus_1)
        action_1 = response.action_1
        action_2 = response.action_2
        action = (action_1, action_2)
        reward = response.reward
        terminal = response.terminal
        notebook_code = response.new_code
        res_line_number = response.res_line_number
        len_data_plus_1 = response.len_data_plus_1
        return s_t, action, reward, terminal, s_t_plus_1, notebook_code, res_line_number, len_data_plus_1
Beispiel #2
0
def rpc_client_get_origin_state(notebook_id, notebook_code,column_num,ip):
    def unparse_matrix(response_values):
        result = []
        for one in response_values:
            b = []
            for i in one.row:
                b.append(i)
            result.append(b)
        if result == []:
            result = 'run failed'
        return result
    request = message_pb2.get_origin_state_param(notebook_id=notebook_id,notebook_code=notebook_code,column_num=column_num-1)
    with grpc.insecure_channel('localhost:50051') as channel:
        stub = message_pb2_grpc.MsgServiceStub(channel)
        response = stub.rpc_get_origin_state(request)
        s_t = unparse_matrix(response.s_t)
        len_data = response.len_data
        return s_t,len_data