From 6b79c1b2b41c72915ebc4539aaf60ab6b91d97c0 Mon Sep 17 00:00:00 2001 From: Forrest Voight Date: Wed, 21 Mar 2012 18:53:48 -0400 Subject: [PATCH] made new graphs work without vip password by only preserving 30 highest usernames per bin. removed vip password display. --- p2pool/main.py | 3 +-- p2pool/web.py | 16 +++++++++++----- web-static/graphs.html | 11 ++++------- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/p2pool/main.py b/p2pool/main.py index 5694ad1..bd2fa7e 100644 --- a/p2pool/main.py +++ b/p2pool/main.py @@ -407,7 +407,6 @@ def main(args, net, datadir_path, merged_urls, worker_endpoint): vip_pass = '%016x' % (random.randrange(2**64),) with open(os.path.join(datadir_path, 'vip_pass'), 'wb') as f: f.write(vip_pass) - print ' Worker password:', vip_pass, '(only required for generating graphs)' # setup worker logic @@ -678,7 +677,7 @@ def main(args, net, datadir_path, merged_urls, worker_endpoint): else: received_header_hashes.add(header_hash) - pseudoshare_received.happened(bitcoin_data.target_to_average_attempts(target), not on_time, request.getUser() if request.getPassword() == vip_pass else None) + pseudoshare_received.happened(bitcoin_data.target_to_average_attempts(target), not on_time, request.getUser(), request.getPassword() == vip_pass) self.recent_shares_ts_work.append((time.time(), bitcoin_data.target_to_average_attempts(target))) while len(self.recent_shares_ts_work) > 50: self.recent_shares_ts_work.pop(0) diff --git a/p2pool/web.py b/p2pool/web.py index acc38b3..d6d33ec 100644 --- a/p2pool/web.py +++ b/p2pool/web.py @@ -363,9 +363,9 @@ def get_web_root(tracker, current_work, current_work2, get_current_txouts, datad grapher.add_poolrate_point(poolrate, poolrate - nonstalerate) task.LoopingCall(add_point).start(100) @pseudoshare_received.watch - def _(work, dead, user): + def _(work, dead, user, had_vip_pass): reactor.callLater(1, grapher.add_localrate_point, work, dead) - if user is not None: + if user is not None and had_vip_pass: reactor.callLater(1, grapher.add_localminer_point, user, work, dead) hd_path = os.path.join(datadir_path, 'graph_db') @@ -383,6 +383,12 @@ def get_web_root(tracker, current_work, current_work2, get_current_txouts, datad 'last_month': graph.DataViewDescription(300, 60*60*24*30), 'last_year': graph.DataViewDescription(300, 60*60*24*365.25), } + def combine_and_keep_largest(*dicts): + res = {} + for d in dicts: + for k, v in d.iteritems(): + res[k] = res.get(k, 0) + v + return dict((k, v) for k, v in sorted(res.iteritems(), key=lambda (k, v): v)[-30:] if v) hd = graph.HistoryDatabase.from_obj({ 'local_hash_rate': graph.DataStreamDescription(False, dataview_descriptions), 'local_dead_hash_rate': graph.DataStreamDescription(False, dataview_descriptions), @@ -391,12 +397,12 @@ def get_web_root(tracker, current_work, current_work2, get_current_txouts, datad 'current_payout': graph.DataStreamDescription(True, dataview_descriptions), 'incoming_peers': graph.DataStreamDescription(True, dataview_descriptions), 'outgoing_peers': graph.DataStreamDescription(True, dataview_descriptions), - 'miner_hash_rates': graph.DataStreamDescription(False, dataview_descriptions, {}, math.add_dicts, math.mult_dict), - 'miner_dead_hash_rates': graph.DataStreamDescription(False, dataview_descriptions, {}, math.add_dicts, math.mult_dict), + 'miner_hash_rates': graph.DataStreamDescription(False, dataview_descriptions, {}, combine_and_keep_largest, math.mult_dict), + 'miner_dead_hash_rates': graph.DataStreamDescription(False, dataview_descriptions, {}, combine_and_keep_largest, math.mult_dict), }, hd_obj) task.LoopingCall(lambda: _atomic_write(hd_path, json.dumps(hd.to_obj()))).start(100) @pseudoshare_received.watch - def _(work, dead, user): + def _(work, dead, user, had_vip_pass): t = time.time() hd.datastreams['local_hash_rate'].add_datum(t, work) if dead: diff --git a/web-static/graphs.html b/web-static/graphs.html index fd9b25e..649b3fb 100644 --- a/web-static/graphs.html +++ b/web-static/graphs.html @@ -199,14 +199,11 @@ var userlist = []; for(var u in users) userlist.push(u); d3.select("#miners").selectAll("*").remove(); var div = d3.select("#miners").selectAll().data(userlist).enter().append("div"); - d.append("h3").text(identity); - d.append("svg:svg").each(function(u) { - function f(d) { - return u in d ? d[u] : 0; - } + div.append("h3").text(identity); + div.append("svg:svg").each(function(u) { plot(d3.select(this), [ - {"data": data, "value_getter": f, "color": "#0000FF"}, - {"data": dead_data, "value_getter": f, "color": "#FF0000"} + {"data": data, "value_getter": function(d) { return u in d ? d[u] : 0; }, "color": "#0000FF"}, + {"data": dead_data, "value_getter": function(d) { return u in d ? d[u] : 0; }, "color": "#FF0000"} ]); }); } -- 1.7.1