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 <h2>Local rate - Blue=All, Red=Dead</h2>
44 <div id="local_hour"></div>
47 <div id="local_day"></div>
50 <div id="local_week"></div>
53 <div id="local_month"></div>
55 <h2>Pool rate - Blue=All, Red=Stale</h2>
58 <div id="pool_hour"></div>
61 <div id="pool_day"></div>
64 <div id="pool_week"></div>
67 <div id="pool_month"></div>
69 <script type="text/javascript">
70 function getData(url) {
71 xmlhttp = new XMLHttpRequest();
72 xmlhttp.open("GET", url, false);
74 var data = JSON.parse(xmlhttp.responseText);
79 function plot(e, blue, red) {
80 data = getData("/web/graph_data/" + blue);
81 dead_data = getData("/web/graph_data/" + red);
87 function itemgetter(i) {
93 return new Date(1000*x);
96 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]);
97 var y = d3.scale.linear().domain([0, d3.max(data, itemgetter(1))]).range([h - margin, margin]);
99 var line = d3.svg.line().x(function(d, i) { return x(as_date(d[0])); }).y(function(d) { return y(d[1]); });
101 e.selectAll("svg").remove();
102 var g = e.insert("svg:svg").attr("width", w).attr("height", h);
105 .attr("d", line(data))
106 .attr("class", "rate");
109 .attr("d", line(dead_data))
110 .attr("class", "deadrate");
114 .attr("x1", margin * 2)
115 .attr("y1", h - margin)
116 .attr("x2", w - margin * 2)
117 .attr("y2", h - margin);
121 .enter().append("svg:g")
122 .attr("transform", function(d) { return "translate(" + x(d) + "," + (h-margin/2) + ")"; })
124 .attr("transform", "rotate(45)")
125 .attr("text-anchor", "middle")
126 .text(x.tickFormat(13));
130 .enter().append("svg:line")
132 .attr("y1", h - margin)
134 .attr("y2", h - margin + 5);
138 .attr("x1", margin * 2)
139 .attr("y1", h - margin)
140 .attr("x2", margin * 2)
145 .enter().append("svg:line")
146 .attr("x1", margin * 2 - 5)
148 .attr("x2", margin * 2)
153 .enter().append("svg:text")
154 .text(d3.format(".3s"))
155 .attr("x", margin - 2.5)
156 .attr("y", function(d) { return y(d) + 4; })
157 .attr("text-anchor", "middle");
160 function attachGraph(e, blue, red) {
162 setInterval(function() { plot(e, blue, red); }, 5000);
165 periods = ["hour", "day", "week", "month"];
166 for(i = 0; i < periods.length; i++) {
167 attachGraph(d3.select("#local_" + periods[i]), "local_hash_rate/last_" + periods[i], "local_dead_hash_rate/last_" + periods[i]);
168 attachGraph(d3.select("#pool_" + periods[i]), "pool_rate/last_" + periods[i], "pool_stale_rate/last_" + periods[i]);