hashrate display units improvement
authorForrest Voight <forrest@forre.st>
Mon, 25 Jul 2011 17:57:45 +0000 (13:57 -0400)
committerForrest Voight <forrest@forre.st>
Mon, 25 Jul 2011 17:57:45 +0000 (13:57 -0400)
p2pool/main.py
p2pool/util/math.py

index 5f202a4..0ec9c34 100644 (file)
@@ -485,11 +485,11 @@ def main(args):
                         att_s = p2pool.get_pool_attempts_per_second(tracker, current_work.value['best_share_hash'], args.net)
                         weights, total_weight = tracker.get_cumulative_weights(current_work.value['best_share_hash'], min(height, 1000), 2**100)
                         count = counter(current_work.value['best_share_hash'], height, 2**100)
-                        print 'Pool: %i mhash/s in %i shares Recent: %.02f%% >%i mhash/s Known: %i shares (so %i stales)' % (
-                            att_s//1000000,
+                        print 'Pool: %sH/s in %i shares Recent: %.02f%% >%sH/s Known: %i shares (so %i stales)' % (
+                            math.format(att_s),
                             height,
                             weights.get(my_script, 0)/total_weight*100,
-                            weights.get(my_script, 0)/total_weight*att_s//1000000,
+                            math.format(weights.get(my_script, 0)/total_weight*att_s),
                             count,
                             len(my_shares) - count,
                         )
index 07a631a..84e2baa 100644 (file)
@@ -54,3 +54,19 @@ def add_dicts(dicts):
         for k, v in d.iteritems():
             res[k] = res.get(k, 0) + v
     return dict((k, v) for k, v in res.iteritems() if v)
+
+def format(x):
+    prefixes = "kMGTPEZY"
+    count = 0
+    while x >= 10000 and count < len(prefixes) - 2:
+        x = x//1000
+        count += 1
+    s = "" if count == 0 else prefixes[count - 1]
+    return "%i" % (x,) + s
+
+if __name__ == "__main__":
+    import random
+    a = 1
+    while True:
+        print a, format(a) + "H/s"
+        a = a * random.randrange(2, 5)