stats flake8 fixes

This commit is contained in:
lakshyacis 2019-09-10 19:44:44 +05:30
parent 8182e159df
commit 7d0bd1cf7a
No known key found for this signature in database
GPG Key ID: D2C539C8EC63E9EB
1 changed files with 23 additions and 15 deletions

View File

@ -4,6 +4,7 @@ import asyncore_pollchoose as asyncore
from network.connectionpool import BMConnectionPool from network.connectionpool import BMConnectionPool
from objectracker import missingObjects from objectracker import missingObjects
lastReceivedTimestamp = time.time() lastReceivedTimestamp = time.time()
lastReceivedBytes = 0 lastReceivedBytes = 0
currentReceivedSpeed = 0 currentReceivedSpeed = 0
@ -11,6 +12,7 @@ lastSentTimestamp = time.time()
lastSentBytes = 0 lastSentBytes = 0
currentSentSpeed = 0 currentSentSpeed = 0
def connectedHostsList(): def connectedHostsList():
retval = [] retval = []
for i in BMConnectionPool().inboundConnections.values() + \ for i in BMConnectionPool().inboundConnections.values() + \
@ -23,9 +25,11 @@ def connectedHostsList():
pass pass
return retval return retval
def sentBytes(): def sentBytes():
return asyncore.sentBytes return asyncore.sentBytes
def uploadSpeed(): def uploadSpeed():
global lastSentTimestamp, lastSentBytes, currentSentSpeed global lastSentTimestamp, lastSentBytes, currentSentSpeed
currentTimestamp = time.time() currentTimestamp = time.time()
@ -36,35 +40,39 @@ def uploadSpeed():
lastSentTimestamp = currentTimestamp lastSentTimestamp = currentTimestamp
return currentSentSpeed return currentSentSpeed
def receivedBytes(): def receivedBytes():
return asyncore.receivedBytes return asyncore.receivedBytes
def downloadSpeed(): def downloadSpeed():
global lastReceivedTimestamp, lastReceivedBytes, currentReceivedSpeed global lastReceivedTimestamp, lastReceivedBytes, currentReceivedSpeed
currentTimestamp = time.time() currentTimestamp = time.time()
if int(lastReceivedTimestamp) < int(currentTimestamp): if int(lastReceivedTimestamp) < int(currentTimestamp):
currentReceivedBytes = asyncore.receivedBytes currentReceivedBytes = asyncore.receivedBytes
currentReceivedSpeed = int((currentReceivedBytes - lastReceivedBytes) / currentReceivedSpeed = int(
(currentTimestamp - lastReceivedTimestamp)) (currentReceivedBytes - lastReceivedBytes) / (currentTimestamp - lastReceivedTimestamp))
lastReceivedBytes = currentReceivedBytes lastReceivedBytes = currentReceivedBytes
lastReceivedTimestamp = currentTimestamp lastReceivedTimestamp = currentTimestamp
return currentReceivedSpeed return currentReceivedSpeed
def pendingDownload(): def pendingDownload():
return len(missingObjects) return len(missingObjects)
#tmp = {} # tmp = {}
#for connection in BMConnectionPool().inboundConnections.values() + \ # for connection in BMConnectionPool().inboundConnections.values() + \
# BMConnectionPool().outboundConnections.values(): # BMConnectionPool().outboundConnections.values():
# for k in connection.objectsNewToMe.keys(): # for k in connection.objectsNewToMe.keys():
# tmp[k] = True # tmp[k] = True
#return len(tmp) # return len(tmp)
def pendingUpload(): def pendingUpload():
#tmp = {} # tmp = {}
#for connection in BMConnectionPool().inboundConnections.values() + \ # for connection in BMConnectionPool().inboundConnections.values() + \
# BMConnectionPool().outboundConnections.values(): # BMConnectionPool().outboundConnections.values():
# for k in connection.objectsNewToThem.keys(): # for k in connection.objectsNewToThem.keys():
# tmp[k] = True # tmp[k] = True
#This probably isn't the correct logic so it's disabled # This probably isn't the correct logic so it's disabled
#return len(tmp) # return len(tmp)
return 0 return 0