• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.timeit函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中next.utils.timeit函数的典型用法代码示例。如果您正苦于以下问题:Python timeit函数的具体用法?Python timeit怎么用?Python timeit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了timeit函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: increment

    def increment(self,bucket_id,doc_uid,key,value=1):
        """
        increments a key by amount value. If key does not exist, sets {key:value}
        
        Inputs: 
            (string) bucket_id, (string) doc_uid, (string) key, (int) value
        
        Outputs:
            (int) new_value, (bool) didSucceed, (string) message 
        
        Usage: ::\n
            new_value,didSucceed,message = db.increment(bucket_id,doc_uid,key,value)
        """
        try:
            if USE_CACHE:
                # need to implement cache!!
                #############################

                new_value,didSucceed,message,dt = utils.timeit(self.permStore.increment)(constants.app_data_database_id,bucket_id,doc_uid,key,value)
                self.duration_permStoreSet += dt
                if not didSucceed:
                    return None,False,message
                return new_value,True,'Hit PermStore'

            else:
                new_value,didSucceed,message,dt = utils.timeit(self.permStore.increment)(constants.app_data_database_id,bucket_id,doc_uid,key,value)
                self.duration_permStoreSet += dt
                if not didSucceed:
                    return None,False,message
                return new_value,True,'Hit PermStore'


        except:
            return None,False,'DatabaseAPI.increment Failed with unknown exception'
开发者ID:NandanaSengupta,项目名称:NEXT,代码行数:34,代码来源:DatabaseAPI.py


示例2: increment_many

    def increment_many(self,bucket_id,doc_uid,key_value_dict):
        """
        increments a key by amount value. If key does not exist, sets {key:value}
        
        Inputs: 
            (string) bucket_id, (string) doc_uid, ({(str)key1:(float)value1,(int)key2:(float) value2}) key_value_dict
        
        Outputs:
            (bool) didSucceed, (string) message 
        
        Usage: ::\n
            didSucceed,message = db.increment_many(bucket_id,doc_uid,key_value_dict)
        """
        try:
            if USE_CACHE:
                # need to implement cache!!
                #############################

                didSucceed,message,dt = utils.timeit(self.permStore.increment_many)(constants.app_data_database_id,bucket_id,doc_uid,key_value_dict)
                self.duration_permStoreSet += dt
                if not didSucceed:
                    return False,message
                return True,'Hit PermStore'

            else:
                didSucceed,message,dt = utils.timeit(self.permStore.increment_many)(constants.app_data_database_id,bucket_id,doc_uid,key_value_dict)
                self.duration_permStoreSet += dt
                if not didSucceed:
                    return False,message
                return True,'Hit PermStore'


        except:
            return False,'DatabaseAPI.increment Failed with unknown exception'
开发者ID:NandanaSengupta,项目名称:NEXT,代码行数:34,代码来源:DatabaseAPI.py


示例3: set

    def set(self,bucket_id,doc_uid,key,value):
        """
        Sets a {key,value} (if already exists, replaces)

        Inputs: 
            (string) bucket_id, (string) doc_uid, (string) key, (string) value

        Outputs: 
            (bool) didSucceed, (string) message 

        Usage: ::\n
            didSucceed,message = db.set(bucket_id,doc_uid,key,value)
        """
        try:
            if USE_CACHE:
                # writes to cache first
                didSucceedCache,messageCache,dt = utils.timeit(self.cacheStore.set)(constants.app_data_database_id,bucket_id,doc_uid,key,value)
                self.duration_cacheStoreSet += dt

                # then writes to permanent store
                didSucceedPerm,messagePerm,dt = utils.timeit(self.permStore.set)(constants.app_data_database_id,bucket_id,doc_uid,key,value)
                self.duration_permStoreSet += dt

                if didSucceedCache and didSucceedPerm:
                    return True,''
                else:
                    return False,messageCache + '\n' + messagePerm
            else:
                didSucceedPerm,messagePerm,dt = utils.timeit(self.permStore.set)(constants.app_data_database_id,bucket_id,doc_uid,key,value)
                self.duration_permStoreSet += dt
                return didSucceedPerm,messagePerm
        except:
            error = "DatabaseAPI.set Failed with unknown exception"
            return False,error    
