Skip to content

Commit

Permalink
added pool rate to graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
forrestv committed Mar 17, 2012
1 parent a2a8d88 commit f3b6e68
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
11 changes: 11 additions & 0 deletions p2pool/web.py
Expand Up @@ -351,6 +351,8 @@ def _(work, dead, user):
hd = graph.HistoryDatabase.from_obj({
'local_hash_rate': graph.DataStreamDescription(False, dataview_descriptions),
'local_dead_hash_rate': graph.DataStreamDescription(False, dataview_descriptions),
'pool_rate': graph.DataStreamDescription(True, dataview_descriptions),
'pool_stale_rate': graph.DataStreamDescription(True, dataview_descriptions),
}, hd_obj)
def _atomic_write(filename, data):
open(filename + '.new', 'w').write(data)
Expand All @@ -362,6 +364,15 @@ def _(work, dead, user):
hd.datastreams['local_hash_rate'].add_datum(t, work)
if dead:
hd.datastreams['local_dead_hash_rate'].add_datum(t, work)
def add_point():
if tracker.get_height(current_work.value['best_share_hash']) < 720:
return
nonstalerate = p2pool_data.get_pool_attempts_per_second(tracker, current_work.value['best_share_hash'], 720)
poolrate = nonstalerate / (1 - p2pool_data.get_average_stale_prop(tracker, current_work.value['best_share_hash'], 720))
t = time.time()
hd.datastreams['pool_rate'].add_datum(t, poolrate)
hd.datastreams['pool_stale_rate'].add_datum(t, poolrate - nonstalerate)
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'))

web_root.putChild('static', static.File(os.path.join(os.path.dirname(sys.argv[0]), 'web-static')))
Expand Down
53 changes: 35 additions & 18 deletions web-static/graphs.html
Expand Up @@ -38,17 +38,33 @@
<body>
<h1>P2Pool Graphs</h1>

<h2>Last hour</h1>
<div id="graph_hour"></div>
<h2>Local rate - Blue=All, Red=Dead</h2>

<h2>Last day</h1>
<div id="graph_day"></div>
<h3>Last hour</h3>
<div id="local_hour"></div>

<h2>Last week</h1>
<div id="graph_week"></div>
<h3>Last day</h3>
<div id="local_day"></div>

<h2>Last month</h1>
<div id="graph_month"></div>
<h3>Last week</h3>
<div id="local_week"></div>

<h3>Last month</h3>
<div id="local_month"></div>

<h2>Pool rate - Blue=All, Red=Stale</h2>

<h3>Last hour</h3>
<div id="pool_hour"></div>

<h3>Last day</h3>
<div id="pool_day"></div>

<h3>Last week</h3>
<div id="pool_week"></div>

<h3>Last month</h3>
<div id="pool_month"></div>

<script type="text/javascript">
function getData(url) {
Expand All @@ -60,9 +76,9 @@ <h2>Last month</h1>
return data;
}

function plot(e, url) {
data = getData("/web/graph_data/local_hash_rate/" + url);
dead_data = getData("/web/graph_data/local_dead_hash_rate/" + url);
function plot(e, blue, red) {
data = getData("/web/graph_data/" + blue);
dead_data = getData("/web/graph_data/" + red);

var w = 640;
var h = 300;
Expand Down Expand Up @@ -141,15 +157,16 @@ <h2>Last month</h1>
.attr("text-anchor", "middle");
}

function attachGraph(e, url) {
plot(e, url);
//setInterval(function() { plot(e, url); }, 5000);
function attachGraph(e, blue, red) {
plot(e, blue, red);
setInterval(function() { plot(e, blue, red); }, 5000);
}

attachGraph(d3.select("#graph_hour"), "last_hour");
attachGraph(d3.select("#graph_day"), "last_day");
attachGraph(d3.select("#graph_week"), "last_week");
attachGraph(d3.select("#graph_month"), "last_month");
periods = ["hour", "day", "week", "month"];
for(i = 0; i < periods.length; i++) {
attachGraph(d3.select("#local_" + periods[i]), "local_hash_rate/last_" + periods[i], "local_dead_hash_rate/last_" + periods[i]);
attachGraph(d3.select("#pool_" + periods[i]), "pool_rate/last_" + periods[i], "pool_stale_rate/last_" + periods[i]);
}
</script>
</body>
</html>

0 comments on commit f3b6e68

Please sign in to comment.