4 <title>P2Pool Graphs</title>
5 <script type="text/javascript" src="d3.v2.min.js"></script>
7 <style type="text/css">
9 font-family: Sans-serif;
16 shape-rendering: crispEdges;
32 font-family: Sans-serif;
39 <h1>P2Pool Graphs</h1>
41 <p>Periods: <span id="period_chooser"></span> Current: <span id="period_current"></span></p>
43 <h2>Local rate - Blue=All, Red=Dead (hash/second)</h2>
44 <svg id="local"></svg>
46 <h2>Current payout (BTC)</h2>
47 <svg id="payout"></svg>
49 <h2>Pool rate - Blue=All, Red=Stale (hash/second)</h2>
52 <h2>Peers - Blue=Incoming, Red=Outgoing</h2>
53 <svg id="peers"></svg>
55 <script type="text/javascript">
57 var funcs = arguments;
59 for(var i = funcs.length-1; i >= 0; i--) {
65 function itemgetter(i) { return function(x) { return x[i]; } }
66 function as_date(x) { return new Date(1000*x); }
67 function not_null(x) { return x != null; }
69 function getData(url) {
70 var xmlhttp = new XMLHttpRequest();
71 xmlhttp.open("GET", url, false);
73 return JSON.parse(xmlhttp.responseText);
76 function plot(g, blue, red) {
77 var data = getData("/web/graph_data/" + blue);
79 var dead_data = getData("/web/graph_data/" + red);
88 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]);
89 var y = d3.scale.linear().domain([0, d3.max(data.concat(dead_data), itemgetter(1))]).range([h - margin, margin_top]);
91 var line = d3.svg.line().x(compose(x, as_date, itemgetter(0))).y(compose(y, itemgetter(1))).defined(compose(not_null, itemgetter(1)));
93 g.attr("width", w).attr("height", h);
94 g.selectAll("*").remove();
97 .attr("d", line(data))
98 .attr("class", "rate");
101 .attr("d", line(dead_data))
102 .attr("class", "deadrate");
106 .attr("x1", margin * 2)
107 .attr("y1", h - margin)
108 .attr("x2", w - margin * 2)
109 .attr("y2", h - margin);
113 .enter().append("svg:g")
114 .attr("transform", function(d) { return "translate(" + x(d) + "," + (h-margin/2) + ")"; })
116 .attr("transform", "rotate(45)")
117 .attr("text-anchor", "middle")
118 .attr("dominant-baseline", "central")
119 .text(x.tickFormat(13));
123 .enter().append("svg:line")
125 .attr("y1", h - margin)
127 .attr("y2", h - margin + 5);
131 .attr("x1", margin * 2)
132 .attr("y1", h - margin)
133 .attr("x2", margin * 2)
134 .attr("y2", margin_top);
138 .enter().append("svg:line")
139 .attr("x1", margin * 2 - 5)
141 .attr("x2", margin * 2)
146 .enter().append("svg:text")
147 .text(d3.format(".3s"))
150 .attr("dominant-baseline", "central")
151 .attr("text-anchor", "middle");
153 function get_avg(data) {
156 for(var i = 0; i < data.length; i++) {
157 if(data[i][1] == null) continue; // no data for bin
158 top += data[i][1] * data[i][2];
159 bottom += data[i][2];
161 if(bottom == 0) return null; // no data at all
165 var mean = get_avg(data);
168 .text("-Mean: " + d3.format(".3s")(mean))
169 .attr("text-anchor", "start")
170 .attr("dominant-baseline", "central")
171 .attr("fill", "#0000FF")
172 .attr("x", w - 2*margin)
176 var mean2 = get_avg(dead_data);
179 .text("-Mean: " + d3.format(".3s")(mean2))
180 .attr("text-anchor", "start")
181 .attr("dominant-baseline", "central")
182 .attr("fill", "#FF0000")
183 .attr("x", w - 2*margin)
184 .attr("y", y(mean2));
188 function attachGraph(e, blue, red) {
190 //setInterval(function() { plot(e, blue, red); }, 5000);
193 periods = ["Hour", "Day", "Week", "Month", "Year"];
194 d3.select("#period_chooser").selectAll().data(periods).enter().append("span")
195 .text(function(x){return x;})
196 .on("click", change_period)
197 .attr("style", function(d, i) { return (i == 0 ? "" : "margin-left:.4em;") + "color:blue;text-decoration:underline;cursor:pointer" });
198 function change_period(period) {
199 var lowerperiod = period.toLowerCase();
200 attachGraph(d3.select("#local"), "local_hash_rate/last_" + lowerperiod, "local_dead_hash_rate/last_" + lowerperiod);
201 attachGraph(d3.select("#payout"), "current_payout/last_" + lowerperiod);
202 attachGraph(d3.select("#pool"), "pool_rate/last_" + lowerperiod, "pool_stale_rate/last_" + lowerperiod);
203 attachGraph(d3.select("#peers"), "incoming_peers/last_" + lowerperiod, "outgoing_peers/last_" + lowerperiod);
204 d3.select("#period_current").text(period);
206 change_period(periods[1]);