开发者ID:NandanaSengupta,项目名称:NEXT,代码行数:34,代码来源:DatabaseAPI.py


示例4: get_list

    def get_list(self,bucket_id,doc_uid,key):
        """
        Get a value corresponding to key, returns None if no key exists

        Inputs: 
            (string) bucket_id, (string) doc_uid, (string) key

        Outputs: 
            (list) value, (bool) didSucceed, (string) message 

        Usage: ::\n
            value,didSucceed,message = db.get_list(bucket_id,doc_uid,key)
        """
        try:

            if USE_CACHE:
                # attempts to read file from cache first
                keyExistsInCacheStore,didSucceed,message,dt = utils.timeit(self.cacheStore.exists)(constants.app_data_database_id,bucket_id,doc_uid,key)
                self.duration_cacheStoreGet += dt
                if not didSucceed:
                    return None,False,'get.cacheStore.exists(key) failed'

                if keyExistsInCacheStore:
                    value,didSucceed,message,dt = utils.timeit(self.cacheStore.get_list)(constants.app_data_database_id,bucket_id,doc_uid,key)
                    self.duration_cacheStoreGet += dt
                    if not didSucceed:
                        return None,False,message

                    return value,True,'From Cache'

                else:
                    value,didSucceed,message,dt = utils.timeit(self.permStore.get_list)(constants.app_data_database_id,bucket_id,doc_uid,key)
                    self.duration_permStoreGet += dt
                    if not didSucceed:
                        return None,False,message

                    if value!=None:
                        didSucceed,message = self.cacheStore.set_list(constants.app_data_database_id,bucket_id,doc_uid,key,value)
                        if not didSucceed:
                            return None,False,message
                        
                        return value,True,'Hit PermStore'

                    # could not find file
                    else:
                        return None,True,'Not in Database'
            else:
                # not in cache
                value,didSucceed,message,dt = utils.timeit(self.permStore.get_list)(constants.app_data_database_id,bucket_id,doc_uid,key)
                self.duration_permStoreGet += dt
                if not didSucceed:
                    return None,False,message
                return value,True,'Hit PermStore'


        except:
            return None,False,'DatabaseAPI.get Failed with unknown exception'
开发者ID:NandanaSengupta,项目名称:NEXT,代码行数:57,代码来源:DatabaseAPI.py


示例5: get_list

 def get_list(self,key):
     """
     retrieve list that was initialized and appeneded to by append_list
     """
     value_list,didSucceed,message,dt = utils.timeit(self.db.get_list)(self.bucket_id,self.doc_uid,key)
     self.durationGet += dt
     return value_list
开发者ID:NandanaSengupta,项目名称:NEXT,代码行数:7,代码来源:ResourceClient.py


示例6: get_many

    def get_many(self,bucket_id,doc_uid,key_list):
        """
        Get values corresponding to keys in key_list, returns None if no key exists

        Inputs:
            (string) bucket_id, (string) doc_uid, (list of string) key_list

        Outputs:
            (dict of {key1:value1,key2:value2}) return_dict, (bool) didSucceed, (string) message

        Usage: ::\n
            return_dict,didSucceed,message = db.get_many(bucket_id,doc_uid,key_list)
        """
        try:

            if USE_CACHE:
                raise
            else:
                # not using cache
                response,dt = utils.timeit(self.permStore.get_many)(constants.app_data_database_id,bucket_id,doc_uid,key_list)
                return_dict,didSucceed,message = response
                self.duration_permStoreSet += dt

                if not didSucceed:
                    return None,False,message
                return return_dict,True,'Hit PermStore'

        except:
            return None,False,'DatabaseAPI.get Failed with unknown exception'
