From: Forrest Voight Date: Wed, 21 Mar 2012 22:19:57 +0000 (-0400) Subject: added per-miner graphs X-Git-Tag: 0.10.2~5 X-Git-Url: https://git.novaco.in/?p=p2pool.git;a=commitdiff_plain;h=1aaec554db2a74e7a3486e250cf07d5ff2ed8680 added per-miner graphs --- diff --git a/p2pool/util/graph.py b/p2pool/util/graph.py index 2070163..66c1f99 100644 --- a/p2pool/util/graph.py +++ b/p2pool/util/graph.py @@ -27,7 +27,7 @@ class DataView(object): def _add_datum(self, t, value): shift = max(0, int(math.ceil((t - self.last_bin_end)/self.desc.bin_width))) - self.bins = _shift(self.bins, shift, (0, 0)) + self.bins = _shift(self.bins, shift, (self.ds_desc.zero_element, 0)) self.last_bin_end += shift*self.desc.bin_width bin = int(math.ceil((self.last_bin_end - self.desc.bin_width - t)/self.desc.bin_width)) @@ -36,27 +36,30 @@ class DataView(object): return prev_total, prev_count = self.bins[bin] - self.bins[bin] = prev_total + value, prev_count + 1 + self.bins[bin] = self.ds_desc.add_operator(prev_total, value), prev_count + 1 def get_data(self, t): shift = max(0, int(math.ceil((t - self.last_bin_end)/self.desc.bin_width))) - bins = _shift(self.bins, shift, (0, 0)) + bins = _shift(self.bins, shift, (self.ds_desc.zero_element, 0)) last_bin_end = self.last_bin_end + shift*self.desc.bin_width assert last_bin_end - self.desc.bin_width <= t <= last_bin_end return [( (min(t, last_bin_end - self.desc.bin_width*i) + (last_bin_end - self.desc.bin_width*(i + 1)))/2, # center time - (total/count if count else None) if self.ds_desc.source_is_cumulative - else total/(min(t, last_bin_end - self.desc.bin_width*i) - (last_bin_end - self.desc.bin_width*(i + 1))), # value + (self.ds_desc.mult_operator(1/count, total) if count else None) if self.ds_desc.source_is_cumulative + else self.ds_desc.mult_operator(1/(min(t, last_bin_end - self.desc.bin_width*i) - (last_bin_end - self.desc.bin_width*(i + 1))), total), # value min(t, last_bin_end - self.desc.bin_width*i) - (last_bin_end - self.desc.bin_width*(i + 1)), # width ) for i, (total, count) in enumerate(bins)] class DataStreamDescription(object): - def __init__(self, source_is_cumulative, dataview_descriptions): + def __init__(self, source_is_cumulative, dataview_descriptions, zero_element=0, add_operator=lambda x, y: x+y, mult_operator=lambda a, x: a*x): self.source_is_cumulative = source_is_cumulative self.dataview_descriptions = dataview_descriptions + self.zero_element = zero_element + self.add_operator = add_operator + self.mult_operator = mult_operator class DataStream(object): def __init__(self, desc, dataviews): @@ -78,7 +81,7 @@ class HistoryDatabase(object): dv_data = ds_data[dv_name] if dv_data['bin_width'] == dv_desc.bin_width and len(dv_data['bins']) == dv_desc.bin_count: return DataView(dv_desc, ds_desc, dv_data['last_bin_end'], dv_data['bins']) - return DataView(dv_desc, ds_desc, 0, dv_desc.bin_count*[(0, 0)]) + return DataView(dv_desc, ds_desc, 0, dv_desc.bin_count*[(ds_desc.zero_element, 0)]) return cls(dict( (ds_name, DataStream(ds_desc, dict( (dv_name, get_dataview(ds_name, ds_desc, dv_name, dv_desc)) diff --git a/p2pool/util/math.py b/p2pool/util/math.py index a484c04..aa5ea8a 100644 --- a/p2pool/util/math.py +++ b/p2pool/util/math.py @@ -65,6 +65,8 @@ def add_dicts(*dicts): res[k] = res.get(k, 0) + v return dict((k, v) for k, v in res.iteritems() if v) +mult_dict = lambda c, x: dict((k, c*v) for k, v in x.iteritems()) + def format(x): prefixes = 'kMGTPEZY' count = 0 diff --git a/p2pool/web.py b/p2pool/web.py index 59c32d7..acc38b3 100644 --- a/p2pool/web.py +++ b/p2pool/web.py @@ -391,6 +391,8 @@ 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), }, hd_obj) task.LoopingCall(lambda: _atomic_write(hd_path, json.dumps(hd.to_obj()))).start(100) @pseudoshare_received.watch @@ -399,6 +401,10 @@ def get_web_root(tracker, current_work, current_work2, get_current_txouts, datad hd.datastreams['local_hash_rate'].add_datum(t, work) if dead: hd.datastreams['local_dead_hash_rate'].add_datum(t, work) + if user is not None: + hd.datastreams['miner_hash_rates'].add_datum(t, {user: work}) + if dead: + hd.datastreams['miner_dead_hash_rates'].add_datum(t, {user: work}) def add_point(): if tracker.get_height(current_work.value['best_share_hash']) < 720: return diff --git a/web-static/graphs.html b/web-static/graphs.html index fe8f548..fd9b25e 100644 --- a/web-static/graphs.html +++ b/web-static/graphs.html @@ -16,14 +16,7 @@ shape-rendering: crispEdges; } - .rate { - stroke: #0000FF; - stroke-width: 1.4; - fill: none; - } - - .deadrate { - stroke: #FF0000; + .plotline { stroke-width: 1.4; fill: none; } @@ -52,6 +45,9 @@

Peers - Blue=Incoming, Red=Outgoing

+

Miners - Blue=All, Red=Dead (hash/second)

+
+