

def get_counters(self, name=None, agent=None):
    'See :func:`burpui.misc.backend.interface.BUIbackend.get_counters`'
    ret = {
        
    }
    if agent:
        if ((not name) or (name not in self.running[agent])):
            return ret
    elif ((not name) or (name not in self.running)):
        return ret
    query = self.status('c:{0}\n'.format(name))
    if (not query):
        return ret
    try:
        client = query['clients'][0]
    except KeyError as e:
        self._logger('warning', 'Client not found')
        return ret
    if (('run_status' not in client) or (client['run_status'] != 'running')):
        return ret
    backup = None
    for back in client['backups']:
        if (('flags' in back) and ('working' in back['flags'])):
            backup = back
            break
    if (not backup):
        return ret
    single = ['bytes_estimated', 'bytes', 'bytes_received', 'bytes_sent', 'time_start', 'time_end', 'warnings', 'errors']
    translate = {
        'bytes_estimated': 'estimated_bytes',
    }
    for counter in backup['counters']:
        name = counter['name']
        if (name in translate):
            name = translate[name]
        if (counter['name'] not in single):
            ret[name] = [counter['count'], counter['changed'], counter['same'], counter['deleted'], counter['scanned']]
        else:
            ret[name] = counter['count']
    if ('bytes' not in ret):
        ret['bytes'] = 0
    if (ret.viewkeys() & {'time_start', 'estimated_bytes', 'bytes'}):
        try:
            diff = (time.time() - int(ret['time_start']))
            byteswant = int(ret['estimated_bytes'])
            bytesgot = int(ret['bytes'])
            bytespersec = (bytesgot / diff)
            bytesleft = (byteswant - bytesgot)
            ret['speed'] = bytespersec
            if (bytespersec > 0):
                timeleft = int((bytesleft / bytespersec))
                ret['timeleft'] = timeleft
            else:
                ret['timeleft'] = (- 1)
        except:
            ret['timeleft'] = (- 1)
    try:
        ret['percent'] = round(((float(ret['bytes']) / float(ret['estimated_bytes'])) * 100))
    except:
        ret['percent'] = 0
    return ret

dataset/ETHPy150Open ziirish/burp-ui/burpui/misc/backend/burp2.py Burp.get_counters/original