'last_day': graph.DataViewDescription(300, 60*60*24),
'last_week': graph.DataViewDescription(300, 60*60*24*7),
'last_month': graph.DataViewDescription(300, 60*60*24*30),
+ 'last_year': graph.DataViewDescription(300, 60*60*24*365.25),
}
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),
+ 'current_payout': graph.DataStreamDescription(True, dataview_descriptions),
}, hd_obj)
def _atomic_write(filename, data):
open(filename + '.new', 'w').write(data)
t = time.time()
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)
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'))
<body>
<h1>P2Pool Graphs</h1>
- <h2>Local rate - Blue=All, Red=Dead</h2>
+ <p>Periods: <span id="period_chooser"></span> Current: <span id="period_current"></span></p>
- <h3>Last hour</h3>
- <div id="local_hour"></div>
+ <h2>Local rate - Blue=All, Red=Dead (hash/second)</h2>
+ <svg id="local"></svg>
- <h3>Last day</h3>
- <div id="local_day"></div>
+ <h2>Current payout (BTC)</h2>
+ <svg id="payout"></svg>
- <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>
+ <h2>Pool rate - Blue=All, Red=Stale (hash/second)</h2>
+ <svg id="pool"></svg>
<script type="text/javascript">
+ function compose() {
+ var funcs = arguments;
+ return function(x) {
+ for(var i = funcs.length-1; i >= 0; i--) {
+ x = funcs[i](x);
+ }
+ return x;
+ }
+ }
+ function itemgetter(i) { return function(x) { return x[i]; } }
+ function as_date(x) { return new Date(1000*x); }
+ function not_null(x) { return x != null; }
+
function getData(url) {
- xmlhttp = new XMLHttpRequest();
+ var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", url, false);
xmlhttp.send();
- var data = JSON.parse(xmlhttp.responseText);
-
- return data;
+ return JSON.parse(xmlhttp.responseText);
}
- function plot(e, blue, red) {
- data = getData("/web/graph_data/" + blue);
- dead_data = getData("/web/graph_data/" + red);
+ function plot(g, blue, red) {
+ var data = getData("/web/graph_data/" + blue);
+ if(red)
+ var dead_data = getData("/web/graph_data/" + red);
+ else
+ var dead_data = [];
var w = 640;
var h = 300;
var margin = 50;
-
- function itemgetter(i) {
- return function(x) {
- return x[i];
- }
- }
- function as_date(x) {
- return new Date(1000*x);
- }
+ var margin_top = 10;
var x = d3.time.scale().domain([as_date(d3.min(data, itemgetter(0))), as_date(d3.max(data, itemgetter(0)))]).range([0 + margin * 2, w - margin * 2]);
- var y = d3.scale.linear().domain([0, d3.max(data, itemgetter(1))]).range([h - margin, margin]);
+ var y = d3.scale.linear().domain([0, d3.max(data, itemgetter(1))]).range([h - margin, margin_top]);
- var line = d3.svg.line().x(function(d, i) { return x(as_date(d[0])); }).y(function(d) { return y(d[1]); }).defined(function(d) { return d[1] != null; });
+ var line = d3.svg.line().x(compose(x, as_date, itemgetter(0))).y(compose(y, itemgetter(1))).defined(compose(not_null, itemgetter(1)));
- e.selectAll("svg").remove();
- var g = e.insert("svg:svg").attr("width", w).attr("height", h);
+ g.attr("width", w).attr("height", h);
+ g.selectAll("*").remove();
g.append("svg:path")
.attr("d", line(data))
.attr("class", "rate");
- g.append("svg:path")
- .attr("d", line(dead_data))
- .attr("class", "deadrate");
+ if(dead_data)
+ g.append("svg:path")
+ .attr("d", line(dead_data))
+ .attr("class", "deadrate");
g.append("svg:line")
.append("svg:text")
.attr("transform", "rotate(45)")
.attr("text-anchor", "middle")
+ .attr("dominant-baseline", "central")
.text(x.tickFormat(13));
g.selectAll()
.attr("x1", margin * 2)
.attr("y1", h - margin)
.attr("x2", margin * 2)
- .attr("y2", margin);
+ .attr("y2", margin_top);
g.selectAll()
- .data(y.ticks(18))
+ .data(y.ticks(6))
.enter().append("svg:line")
.attr("x1", margin * 2 - 5)
.attr("y1", y)
.enter().append("svg:text")
.text(d3.format(".3s"))
.attr("x", margin - 2.5)
- .attr("y", function(d) { return y(d) + 4; })
+ .attr("y", y)
+ .attr("dominant-baseline", "central")
.attr("text-anchor", "middle");
+
+ function get_avg(data) {
+ var top = 0;
+ var bottom = 0;
+ for(var i = 0; i < data.length; i++) {
+ if(data[i][1] == null) continue; // no data for bin
+ top += data[i][1] * data[i][2];
+ bottom += data[i][2];
+ }
+ if(bottom == 0) return null; // no data at all
+ return top/bottom;
+ }
+
+ var mean = get_avg(data);
+ if(mean != null) {
+ g.append("svg:text")
+ .text("-Mean: " + d3.format(".3s")(mean))
+ .attr("text-anchor", "start")
+ .attr("dominant-baseline", "central")
+ .attr("fill", "#0000FF")
+ .attr("x", w - 2*margin)
+ .attr("y", y(mean));
+ }
+
+ var mean2 = get_avg(dead_data);
+ if(mean2 != null) {
+ g.append("svg:text")
+ .text("-Mean: " + d3.format(".3s")(mean2))
+ .attr("text-anchor", "start")
+ .attr("dominant-baseline", "central")
+ .attr("fill", "#FF0000")
+ .attr("x", w - 2*margin)
+ .attr("y", y(mean2));
+ }
}
function attachGraph(e, blue, red) {
plot(e, blue, red);
- setInterval(function() { plot(e, blue, red); }, 5000);
+ //setInterval(function() { plot(e, blue, red); }, 5000);
}
- 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]);
+ periods = ["Hour", "Day", "Week", "Month", "Year"];
+ d3.select("#period_chooser").selectAll().data(periods).enter().append("span")
+ .text(function(x){return x;})
+ .on("click", change_period)
+ .attr("style", function(d, i) { return (i == 0 ? "" : "margin-left:.4em;") + "color:blue;text-decoration:underline;cursor:pointer" });
+ function change_period(period) {
+ var lowerperiod = period.toLowerCase();
+ attachGraph(d3.select("#local"), "local_hash_rate/last_" + lowerperiod, "local_dead_hash_rate/last_" + lowerperiod);
+ attachGraph(d3.select("#payout"), "current_payout/last_" + lowerperiod);
+ attachGraph(d3.select("#pool"), "pool_rate/last_" + lowerperiod, "pool_stale_rate/last_" + lowerperiod);
+ d3.select("#period_current").text(period);
}
+ change_period(periods[1]);
</script>
</body>
</html>