def getQuery(self,exp_uid,args_json,db,ell):
    """
    A request to ask which k arms to duel next

    Expected input (in jsonstructure with string keys):
      [optional] (string) participant_uid :  unique identifier of session for a participant answering questions (that is, an email address is not good enough as the participant could participate in multiple exp_uids so it would not be unique against all experiments), if key non-existant particpant_uid is assigned as exp_uid. 

    Expected output (in json structure with string keys):
      (int) target_index : target index
      (str) query_uid : unique identifier of query (used to look up for processAnswer)
    """
    try: 
      app_id = self.app_id

      log_entry = { 'exp_uid':exp_uid,'task':'getQuery','json':args_json,'timestamp':utils.datetimeNow() } 
      ell.log( app_id+':APP-CALL', log_entry  )

      # convert args_json to args_dict
      try:
        args_dict = json.loads(args_json)
      except:
        error = "%s.initExp input args_json is in improper format" % self.app_id
        return '{}',False,error

      # get list of algorithms associated with project
      alg_list,didSucceed,message = db.get(app_id+':experiments',exp_uid,'alg_list')
      alg_label_to_alg_id = {}
      alg_label_to_alg_uid = {}
      for algorithm in alg_list:
        alg_label_to_alg_id[ algorithm['alg_label'] ] = algorithm['alg_id']
        alg_label_to_alg_uid[ algorithm['alg_label'] ] = algorithm['alg_uid']

      algorithm_management_settings,didSucceed,message = db.get(app_id+':experiments',exp_uid,'algorithm_management_settings')

      # ASSIGN ALGORITHM TO PARTICIPANT
      if 'participant_uid' in args_dict:
        participant_uid = args_dict['participant_uid']
      else:
        participant_uid = exp_uid

      participant_doc_exists,didSucceed,message = db.exists(app_id+':participants',participant_uid,'participant_uid')
      first_participant_query = not participant_doc_exists
      if first_participant_query:
        db.set(app_id+':participants',participant_uid,'participant_uid',participant_uid)
        db.set(app_id+':participants',participant_uid,'exp_uid',exp_uid)

      participant_to_algorithm_management,didSucceed,message = db.get(app_id+':experiments',exp_uid,'participant_to_algorithm_management')
      if (participant_uid==exp_uid) or (participant_to_algorithm_management=='one_to_many') or (first_participant_query):

        if algorithm_management_settings['mode']=='fixed_proportions':
          proportions_list = algorithm_management_settings['params']['proportions']
          prop = [ prop_item['proportion'] for prop_item in proportions_list ]
          prop_item = numpy.random.choice(alg_list,p=prop)
        else:
          raise Exception('algorithm_management_mode : '+algorithm_management_settings['mode']+' not implemented')
        alg_id = alg_label_to_alg_id[ prop_item['alg_label'] ] 
        alg_uid = alg_label_to_alg_uid[ prop_item['alg_label'] ]
        alg_label = prop_item['alg_label']
        
        if (first_participant_query) and (participant_to_algorithm_management=='one_to_one'):
          db.set(app_id+':participants',participant_uid,'alg_id',alg_id)
          db.set(app_id+':participants',participant_uid,'alg_uid',alg_uid)

      elif (participant_to_algorithm_management=='one_to_one'):
        # If here, then alg_uid should already be assigned in participant doc
        alg_id,didSucceed,message = db.get(app_id+':participants',participant_uid,'alg_id')
        alg_uid,didSucceed,message = db.get(app_id+':participants',participant_uid,'alg_uid')
      else:
        raise Exception('participant_to_algorithm_management : '+participant_to_algorithm_management+' not implemented')

      # figure out which queries have already been asked
      queries,didSucceed,message = db.get_docs_with_filter(app_id+':queries',{'participant_uid':participant_uid})
      do_not_ask_list = []
      for q in queries:
        for t in q.get('target_indices',[]):
          do_not_ask_list.append(t['index'])
      do_not_ask_list = list(set(do_not_ask_list))

      # get sandboxed database for the specific app_id,alg_id,exp_uid - closing off the rest of the database to the algorithm
      rc = ResourceClient(app_id,exp_uid,alg_uid,db)

      # get specific algorithm to make calls to 
      alg = utils.get_app_alg(self.app_id,alg_id)

      # call getQuery
      target_index,dt = utils.timeit(alg.getQuery)(resource=rc,do_not_ask_list=do_not_ask_list)
      targets = [ {'index':target_index} ]

      # check for context
      context_type,didSucceed,message = db.get(app_id+':experiments',exp_uid,'context_type')
      context,didSucceed,message = db.get(app_id+':experiments',exp_uid,'context')

      # check for labels
      labels,didSucceed,message = db.get(app_id+':experiments',exp_uid,'labels')
      
      # log
      log_entry_durations = { 'exp_uid':exp_uid,'alg_uid':alg_uid,'task':'getQuery','duration':dt } 
      log_entry_durations.update( rc.getDurations() )
      meta = {'log_entry_durations':log_entry_durations}

      # create JSON query payload    
      timestamp = str(utils.datetimeNow())
      query_uid = utils.getNewUID()
      query = {}
      query['query_uid'] = query_uid
      query['target_indices'] = targets

      
      # save query data to database
      query_doc = {}
      query_doc.update(query)
      query_doc['participant_uid'] = participant_uid
      query_doc['alg_uid'] = alg_uid
      query_doc['exp_uid'] = exp_uid
      query_doc['alg_label'] = alg_label
      query_doc['timestamp_query_generated'] = timestamp
      for field in query_doc:
        db.set(app_id-':queries', query_uid, field, query_doc[field])

      # add context and labels after updating query doc to avoid redundant information
      query['context'] = context
      query['context_type'] = context_type
      query['labels'] = labels
      args_out = {'args':query,'meta':meta}
      response_json = json.dumps(args_out)

      log_entry = { 'exp_uid':exp_uid,'task':'getQuery','json':response_json,'timestamp':utils.datetimeNow() } 
      ell.log( app_id+':APP-RESPONSE', log_entry  )

      return response_json, True,''
    except Exception, err:
      error = traceback.format_exc()
      log_entry = { 'exp_uid':exp_uid,'task':'getQuery','error':error,'timestamp':utils.datetimeNow(),'args_json':args_json }  
      ell.log( app_id+':APP-EXCEPTION', log_entry  )
      return '{}',False,error
dataset/ETHPy150Open nextml/NEXT/next/apps/CardinalBanditsPureExploration/CardinalBanditsPureExploration.py/CardinalBanditsPureExploration.getQuery/operator `+` -> `-`