code: def update_stats(stats, start_time, data):
      '''
      Calculate the master stats and return the updated stat info
      '''
      end_time = time.time()
      cmd = data['cmd']
      # the jid is used as the create time
      try:
          jid = data['jid']
      except KeyError:
          try:
              jid = data['data']['__pub_jid']
          except KeyError:
              log.info('jid not found in data, stats not updated')
              return stats
      create_time = int(time.mktime(time.strptime(jid, '%Y%m%d%H%M%S%f')))
      latency = start_time - create_time
      duration = end_time - start_time
  
      stats[cmd]['runs'] += 1
      stats[cmd]['latency'] = (stats[cmd]['latency'] * (stats[cmd]['runs'] - 1) + latency) / stats[cmd]['runs']
      stats[cmd]['mean'] = (stats[cmd]['mean'] * (stats[cmd]['runs'] - 1) + duration) / stats[cmd]['runs']
  
      return statf update_stats(stats, start_time, data):
      '''
      Calculate the master stats and return the updated stat info
      '''
      end_time = time.time()
      cmd = data['cmd']
      # the jid is used as the create time
      try:
          jid = data['jid']
      except KeyError:
          try:
              jid = data['data']['__pub_jid']
          except KeyError:
              log.info('jid not found in data, stats not updated')
              return stats
      create_time = int(time.mktime(time.strptime(jid, '%Y%m%d%H%M%S%f')))
      latency = start_time - create_time
      duration = end_time - start_time
  
      stats[cmd]['runs'] += 1
      stats[cmd]['latency'] = (stats[cmd]['latency'] * (stats[cmd]['runs'] - 1) + latency) / stats[cmd]['runs']
      stats[cmd]['mean'] = (stats[cmd]['mean'] * (stats[cmd]['runs'] - 1) + duration) / stats[cmd]['runs']
  
      return stats
docs: Calculate the master stats and return the updated stat info