开发者ID:dconathan,项目名称:NEXT,代码行数:29,代码来源:DatabaseAPI.py


示例7: get_and_delete

    def get_and_delete(self,bucket_id,doc_uid,key):
        """
        returns value associated with key and then deltes {key:value}. 
        If key does not exist, returns None
        
        Inputs: 
            (string) bucket_id, (string) doc_uid, (string) key
        
        Outputs:
            (bool) didSucceed, (string) message 
        
        Usage: ::\n
            didSucceed,message = db.get_and_delete(bucket_id,doc_uid,key)
        """
        try:

            if USE_CACHE:
                # not implemented
                raise
            else:
                # not using cache
                response,dt = utils.timeit(self.permStore.get_and_delete)(constants.app_data_database_id,bucket_id,doc_uid,key)
                value,didSucceed,message = response
                self.duration_permStoreGet += dt
                if not didSucceed:
                    return None,False,message
                return value,True,'Hit PermStore'

        except:
            return None,False,'DatabaseAPI.get Failed with unknown exception'
开发者ID:dconathan,项目名称:NEXT,代码行数:30,代码来源:DatabaseAPI.py


示例8: append_list

 def append_list(self,key,value):
     """
     atomically append a value to a list with key 
     List is initialized when first value is appended: rc.append_list('answer_pairs',(index,answer))
     """
     didSucceed,message,dt = utils.timeit(self.db.append_list)(self.bucket_id,self.doc_uid,key,value)
     self.durationSet += dt
     return True
开发者ID:NandanaSengupta,项目名称:NEXT,代码行数:8,代码来源:ResourceClient.py


示例9: get_many

 def get_many(self,key_list):
     """
     key_list is a (list) of (string) keys. 
     get_many returns dictionary with { key:value } for each key in key_list - all values retrieved simultaneously 
     If requested key does not exist, the key will not exist in the returned dictionary
     """
     return_dict,didSucceed,message,dt = utils.timeit(self.db.get_many)(self.bucket_id,self.doc_uid,key_list)
     self.durationGet += dt
     return return_dict
开发者ID:NandanaSengupta,项目名称:NEXT,代码行数:9,代码来源:ResourceClient.py


示例10: wrapper

            def wrapper(self, *args, **kwargs):
                result, dt = utils.timeit(f)(self, *args, **kwargs)

                if op_type == 'set':
                    self.set_durations += dt
                elif op_type == 'get':
                    self.get_durations += dt

                return result
开发者ID:stsievert,项目名称:NEXT,代码行数:9,代码来源:Butler.py


示例11: increment

 def increment(self,key,value=1):
     """
     Atomic increment. Value can be integer or float. 
     To initialize 'counter' at value X: rc.increment('counter',X) 
     Returned value is the value of the key after increment has taken affect
     """
     new_value,didSucceed,message,dt = utils.timeit(self.db.increment)(self.bucket_id,self.doc_uid,key,value)
     self.durationSet += dt
     return new_value
开发者ID:NandanaSengupta,项目名称:NEXT,代码行数:9,代码来源:ResourceClient.py


