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 <script type="text/javascript">
54 var funcs = arguments;
56 for(var i = funcs.length-1; i >= 0; i--) {
62 function itemgetter(i) { return function(x) { return x[i]; } }
63 function as_date(x) { return new Date(1000*x); }
64 function not_null(x) { return x != null; }
66 function getData(url) {
67 var xmlhttp = new XMLHttpRequest();
68 xmlhttp.open("GET", url, false);
70 return JSON.parse(xmlhttp.responseText);
73 function plot(g, blue, red) {
74 var data = getData("/web/graph_data/" + blue);
76 var dead_data = getData("/web/graph_data/" + red);
85 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]);
86 var y = d3.scale.linear().domain([0, d3.max(data, itemgetter(1))]).range([h - margin, margin_top]);
88 var line = d3.svg.line().x(compose(x, as_date, itemgetter(0))).y(compose(y, itemgetter(1))).defined(compose(not_null, itemgetter(1)));
90 g.attr("width", w).attr("height", h);
91 g.selectAll("*").remove();
94 .attr("d", line(data))
95 .attr("class", "rate");
98 .attr("d", line(dead_data))
99 .attr("class", "deadrate");
103 .attr("x1", margin * 2)
104 .attr("y1", h - margin)
105 .attr("x2", w - margin * 2)
106 .attr("y2", h - margin);
110 .enter().append("svg:g")
111 .attr("transform", function(d) { return "translate(" + x(d) + "," + (h-margin/2) + ")"; })
113 .attr("transform", "rotate(45)")
114 .attr("text-anchor", "middle")
115 .attr("dominant-baseline", "central")
116 .text(x.tickFormat(13));
120 .enter().append("svg:line")
122 .attr("y1", h - margin)
124 .attr("y2", h - margin + 5);
128 .attr("x1", margin * 2)
129 .attr("y1", h - margin)
130 .attr("x2", margin * 2)
131 .attr("y2", margin_top);
135 .enter().append("svg:line")
136 .attr("x1", margin * 2 - 5)
138 .attr("x2", margin * 2)
143 .enter().append("svg:text")
144 .text(d3.format(".3s"))
147 .attr("dominant-baseline", "central")
148 .attr("text-anchor", "middle");
150 function get_avg(data) {
153 for(var i = 0; i < data.length; i++) {
154 if(data[i][1] == null) continue; // no data for bin
155 top += data[i][1] * data[i][2];
156 bottom += data[i][2];
158 if(bottom == 0) return null; // no data at all
162 var mean = get_avg(data);
165 .text("-Mean: " + d3.format(".3s")(mean))
166 .attr("text-anchor", "start")
167 .attr("dominant-baseline", "central")
168 .attr("fill", "#0000FF")
169 .attr("x", w - 2*margin)
173 var mean2 = get_avg(dead_data);
176 .text("-Mean: " + d3.format(".3s")(mean2))
177 .attr("text-anchor", "start")
178 .attr("dominant-baseline", "central")
179 .attr("fill", "#FF0000")
180 .attr("x", w - 2*margin)
181 .attr("y", y(mean2));
185 function attachGraph(e, blue, red) {
187 //setInterval(function() { plot(e, blue, red); }, 5000);
190 periods = ["Hour", "Day", "Week", "Month", "Year"];
191 d3.select("#period_chooser").selectAll().data(periods).enter().append("span")
192 .text(function(x){return x;})
193 .on("click", change_period)
194 .attr("style", function(d, i) { return (i == 0 ? "" : "margin-left:.4em;") + "color:blue;text-decoration:underline;cursor:pointer" });
195 function change_period(period) {
196 var lowerperiod = period.toLowerCase();
197 attachGraph(d3.select("#local"), "local_hash_rate/last_" + lowerperiod, "local_dead_hash_rate/last_" + lowerperiod);
198 attachGraph(d3.select("#payout"), "current_payout/last_" + lowerperiod);
199 attachGraph(d3.select("#pool"), "pool_rate/last_" + lowerperiod, "pool_stale_rate/last_" + lowerperiod);
200 d3.select("#period_current").text(period);
202 change_period(periods[1]);