added peer count graph
[p2pool.git] / p2pool / web.py
index d7c6332..59c32d7 100644 (file)
@@ -142,6 +142,8 @@ def get_web_root(tracker, current_work, current_work2, get_current_txouts, datad
             if datum['dead']:
                 miner_dead_hash_rates[datum['user']] = miner_dead_hash_rates.get(datum['user'], 0) + datum['work']/dt
         
+        (stale_orphan_shares, stale_doa_shares), shares, _ = get_stale_counts()
+        
         return json.dumps(dict(
             my_hash_rates_in_last_hour=dict(
                 note="DEPRECATED",
@@ -163,6 +165,7 @@ def get_web_root(tracker, current_work, current_work2, get_current_txouts, datad
             ),
             miner_hash_rates=miner_hash_rates,
             miner_dead_hash_rates=miner_dead_hash_rates,
+            efficiency_if_miner_perfect=(1 - stale_orphan_shares/shares)/(1 - global_stale_prop) if shares else None, # ignores dead shares because those are miner's fault and indicated by pseudoshare rejection
         ))
     
     def get_peer_addresses():
@@ -386,6 +389,8 @@ def get_web_root(tracker, current_work, current_work2, get_current_txouts, datad
         'pool_rate': graph.DataStreamDescription(True, dataview_descriptions),
         'pool_stale_rate': graph.DataStreamDescription(True, dataview_descriptions),
         'current_payout': graph.DataStreamDescription(True, dataview_descriptions),
+        'incoming_peers': graph.DataStreamDescription(True, dataview_descriptions),
+        'outgoing_peers': graph.DataStreamDescription(True, dataview_descriptions),
     }, hd_obj)
     task.LoopingCall(lambda: _atomic_write(hd_path, json.dumps(hd.to_obj()))).start(100)
     @pseudoshare_received.watch
@@ -403,6 +408,8 @@ def get_web_root(tracker, current_work, current_work2, get_current_txouts, datad
         hd.datastreams['pool_rate'].add_datum(t, poolrate)
         hd.datastreams['pool_stale_rate'].add_datum(t, poolrate - nonstalerate)
         hd.datastreams['current_payout'].add_datum(t, get_current_txouts().get(bitcoin_data.pubkey_hash_to_script2(my_pubkey_hash), 0)*1e-8)
+        hd.datastreams['incoming_peers'].add_datum(t, sum(1 for peer in p2p_node.peers.itervalues() if peer.incoming))
+        hd.datastreams['outgoing_peers'].add_datum(t, sum(1 for peer in p2p_node.peers.itervalues() if not peer.incoming))
     task.LoopingCall(add_point).start(5)
     new_root.putChild('graph_data', WebInterface(lambda source, view: json.dumps(hd.datastreams[source].dataviews[view].get_data(time.time())), 'application/json'))