# HG changeset patch # User Laman # Date 2017-10-26 00:18:10 # Node ID d76b98d421aecd9dbf8a541e39de402da713c6c2 # Parent 75e070b6b4476c4e4f2a4f4d3446b3e8500b8caf enhanced stats diff --git a/src/stats.py b/src/stats.py --- a/src/stats.py +++ b/src/stats.py @@ -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])