use mean instead of median for stale proportion calculation
authorForrest Voight <forrest.voight@gmail.com>
Tue, 27 Dec 2011 07:07:08 +0000 (02:07 -0500)
committerForrest Voight <forrest.voight@gmail.com>
Tue, 27 Dec 2011 07:07:08 +0000 (02:07 -0500)
p2pool/main.py
p2pool/util/math.py

index 2348e1b..802075d 100644 (file)
@@ -553,7 +553,7 @@ def main(args, net, datadir_path):
                 height, last = tracker.get_height_and_last(current_work.value['best_share_hash'])
                 att_s = p2pool_data.get_pool_attempts_per_second(tracker, current_work.value['best_share_hash'], min(height - 1, 720))
                 fracs = [share.stale_frac for share in tracker.get_chain(current_work.value['best_share_hash'], min(120, height)) if share.stale_frac is not None]
-                return json.dumps(int(att_s / (1. - (math.median(fracs) if fracs else 0))))
+                return json.dumps(int(att_s / (1. - (math.mean(fracs) if fracs else 0))))
             return json.dumps(None)
         
         def get_users():
@@ -617,7 +617,7 @@ def main(args, net, datadir_path):
                             weights, total_weight, donation_weight = tracker.get_cumulative_weights(current_work.value['best_share_hash'], min(height, 720), 65535*2**256)
                             (stale_orphan_shares, stale_doa_shares), shares = get_stale_counts()
                             fracs = [share.stale_frac for share in tracker.get_chain(current_work.value['best_share_hash'], min(120, height)) if share.stale_frac is not None]
-                            real_att_s = att_s / (1. - (math.median(fracs) if fracs else 0))
+                            real_att_s = att_s / (1. - (math.mean(fracs) if fracs else 0))
                             my_att_s = real_att_s*weights.get(my_script, 0)/total_weight
                             this_str = 'Pool: %sH/s in %i shares (%i/%i verified) Recent: %.02f%% >%sH/s Shares: %i (%i orphan, %i dead) Peers: %i' % (
                                 math.format(int(real_att_s)),
@@ -635,7 +635,7 @@ def main(args, net, datadir_path):
                                 2**256 / current_work.value['bits'].target / real_att_s / (60 * 60 * 24),
                             )
                             if fracs:
-                                med = math.median(fracs)
+                                med = math.mean(fracs)
                                 this_str += '\nPool stales: %i%%' % (int(100*med+.5),)
                                 conf = 0.95
                                 if shares:
index 3cea2e4..00567e8 100644 (file)
@@ -17,6 +17,14 @@ def median(x, use_float=True):
     else:
         return sum//2
 
+def mean(x):
+    total = 0
+    count = 0
+    for y in x:
+        total += y
+        count += 1
+    return total/count
+
 def shuffled(x):
     x = list(x)
     random.shuffle(x)