1 <?xml version="1.0" encoding="UTF-8"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
5 <title>P2Pool Graphs</title>
6 <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
7 <script type="text/javascript" src="d3.v2.min.js"></script>
9 <style type="text/css">
13 shape-rendering: crispEdges;
22 font-family: Sans-serif;
29 <h1><a href=".">P2Pool</a> > Graphs</h1>
31 <p>Periods: <span id="period_chooser"></span> Current: <span id="period_current"></span></p>
33 <div id="warnings"></div>
36 <svg id="local"></svg>
38 <h2>Local rate reflected in shares</h2>
39 <svg id="local_shares"></svg>
41 <h2>Current payout to default address</h2>
42 <svg id="payout"></svg>
48 <svg id="peers"></svg>
51 <div id="miners"></div>
53 <h2>Desired version rates</h2>
54 <svg id="desired_version_rates"></svg>
57 <svg id="traffic_rate"></svg>
59 <h2>Bitcoind GetBlockTemplate Latency</h2>
60 <svg id="getwork_latency"></svg>
63 <svg id="memory_usage"></svg>
65 <script type="text/javascript">
67 var funcs = arguments;
69 for(var i = funcs.length-1; i >= 0; i--) {
75 function itemgetter(i) { return function(x) { return x[i]; } }
76 function as_date(x) { return new Date(1000*x); }
77 function not_null(x) { return x != null; }
78 var cloneOf = (function() {
86 function get_area_mean(data) {
89 for(var i = 0; i < data.length; i++) {
90 if(data[i][1] == null) continue; // no data for bin
91 top += data[i][1] * data[i][2];
94 return {"area": top, "mean": bottom==0?null:top/bottom};
97 function plot(g, unit, total_unit, lines, stack, proportion_view) {
98 // lines is a list of objects which have attributes data, color, and label
100 var orig_unit = unit;
101 var orig_total_unit = total_unit;
102 var orig_lines = lines;
103 if(proportion_view) {
105 for(var i = 0; i < lines.length; ++i) {
107 for(var j = 0; j < line.data.length; ++j) {
108 var time_str = JSON.stringify(line.data[j][0]);
109 if(!totals.hasOwnProperty(time_str)) totals[time_str] = 0;
110 totals[time_str] += line.data[j][1];
115 for(var i = 0; i < lines.length; ++i) {
117 var new_line = cloneOf(line);
120 for(var j = 0; j < line.data.length; ++j) {
121 var time_str = JSON.stringify(line.data[j][0]);
122 new_line.data.push([line.data[j][0], totals[time_str] ? line.data[j][1]*100/totals[time_str] : null, line.data[j][2]]);
125 new_lines.push(new_line)
127 var lines = new_lines;
129 var total_unit = null;
132 var table_div = document.createElement("div");
133 g.node().parentNode.insertBefore(table_div, g.node().nextSibling);
134 table_div.style.display = "none";
136 var showhide = document.createElement("p");
137 g.node().parentNode.insertBefore(showhide, g.node().nextSibling);
138 d3.select(showhide).append("a")
139 .text('Show/hide table')
140 .on('click', function() { table_div.style.display = table_div.style.display == "block" ? "none" : "block" })
141 .attr("style", "color:blue;text-decoration:underline;cursor:pointer");
143 d3.select(showhide).append('span').text(' ');
144 d3.select(showhide).append("a")
145 .text('Switch to/from proportion view')
146 .on('click', function() {
147 table_div.parentNode.removeChild(table_div);
148 showhide.parentNode.removeChild(showhide);
149 plot(g, orig_unit, orig_total_unit, orig_lines, stack, !proportion_view);
151 .attr("style", "color:blue;text-decoration:underline;cursor:pointer");
154 for(var i = 0; i < lines.length; ++i) {
156 var table_sel = d3.select(table_div).append('table').attr('border', 1).attr('style', 'float:left');
158 var first_tr = table_sel.insert('tr');
159 first_tr.append('th').text('Date');
160 first_tr.append('th').text(line.label + '/(' + unit + ')');
163 for(var j = 0; j < line.data.length; ++j)
165 new_data.push(line.data[j]);
166 var tr = table_sel.selectAll().data(new_data).enter().append('tr');
167 tr.append('td').text(function(datum){return new Date(1000*datum[0]).toString()});
168 tr.append('td').text(function(datum){return d3.format(".3s")(datum[1])});
170 d3.select(table_div).append('div').attr('style', 'clear:both');
172 var p_after = d3.select(table_div).append('p');
174 .text('Show/hide table')
175 .on('click', function() { table_div.style.display = table_div.style.display == "block" ? "none" : "block" })
176 .attr("style", "color:blue;text-decoration:underline;cursor:pointer");
184 var x = d3.time.scale().domain([
185 as_date(d3.min(lines, function(line) { return d3.min(line.data, itemgetter(0)); })),
186 as_date(d3.max(lines, function(line) { return d3.max(line.data, itemgetter(0)); }))
187 ]).range([0 + margin_h, w - margin_h]);
190 g.attr("width", w).attr("height", h);
191 g.selectAll("*").remove();
194 var data = d3.layout.stack()
197 .values(function(line){ return line.data })
200 var y = d3.scale.linear().domain([
202 d3.max(data, function(d) { return d3.max(d.data, function(d) { return d.y0 + d.y; }) })
203 ]).range([h - margin_v, margin_v]);
205 var y_abs = d3.scale.linear().domain([0, 1]).range([h - margin_v, margin_v]);
207 g.selectAll().data(lines).enter().append("svg:path")
208 .attr("d", function(line){
210 .x(function(d) { return x(as_date(d[0])) })
211 .y0(function(d) { return y(d.y0) })
212 .y1(function(d) { return y(d.y0 + d.y) })
213 .defined(compose(not_null, itemgetter(1)))
216 .style("fill", function(line){return line.color})
217 .attr("stroke", function(line){return line.color})
218 .attr("class", "plotline");
222 for(var i = 0; i < lines.length; ++i) {
224 var stats = get_area_mean(line.data);
225 if(stats.mean != null) {
227 total_area += stats.area;
231 for(var i = 0; i < lines.length; ++i) {
233 var stats = get_area_mean(line.data);
234 if(stats.mean != null) {
237 for(var j = 0; j < line.data.length; j++)
238 if(line.data[j] != null) {
239 var d = line.data[j];
240 num += (d.y+1)*((d.y0 + d.y) + (d.y0))/2;
244 .style("stroke", line.color)
245 .attr("x1", w - margin_h + 3)
246 .attr("y1", y(num/denom))
247 .attr("x2", w - margin_h + 10)
248 .attr("y2", y_abs(i/lines.length));
250 .text(line.label + " (mean: " + d3.format(".3s")(stats.mean) + unit + ")")
251 .attr("text-anchor", "start")
252 .attr("dominant-baseline", "central")
253 .attr("fill", line.color)
254 .attr("x", w - margin_h + 10)
255 .attr("y", y_abs(i/lines.length));
256 if(total_unit != null)
258 .text("Area: " + d3.format(".3s")(stats.area) + total_unit + " (" + d3.format(".2p")(stats.area/total_area) + " total)")
259 .attr("text-anchor", "start")
260 .attr("dominant-baseline", "central")
261 .attr("fill", line.color)
262 .attr("x", w - margin_h + 10)
263 .attr("y", y_abs(i/lines.length) + 12);
267 .style("stroke", "black")
268 .attr("x1", w - margin_h + 3)
269 .attr("y1", y(total))
270 .attr("x2", w - margin_h + 10)
271 .attr("y2", y_abs(1));
273 .text("Total (mean: " + d3.format(".3s")(total) + unit + ")")
274 .attr("text-anchor", "start")
275 .attr("dominant-baseline", "central")
276 .attr("fill", "black")
277 .attr("x", w - margin_h + 10)
278 .attr("y", y_abs(1));
279 if(total_unit != null)
281 .text("Area: " + d3.format(".3s")(total_area) + total_unit)
282 .attr("text-anchor", "start")
283 .attr("dominant-baseline", "central")
284 .attr("fill", "black")
285 .attr("x", w - margin_h + 10)
286 .attr("y", y_abs(1) + 12);
288 var y = d3.scale.linear().domain([
290 d3.max(lines, function(line) { return d3.max(line.data, itemgetter(1)); } )
291 ]).range([h - margin_v, margin_v]);
293 var y_abs = d3.scale.linear().domain([0, 1]).range([h - margin_v, margin_v]);
295 g.selectAll().data(lines).enter().append("svg:path")
296 .attr("d", function(line) {
298 .x(compose(x, as_date, itemgetter(0)))
299 .y(compose(y, itemgetter(1)))
300 .defined(compose(not_null, itemgetter(1)))
303 .style("stroke", function(line) { return line.color })
304 .attr("class", "plotline");
306 lines.sort(function(a, b) { return get_area_mean(a.data).mean > get_area_mean(b.data).mean; });
308 for(var i = 0; i < lines.length; ++i) {
310 var stats = get_area_mean(line.data);
311 if(stats.mean != null) {
313 .style("stroke", line.color)
314 .attr("x1", w - margin_h + 3)
315 .attr("y1", y(stats.mean))
316 .attr("x2", w - margin_h + 10)
317 .attr("y2", y_abs(i/lines.length));
320 .attr("text-anchor", "start")
321 .attr("dominant-baseline", "central")
322 .attr("fill", line.color)
323 .attr("x", w - margin_h + 10)
324 .attr("y", y_abs(i/lines.length) - 12);
326 .text("Mean: " + d3.format(".3s")(stats.mean) + unit)
327 .attr("text-anchor", "start")
328 .attr("dominant-baseline", "central")
329 .attr("fill", line.color)
330 .attr("x", w - margin_h + 10)
331 .attr("y", y_abs(i/lines.length));
332 if(total_unit != null)
334 .text("Area: " + d3.format(".3s")(stats.area) + total_unit)
335 .attr("text-anchor", "start")
336 .attr("dominant-baseline", "central")
337 .attr("fill", line.color)
338 .attr("x", w - margin_h + 10)
339 .attr("y", y_abs(i/lines.length) + 12);
347 .attr("x1", margin_h)
348 .attr("y1", h - margin_v)
349 .attr("x2", w - margin_h)
350 .attr("y2", h - margin_v);
354 .enter().append("svg:g")
355 .attr("transform", function(d) { return "translate(" + x(d) + "," + (h-margin_v/2) + ")"; })
357 .attr("transform", "rotate(45)")
358 .attr("text-anchor", "middle")
359 .attr("dominant-baseline", "central")
360 .text(x.tickFormat(13));
364 .enter().append("svg:line")
366 .attr("y1", h - margin_v)
368 .attr("y2", h - margin_v + 5);
373 .attr("x1", margin_h)
374 .attr("y1", h - margin_v)
375 .attr("x2", margin_h)
376 .attr("y2", margin_v);
380 .enter().append("svg:line")
381 .attr("x1", margin_h - 5)
383 .attr("x2", margin_h)
388 .enter().append("svg:text")
389 .text(compose(function(x) { return x + unit; }, d3.format(".2s")))
390 .attr("x", margin_h/2)
392 .attr("dominant-baseline", "central")
393 .attr("text-anchor", "middle");
395 function plot_later(g, unit, total_unit, lines, stack) { // takes lines with url attribute instead of data attribute
396 var callbacks_left = lines.length;
397 lines.map(function(line) {
398 d3.json(line.url, function(line_data) {
399 line.data = line_data;
401 if(callbacks_left == 0)
402 plot(g, unit, total_unit, lines, stack);
407 function data_to_lines(data, sort_key) {
408 var vers = {}; for(var i = 0; i < data.length; ++i) if(data[i][1] != null) for(var v in data[i][1]) if(data[i][1][v] != data[i][3]) vers[v] = null;
409 var verlist = []; for(var v in vers) verlist.push(v);
413 for(var i = 0; i < verlist.length; i++) {
415 data: data.map(function(d){ return [d[0], d[1] == null ? null : (verlist[i] in d[1] ? d[1][verlist[i]] : d[3]), d[2]] }),
416 color: d3.hsl(i/verlist.length*360, 0.5, 0.5),
420 if(sort_key == undefined)
421 var sort_key = function(x) { return d3.max(x.data, function(d){ return d[1] }) }
422 lines.sort(function(a, b){ return sort_key(a) - sort_key(b) });
426 function change_period(period, currency_info) {
427 d3.select("#period_current").text(period);
428 var lowerperiod = period.toLowerCase();
429 plot_later(d3.select("#local"), "H/s", "H", [
430 {"url": "../web/graph_data/local_hash_rate/last_" + lowerperiod, "color": "#0000FF", "label": "Total"},
431 {"url": "../web/graph_data/local_dead_hash_rate/last_" + lowerperiod, "color": "#FF0000", "label": "Dead"}
433 d3.json("../web/graph_data/local_share_hash_rates/last_" + lowerperiod, function(data) {
434 plot(d3.select('#local_shares'), 'H/s', 'H', data_to_lines(data), true);
436 plot_later(d3.select("#payout"), currency_info.symbol, null, [
437 {"url": "../web/graph_data/current_payout/last_" + lowerperiod, "color": "#0000FF"}
439 d3.json("../web/graph_data/pool_rates/last_" + lowerperiod, function(data) {
440 plot(d3.select('#pool'), 'H/s', 'H', data_to_lines(data), true);
442 d3.json("../web/graph_data/peers/last_" + lowerperiod, function(data) {
443 plot(d3.select('#peers'), '', null, data_to_lines(data, function(line){ return line.label == "incoming" }), true);
446 d3.json("../web/graph_data/miner_hash_rates/last_" + lowerperiod, function(data) {
447 d3.json("../web/graph_data/miner_dead_hash_rates/last_" + lowerperiod, function(dead_data) {
448 d3.json("../web/graph_data/current_payouts/last_" + lowerperiod, function(current_payouts) {
449 var users = {}; for(var i = 0; i < data.length; ++i) for(var u in data[i][1]) users[u] = null; for(var i = 0; i < dead_data.length; ++i) for(var u in dead_data[i][1]) users[u] = null;
450 var userlist = []; for(var u in users) userlist.push(u);
452 d3.select("#miners").selectAll("*").remove();
453 var div = d3.select("#miners").selectAll().data(userlist).enter().append("div");
454 div.append("h3").text(function(u) { return u });
455 div.append("svg:svg").each(function(u) {
456 plot(d3.select(this), "H/s", "H", [
457 {"data": data.map(function(d){ return [d[0], u in d[1] ? d[1][u] : d[3], d[2]] }), "color": "#0000FF", "label": "Total"},
458 {"data": dead_data.map(function(d){ return [d[0], u in d[1] ? d[1][u] : d[3], d[2]] }), "color": "#FF0000", "label": "Dead"}
461 div.append("svg:svg").each(function(u) {
462 plot(d3.select(this), currency_info.symbol, null, [
463 {"data": current_payouts.map(function(d){ return [d[0], u in d[1] ? d[1][u] : d[3], d[2]] }), "color": "#0000FF"}
470 d3.json("../web/graph_data/desired_version_rates/last_" + lowerperiod, function(data) {
471 plot(d3.select('#desired_version_rates'), 'H/s', 'H', data_to_lines(data, function(line){ return parseInt(line.label) }), true);
474 d3.json("../web/graph_data/traffic_rate/last_" + lowerperiod, function(data) {
475 plot(d3.select('#traffic_rate'), 'B/s', 'B', data_to_lines(data, function(line){ return parseInt(line.label) }), true);
478 plot_later(d3.select("#getwork_latency"), "s", null, [
479 {"url": "../web/graph_data/getwork_latency/last_" + lowerperiod, "color": "#FF0000", "label": "Getwork Latency"}
482 plot_later(d3.select("#memory_usage"), "B", null, [
483 {"url": "../web/graph_data/memory_usage/last_" + lowerperiod, "color": "#FF0000", "label": "Memory Usage"}
487 d3.json('../local_stats', function(local_stats) {
488 d3.select('#warnings').selectAll().data(local_stats.warnings).enter().append('p')
489 .text(function(w){ return 'Warning: ' + w })
490 .attr('style', 'color:red;border:1px solid red;padding:5px');
493 periods = ["Hour", "Day", "Week", "Month", "Year"];
494 d3.select("#period_chooser").selectAll().data(periods).enter().append("a")
495 .text(function(period) { return period })
496 .attr('href', function(period){ return "?" + period })
497 .attr("style", function(d, i) { return (i == 0 ? "" : "margin-left:.4em;") + "color:blue;text-decoration:underline;cursor:pointer" });
498 period = window.location.search.substr(1);
499 if(period.length < 3) {
500 window.location.search = "Day";
502 d3.json('../web/currency_info', function(currency_info) {
503 change_period(period, currency_info);