Files
@ d76b98d421ae
Branch filter:
Location: Morevna/src/stats.py - annotation
d76b98d421ae
784 B
text/x-python
enhanced stats
41ea9614ce8c 41ea9614ce8c 41ea9614ce8c 41ea9614ce8c 41ea9614ce8c 41ea9614ce8c 41ea9614ce8c 41ea9614ce8c 41ea9614ce8c 41ea9614ce8c 41ea9614ce8c 41ea9614ce8c 41ea9614ce8c 41ea9614ce8c 41ea9614ce8c 5813971dbecc 5813971dbecc 41ea9614ce8c 41ea9614ce8c 41ea9614ce8c 41ea9614ce8c 41ea9614ce8c 41ea9614ce8c 41ea9614ce8c d76b98d421ae d76b98d421ae d76b98d421ae d76b98d421ae d76b98d421ae d76b98d421ae d76b98d421ae d76b98d421ae d76b98d421ae d76b98d421ae d76b98d421ae d76b98d421ae d76b98d421ae d76b98d421ae d76b98d421ae d76b98d421ae | class Stats:
received=0
sent=0
exchangedNodes=0
transferredBlocks=0
def logReceived(data):
Stats.received+=len(data)
def logSent(data):
Stats.sent+=len(data)
def logExchangedNode(k=1):
Stats.exchangedNodes+=k
def logTransferredBlock():
Stats.transferredBlocks+=1
def report():
return """received {rf} ({r:,} B)
sent {sf} ({s:,} B)
exchanged {nodes:,} hash tree nodes
transferred {blocks:,} blocks""".format(rf=formatBytes(Stats.received), r=Stats.received, sf=formatBytes(Stats.sent), s=Stats.sent, nodes=Stats.exchangedNodes, blocks=Stats.transferredBlocks)
def formatBytes(x):
exts=["B","kiB","MiB","GiB","TiB","PiB"]
i=0
while x>1024:
x/=1024
i+=1
if x>=100: x=round(x)
elif x>=10: x=round(x,1)
else: x=round(x,2)
return "{0} {1}".format(x,exts[i])
|