From 738ddc6fa98fb938e096e1c1b98639205a5370b5 Mon Sep 17 00:00:00 2001 From: Forrest Voight Date: Tue, 27 Dec 2011 02:07:08 -0500 Subject: [PATCH] use mean instead of median for stale proportion calculation --- p2pool/main.py | 6 +++--- p2pool/util/math.py | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/p2pool/main.py b/p2pool/main.py index 2348e1b..802075d 100644 --- a/p2pool/main.py +++ b/p2pool/main.py @@ -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: diff --git a/p2pool/util/math.py b/p2pool/util/math.py index 3cea2e4..00567e8 100644 --- a/p2pool/util/math.py +++ b/p2pool/util/math.py @@ -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) -- 1.7.1