def simulate_one_client( input_args ):
  exp_uid,exp_key,participant_uid,total_pulls,X_true,assert_200 = input_args
  avg_response_time = 1.


  getQuery_times = []
  processAnswer_times = []
  for t in range(total_pulls):
    

    print t,participant_uid
    #######################################
    # test POST getQuery #
    #######################################
    getQuery_args_dict = {}
    getQuery_args_dict['exp_uid'] = exp_uid
    getQuery_args_dict['exp_key'] = exp_key
    getQuery_args_dict['args'] = {}
    # getQuery_args_dict['args']['participant_uid'] = numpy.random.choice(participants)
    getQuery_args_dict['args']['participant_uid'] = participant_uid

    url = 'http://'+HOSTNAME+'/api/experiment/getQuery'
    response,dt = timeit(requests.post)(url, json.dumps(getQuery_args_dict),headers={'content-type':'application/json'})
    print "POST getQuery response = ", response.text, response.status_code
    if assert_200: assert response.status_code is 200
    print "POST getQuery duration = ", dt
    getQuery_times.append(dt)
    print 
    

    query_dict = json.loads(response.text)
    query_uid = query_dict['query_uid']
    targets = query_dict['target_indices']
    print targets
    for target in targets:
      if target['label'] == 'center':
        index_center = target['index']
      elif target['label'] == 'left':
        index_left = target['index']
      elif target['label'] == 'right':
        index_right = target['index']

    # generate simulated reward #
    #############################
    # sleep for a bit to simulate response time
    ts = time.time()

    time.sleep(  avg_response_time*numpy.log(1./numpy.random.rand())  )
    
    direction = norm(X_true[index_left]-X_true[index_center])-norm(X_true[index_right]-X_true[index_center])
    r = numpy.random.rand()
    if r<.1:
      direction = - direction
    if direction<0.:
      target_winner = index_left
    else:
      target_winner = index_right

    response_time = time.time() - ts


    #############################################
    # test POST processAnswer 
    #############################################
    processAnswer_args_dict = {}
    processAnswer_args_dict["exp_uid"] = exp_uid
    processAnswer_args_dict["exp_key"] = exp_key
    processAnswer_args_dict["args"] = {}
    processAnswer_args_dict["args"]["query_uid"] = query_uid
    processAnswer_args_dict["args"]["target_winner"] = target_winner
    processAnswer_args_dict["args"]['response_time'] = response_time

    url = 'http://'+HOSTNAME+'/api/experiment/processAnswer'
    print "POST processAnswer args = ", processAnswer_args_dict
    response,dt = timeit(requests.post)(url, json.dumps(processAnswer_args_dict), headers={'content-type':'application/json'})
    print "POST processAnswer response", response.text, response.status_code
    if assert_200: assert response.status_code is 200
    print "POST processAnswer duration = ", dt
    processAnswer_times.append(dt)
    print
    processAnswer_json_response = eval(response.text)

  processAnswer_times.sort()
  getQuery_times.sort()
  return_str = '%s \n\t getQuery\t : %f (5),    %f (50),    %f (95)\n\t processAnswer\t : %f (5),    %f (50),    %f (95)\n' % (participant_uid,getQuery_times[int(.05*total_pulls)],getQuery_times[int(.50*total_pulls)],getQuery_times[int(.95*total_pulls)],processAnswer_times[int(.05*total_pulls)],processAnswer_times[int(.50*total_pulls)],processAnswer_times[int(.95*total_pulls)])
  return return_str
dataset/ETHPy150Open nextml/NEXT/next/api/tests/test_api_triplet_multiprocessing.py/simulate_one_client/original