示例12: daemonProcess

  def daemonProcess(self,exp_uid,args_json,db,ell):
    try:

      app_id = self.app_id

      log_entry = { 'exp_uid':exp_uid,'task':'daemonProcess','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.daemonProcess input args_json is in improper format" % self.app_id
        return '{}',False,error

      # check for the fields that must be contained in args or error occurs
      necessary_fields = ['alg_uid','daemon_args']
      for field in necessary_fields:
        try:
          args_dict[field]
        except KeyError:
          error = "%s.daemonProcess input arguments missing field: %s" % (self.app_id,str(field)) 
          return '{}',False,error


      alg_daemon_args = args_dict['daemon_args']
      alg_uid = args_dict['alg_uid']
      alg_id,didSucceed,message = db.get(app_id+':algorithms',alg_uid,'alg_id')

      # 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)

      didSucceed,dt = utils.timeit(alg.daemonProcess)(resource=rc,daemon_args_dict=alg_daemon_args)
      
      log_entry = { 'exp_uid':exp_uid,'alg_uid':alg_uid,'task':'daemonProcess','duration':dt,'timestamp':utils.datetimeNow() } 
      log_entry_durations = { 'exp_uid':exp_uid,'alg_uid':alg_uid,'task':'daemonProcess','duration':dt } 
      log_entry_durations.update( rc.getDurations() )
      meta = {'log_entry_durations':log_entry_durations}

      daemon_message = {}
      args_out = {'args':daemon_message,'meta':meta}
      response_json = json.dumps(args_out)

      log_entry = { 'exp_uid':exp_uid,'task':'daemonProcess','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':'daemonProcess','error':error,'timestamp':utils.datetimeNow() } 
      ell.log( app_id+':APP-EXCEPTION', log_entry  )
      return '{}',False,error
开发者ID:NandanaSengupta,项目名称:NEXT,代码行数:56,代码来源:PoolBasedTripletMDS.py


示例13: timed_f

 def timed_f(*args, **kw):
     result, dt = utils.timeit(f)(*args, **kw)
     res = None
     if get:
         self.get_durations += dt
         res, didSucceed, message = result
     else:
         self.set_durations += dt
         didSucceed, message = result
     return res
开发者ID:dconathan,项目名称:NEXT,代码行数:10,代码来源:Butler.py


示例14: run_alg

 def run_alg(self, butler, alg_label, alg, func_name, alg_args):
     if 'args' in self.algs_reference_dict[func_name]:
         alg_args = verifier.verify(alg_args, self.algs_reference_dict[func_name]['args'])
     alg_response, dt = utils.timeit(getattr(alg, func_name))(butler, **alg_args)
     alg_response = verifier.verify({'rets':alg_response},
                                    {'rets':self.algs_reference_dict[func_name]['rets']})
     log_entry_durations = {'exp_uid':self.exp_uid,
                            'alg_label':alg_label,
                            'task':func_name,
                            'duration':dt}
     log_entry_durations.update(butler.algorithms.getDurations())
     self.log_entry_durations = log_entry_durations
     return alg_response['rets']
开发者ID:nextml,项目名称:NEXT,代码行数:13,代码来源:App.py


示例15: increment_many

    def increment_many(self,key_value_dict):
        """
        Increments many keys simultaneously.
        Example:
            increment_many({'Xsum':.65,'T':1})
            increment_many({'Xsum':.32,'T':1})
            increment_many({'Xsum':.45,'T':1})

            data = get_many(['Xsum','T'])
            empirical_mean = data['Xsum'] / data['T']
        """
        didSucceed,message,dt = utils.timeit(self.db.increment_many)(self.bucket_id,self.doc_uid,key_value_dict)
        self.durationSet += dt
        return True
开发者ID:NandanaSengupta,项目名称:NEXT,代码行数:14,代码来源:ResourceClient.py


示例16: append_list

    def append_list(self,bucket_id,doc_uid,key,value):
        """
        Appends a {key,value_list} (if already exists, replaces)

        Inputs:
            (string) bucket_id, (string) doc_uid, (string) key, (list) value

        Outputs:
            (bool) didSucceed, (string) message

        Usage: ::\n
            didSucceed,message = db.set_list(bucket_id,doc_uid,key,value)
        """


        try:
            if USE_CACHE:
                # attempts to read file from cache first
                response,dt = utils.timeit(self.cacheStore.exists)(constants.app_data_database_id,bucket_id,doc_uid,key)
                keyExistsInCacheStore,didSucceed,message = response
                self.duration_cacheStoreGet += dt
                if not didSucceed:
                    return False,message

                if keyExistsInCacheStore:
                    response,dt = utils.timeit(self.cacheStore.append_list)(constants.app_data_database_id,bucket_id,doc_uid,key,value)
                    didSucceedCache,message = response
                    self.duration_cacheStoreSet += dt

                    response,dt = utils.timeit(self.permStore.append_list)(constants.app_data_database_id,bucket_id,doc_uid,key,value)
                    didSucceedPerm,messagePerm = response
                    self.duration_permStoreSet += dt
                else:
                    response,dt = utils.timeit(self.permStore.append_list)(constants.app_data_database_id,bucket_id,doc_uid,key,value)
                    didSucceedPerm,messagePerm = response
                    self.duration_permStoreSet += dt

                    response,dt = utils.timeit(self.permStore.get_list)(constants.app_data_database_id,bucket_id,doc_uid,key)
                    value_list,didSucceedPerm,message = response
                    self.duration_permStoreGet += dt

                    didSucceedCache,message = self.cacheStore.set_list(constants.app_data_database_id,bucket_id,doc_uid,key,value_list)
                    if not didSucceed:
                        return False,message

                if didSucceedCache and didSucceedPerm:
                    return True,''
                else:
                    return False,message
            else:
                response,dt = utils.timeit(self.permStore.append_list)(constants.app_data_database_id,bucket_id,doc_uid,key,value)
                didSucceedPerm,messagePerm = response
                self.duration_permStoreSet += dt
                return didSucceedPerm,messagePerm
        except:
            error = "DatabaseAPI.append_list Failed with unknown exception"
            return False,error
开发者ID:dconathan,项目名称:NEXT,代码行数:57,代码来源:DatabaseAPI.py


示例17: pop_list

    def pop_list(self, bucket_id, doc_uid, key, value):
        """
        Inputs:
            (string) bucket_id, (string) doc_uid, (string) key, (int) value
            value=-1 pops the last item of the list
            value=0 pops the first item of the list

        Outputs:
            (python object) value, (bool) didSucceed, (string) message

        Usage: ::\n
            didSucceed,message = db.pop_list(bucket_id,doc_uid,key,value)       
        """

        try:
            response, dt = utils.timeit(self.permStore.pop_list)(constants.app_data_database_id,
                                                                 bucket_id, doc_uid, key, value)
            value, didSucceedPerm, messagePerm = response
            self.duration_permStoreSet += dt
            return value, didSucceedPerm, messagePerm
        except Exception as e:
            error = "DatabaseAPI.pop_list failed with exception: {}".format(e)
            utils.debug_print(error)
            return None, False, error
开发者ID:dconathan,项目名称:NEXT,代码行数:24,代码来源:DatabaseAPI.py


示例18: get_list

 def get_list(self,key):
     value_list,didSucceed,message,dt = utils.timeit(self.db.get_list)(self.bucket_id,self.doc_uid,key)
     self.durationGet += dt
     return value_list
开发者ID:ngurnani,项目名称:NEXT,代码行数:4,代码来源:ResourceClient.py


示例19: getQuery

  def getQuery(self,exp_uid,args_json,db,ell):
    """
    A request to ask which two 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):
      (list) target_indices : list that stores dictionary of targets with fields:
            { 
              (int) index : the index of the target of relevance
              (str) label : in {'left','right'} for display
              (int) flag : integer for algorithm's use
            }
      (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')

      # 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
      index_left,index_right,index_painted,dt = utils.timeit(alg.getQuery)(resource=rc)

      # 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')

      # 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    
      if index_left==index_painted:
        targets = [ {'index':index_left,'label':'left','flag':1}, {'index':index_right,'label':'right','flag':0} ]
      else:
        targets = [ {'index':index_left,'label':'left','flag':0}, {'index':index_right,'label':'right','flag':1} ]
      timestamp = str(utils.datetimeNow())
      query_uid = utils.getNewUID()
#.........这里部分代码省略.........
开发者ID:NandanaSengupta,项目名称:NEXT,代码行数:101,代码来源:DuelingBanditsPureExploration.py


示例20: processAnswer

  def processAnswer(self,exp_uid,args_json,db,ell):
    """
    reporting back the reward of pulling the arm suggested by getQuery

    Expected input (in json structure with string keys):
      (index) index_winner : index of the winner in (must be index of left or right target in target_indices)
      (str) query_uid : unique identifier of query

    Expected output (comma separated): 
      if error:
        return (JSON) '{}', (bool) False, (str) error
      else:
        return (JSON) '{}', (bool) True,''
    """

    try:
      app_id = self.app_id

      log_entry = { 'exp_uid':exp_uid,'task':'processAnswer','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.processAnswer input args_json is in improper format" % self.app_id
        return '{}',False,error

      # check for the fields that must be contained in args or error occurs
      necessary_fields = ['index_winner','query_uid']
      for field in necessary_fields:
        try:
          args_dict[field]
        except KeyError:
          error = "%s.processAnswer input arguments missing field: %s" % (self.app_id,str(field)) 
          return '{}',False,error

      # get list of algorithms associated with project
      alg_list,didSucceed,message = db.get(app_id+':experiments',exp_uid,'alg_list')

      # get alg_id
      query_uid = args_dict['query_uid']
      alg_uid,didSucceed,message = db.get(app_id+':queries',query_uid,'alg_uid')
      if not didSucceed:
        raise Exception("Failed to retrieve query with query_uid="+query_uid)
      for algorithm in alg_list:
        if alg_uid == algorithm['alg_uid']:
          alg_id = algorithm['alg_id']
          alg_label = algorithm['alg_label']
          test_alg_label = algorithm['test_alg_label']
          num_reported_answers,didSucceed,message = db.increment(app_id+':experiments',exp_uid,'num_reported_answers_for_'+alg_uid)

      # 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)

      targets,didSucceed,message = db.get(app_id+':queries',query_uid,'target_indices')
      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']

      index_winner = args_dict['index_winner']

      # update query doc
      timestamp_query_generated,didSucceed,message = db.get(app_id+':queries',query_uid,'timestamp_query_generated')
      datetime_query_generated = utils.str2datetime(timestamp_query_generated)
      timestamp_answer_received = args_dict.get('meta',{}).get('timestamp_answer_received',None)
      if timestamp_answer_received == None:
        datetime_answer_received = datetime_query_generated
      else:
        datetime_answer_received = utils.str2datetime(timestamp_answer_received)
      delta_datetime = datetime_answer_received - datetime_query_generated
      round_trip_time = delta_datetime.seconds + delta_datetime.microseconds/1000000.
      response_time = float(args_dict.get('response_time',0.))
      db.set(app_id+':queries',query_uid,'response_time',response_time)
      db.set(app_id+':queries',query_uid,'network_delay',round_trip_time-response_time)
      db.set(app_id+':queries',query_uid,'index_winner',index_winner)
      q = [index_left,index_right,index_center]
      if index_winner==index_right:
        q = [index_right,index_left,index_center]
      db.set(app_id+':queries',query_uid,'q',q)

      # call processAnswer
      didSucceed,dt = utils.timeit(alg.processAnswer)(resource=rc,index_center=index_center,index_left=index_left,index_right=index_right,index_winner=index_winner)

      log_entry_durations = { 'exp_uid':exp_uid,'alg_uid':alg_uid,'task':'processAnswer','duration':dt } 
      log_entry_durations.update( rc.getDurations() )
      meta = {'log_entry_durations':log_entry_durations}

      
      # check if we're going to evaluate this loss
      n,didSucceed,message = db.get(app_id+':experiments',exp_uid,'n')
      
      if num_reported_answers % ((n+4)/4) == 0:
#.........这里部分代码省略.........
开发者ID:NandanaSengupta,项目名称:NEXT,代码行数:101,代码来源:PoolBasedTripletMDS.py



注:本文中的next.utils.timeit函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.DBSession类代码示例发布时间:2022-05-27
下一篇:
Python utils.datetimeNow函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap