display links to found shares in share explorer
[p2pool.git] / p2pool / web.py
index 7bc9240..4400e7d 100644 (file)
@@ -323,6 +323,7 @@ def get_web_root(wb, datadir_path, bitcoind_getinfo_var, stop_event=variable.Eve
     new_root.putChild('tails', WebInterface(lambda: ['%064x' % x for t in node.tracker.tails for x in node.tracker.reverse.get(t, set())]))
     new_root.putChild('verified_tails', WebInterface(lambda: ['%064x' % x for t in node.tracker.verified.tails for x in node.tracker.verified.reverse.get(t, set())]))
     new_root.putChild('best_share_hash', WebInterface(lambda: '%064x' % node.best_share_var.value))
+    new_root.putChild('my_share_hashes', WebInterface(lambda: ['%064x' % my_share_hash for my_share_hash in wb.my_share_hashes]))
     def get_share_data(share_hash_str):
         if int(share_hash_str, 16) not in node.tracker.items:
             return ''
@@ -355,19 +356,17 @@ def get_web_root(wb, datadir_path, bitcoind_getinfo_var, stop_event=variable.Eve
     hd = graph.HistoryDatabase.from_obj({
         'local_hash_rate': graph.DataStreamDescription(dataview_descriptions, is_gauge=False),
         'local_dead_hash_rate': graph.DataStreamDescription(dataview_descriptions, is_gauge=False),
-        'local_share_hash_rate': graph.DataStreamDescription(dataview_descriptions, is_gauge=False),
-        'local_dead_share_hash_rate': graph.DataStreamDescription(dataview_descriptions, is_gauge=False),
-        'local_orphan_share_hash_rate': graph.DataStreamDescription(dataview_descriptions, is_gauge=False),
+        'local_share_hash_rates': graph.DataStreamDescription(dataview_descriptions, is_gauge=False,
+            multivalues=True, multivalue_undefined_means_0=True,
+            default_func=graph.make_multivalue_migrator(dict(good='local_share_hash_rate', dead='local_dead_share_hash_rate', orphan='local_orphan_share_hash_rate'),
+                post_func=lambda bins: [dict((k, (v[0] - (sum(bin.get(rem_k, (0, 0))[0] for rem_k in ['dead', 'orphan']) if k == 'good' else 0), v[1])) for k, v in bin.iteritems()) for bin in bins])),
         'pool_rates': graph.DataStreamDescription(dataview_descriptions, multivalues=True,
             multivalue_undefined_means_0=True),
         'current_payout': graph.DataStreamDescription(dataview_descriptions),
         'current_payouts': graph.DataStreamDescription(dataview_descriptions, multivalues=True),
-        'incoming_peers': graph.DataStreamDescription(dataview_descriptions),
-        'outgoing_peers': graph.DataStreamDescription(dataview_descriptions),
+        'peers': graph.DataStreamDescription(dataview_descriptions, multivalues=True, default_func=graph.make_multivalue_migrator(dict(incoming='incoming_peers', outgoing='outgoing_peers'))),
         'miner_hash_rates': graph.DataStreamDescription(dataview_descriptions, is_gauge=False, multivalues=True),
         'miner_dead_hash_rates': graph.DataStreamDescription(dataview_descriptions, is_gauge=False, multivalues=True),
-        'desired_versions': graph.DataStreamDescription(dataview_descriptions, multivalues=True,
-            multivalue_undefined_means_0=True),
         'desired_version_rates': graph.DataStreamDescription(dataview_descriptions, multivalues=True,
             multivalue_undefined_means_0=True),
         'traffic_rate': graph.DataStreamDescription(dataview_descriptions, is_gauge=False, multivalues=True),
@@ -390,18 +389,19 @@ def get_web_root(wb, datadir_path, bitcoind_getinfo_var, stop_event=variable.Eve
     @wb.share_received.watch
     def _(work, dead, share_hash):
         t = time.time()
-        hd.datastreams['local_share_hash_rate'].add_datum(t, work)
-        if dead:
-            hd.datastreams['local_dead_share_hash_rate'].add_datum(t, work)
+        if not dead:
+            hd.datastreams['local_share_hash_rates'].add_datum(t, dict(good=work))
+        else:
+            hd.datastreams['local_share_hash_rates'].add_datum(t, dict(dead=work))
         def later():
             res = node.tracker.is_child_of(share_hash, node.best_share_var.value)
-            if res is None: return # share isn't connected to sharechain?
+            if res is None: res = False # share isn't connected to sharechain? assume orphaned
             if res and dead: # share was DOA, but is now in sharechain
-                # remove from DOA graph
-                hd.datastreams['local_dead_share_hash_rate'].add_datum(t, -work)
+                # move from dead to good
+                hd.datastreams['local_share_hash_rates'].add_datum(t, dict(dead=-work, good=work))
             elif not res and not dead: # share wasn't DOA, and isn't in sharechain
-                # add to orphan graph
-                hd.datastreams['local_orphan_share_hash_rate'].add_datum(t, work)
+                # move from good to orphan
+                hd.datastreams['local_share_hash_rates'].add_datum(t, dict(good=-work, orphan=work))
         reactor.callLater(200, later)
     @node.p2p_node.traffic_happened.watch
     def _(name, bytes):
@@ -422,12 +422,13 @@ def get_web_root(wb, datadir_path, bitcoind_getinfo_var, stop_event=variable.Eve
         current_txouts_by_address = dict((bitcoin_data.script2_to_address(script, node.net.PARENT), amount) for script, amount in current_txouts.iteritems())
         hd.datastreams['current_payouts'].add_datum(t, dict((user, current_txouts_by_address[user]*1e-8) for user in miner_hash_rates if user in current_txouts_by_address))
         
-        hd.datastreams['incoming_peers'].add_datum(t, sum(1 for peer in node.p2p_node.peers.itervalues() if peer.incoming))
-        hd.datastreams['outgoing_peers'].add_datum(t, sum(1 for peer in node.p2p_node.peers.itervalues() if not peer.incoming))
+        hd.datastreams['peers'].add_datum(t, dict(
+            incoming=sum(1 for peer in node.p2p_node.peers.itervalues() if peer.incoming),
+            outgoing=sum(1 for peer in node.p2p_node.peers.itervalues() if not peer.incoming),
+        ))
         
         vs = p2pool_data.get_desired_version_counts(node.tracker, node.best_share_var.value, lookbehind)
         vs_total = sum(vs.itervalues())
-        hd.datastreams['desired_versions'].add_datum(t, dict((str(k), v/vs_total) for k, v in vs.iteritems()))
         hd.datastreams['desired_version_rates'].add_datum(t, dict((str(k), v/vs_total*pool_total) for k, v in vs.iteritems()))
         try:
             hd.datastreams['memory_usage'].add_datum(t, memory.resident())