Changeset - d76b98d421ae
[Not reviewed]
default
0 1 0
Laman - 7 years ago 2017-10-26 00:18:10

enhanced stats
1 file changed with 16 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/stats.py
Show inline comments
 
@@ -22,7 +22,19 @@ def logTransferredBlock():
 

	
 

	
 
def report():
 
	return """received {r}B
 
sent {s}B
 
exchanged {nodes} hash tree nodes
 
transferred {blocks} blocks""".format(r=Stats.received, s=Stats.sent, nodes=Stats.exchangedNodes, blocks=Stats.transferredBlocks)
 
	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])
0 comments (0 inline, 0 general)