removed unused argument in graphs
[p2pool.git] / web-static / graphs.html
index bc44a68..62d8c74 100644 (file)
@@ -26,7 +26,7 @@
     </head>
     
     <body>
-        <h1><a href="/static/">P2Pool</a> &gt; Graphs</h1>
+        <h1><a href=".">P2Pool</a> &gt; Graphs</h1>
         
         <p>Periods: <span id="period_chooser"></span> Current: <span id="period_current"></span></p>
         
         <h2>Traffic rate</h2>
         <svg id="traffic_rate"></svg>
         
-        <h2>Getwork Latency</h2>
+        <h2>Bitcoind GetBlockTemplate Latency</h2>
         <svg id="getwork_latency"></svg>
         
+        <h2>Memory Usage</h2>
+        <svg id="memory_usage"></svg>
+        
         <script type="text/javascript">
             function compose() {
                 var funcs = arguments;
             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; }
+            var cloneOf = (function() {
+              function F(){}
+              return function(o) {
+                F.prototype = o;
+                return new F();
+              }
+            }());
             
             function get_area_mean(data) {
                 var top = 0;
                 return {"area": top, "mean": bottom==0?null:top/bottom};
             }
             
-            function plot(g, unit, total_unit, lines, stack) {
+            function plot(g, unit, total_unit, lines, stack, proportion_view) {
                 // lines is a list of objects which have attributes data, color, and label
                 
+                var orig_unit = unit;
+                var orig_total_unit = total_unit;
+                var orig_lines = lines;
+                if(proportion_view) {
+                    var totals = {};
+                    for(var i = 0; i < lines.length; ++i) {
+                        var line = lines[i];
+                        for(var j = 0; j < line.data.length; ++j) {
+                            var time_str = JSON.stringify(line.data[j][0]);
+                            if(!totals.hasOwnProperty(time_str)) totals[time_str] = 0;
+                            totals[time_str] += line.data[j][1];
+                        }
+                    }
+                    
+                    var new_lines = [];
+                    for(var i = 0; i < lines.length; ++i) {
+                        var line = lines[i];
+                        var new_line = cloneOf(line);
+                        
+                        new_line.data = [];
+                        for(var j = 0; j < line.data.length; ++j) {
+                            var time_str = JSON.stringify(line.data[j][0]);
+                            new_line.data.push([line.data[j][0], totals[time_str] ? line.data[j][1]*100/totals[time_str] : null, line.data[j][2]]);
+                        }
+                        
+                        new_lines.push(new_line)
+                    }
+                    var lines = new_lines;
+                    var unit = '%';
+                    var total_unit = null;
+                }
+                
                 var table_div = document.createElement("div");
                 g.node().parentNode.insertBefore(table_div, g.node().nextSibling);
                 table_div.style.display = "none";
                     .text('Show/hide table')
                     .on('click', function() { table_div.style.display = table_div.style.display == "block" ? "none" : "block" })
                     .attr("style", "color:blue;text-decoration:underline;cursor:pointer");
+                if(stack) {
+                    d3.select(showhide).append('span').text(' ');
+                    d3.select(showhide).append("a")
+                        .text('Switch to/from proportion view')
+                        .on('click', function() {
+                            table_div.parentNode.removeChild(table_div);
+                            showhide.parentNode.removeChild(showhide);
+                            plot(g, orig_unit, orig_total_unit, orig_lines, stack, !proportion_view);
+                        })
+                        .attr("style", "color:blue;text-decoration:underline;cursor:pointer");
+                }
                 
                 for(var i = 0; i < lines.length; ++i) {
                     var line = lines[i];
                 }
                 d3.select(table_div).append('div').attr('style', 'clear:both');
                 
-                d3.select(table_div).append('p').append("a")
+                var p_after = d3.select(table_div).append('p');
+                p_after.append("a")
                     .text('Show/hide table')
                     .on('click', function() { table_div.style.display = table_div.style.display == "block" ? "none" : "block" })
                     .attr("style", "color:blue;text-decoration:underline;cursor:pointer");
                 d3.select("#period_current").text(period);
                 var lowerperiod = period.toLowerCase();
                 plot_later(d3.select("#local"), "H/s", "H", [
-                    {"url": "/web/graph_data/local_hash_rate/last_" + lowerperiod, "color": "#0000FF", "label": "Total"},
-                    {"url": "/web/graph_data/local_dead_hash_rate/last_" + lowerperiod, "color": "#FF0000", "label": "Dead"}
+                    {"url": "../web/graph_data/local_hash_rate/last_" + lowerperiod, "color": "#0000FF", "label": "Total"},
+                    {"url": "../web/graph_data/local_dead_hash_rate/last_" + lowerperiod, "color": "#FF0000", "label": "Dead"}
                 ]);
                 plot_later(d3.select("#local_shares"), "H/s", "H", [
-                    {"url": "/web/graph_data/local_share_hash_rate/last_" + lowerperiod, "color": "#0000FF", "label": "Total"},
-                    //{"url": getData("/web/graph_data/local_dead_share_hash_rate/last_" + lowerperiod, "color": "#FF0000", "label": "Dead"}
+                    {"url": "../web/graph_data/local_share_hash_rate/last_" + lowerperiod, "color": "#0000FF", "label": "Total"},
+                    //{"url": getData("../web/graph_data/local_dead_share_hash_rate/last_" + lowerperiod, "color": "#FF0000", "label": "Dead"}
                 ]);
                 plot_later(d3.select("#payout"), currency_info.symbol, null, [
-                    {"url": "/web/graph_data/current_payout/last_" + lowerperiod, "color": "#0000FF"}
+                    {"url": "../web/graph_data/current_payout/last_" + lowerperiod, "color": "#0000FF"}
                 ]);
-                d3.json("/web/graph_data/pool_rates/last_" + lowerperiod, function(data) {
+                d3.json("../web/graph_data/pool_rates/last_" + lowerperiod, function(data) {
                     plot(d3.select('#pool'), 'H/s', 'H', data_to_lines(data), true);
                 });
                 plot_later(d3.select("#peers"), "", null, [
-                    {"url": "/web/graph_data/outgoing_peers/last_" + lowerperiod, "color": "#FF0000", "label": "Outgoing"},
-                    {"url": "/web/graph_data/incoming_peers/last_" + lowerperiod, "color": "#0000FF", "label": "Incoming"}
+                    {"url": "../web/graph_data/outgoing_peers/last_" + lowerperiod, "color": "#FF0000", "label": "Outgoing"},
+                    {"url": "../web/graph_data/incoming_peers/last_" + lowerperiod, "color": "#0000FF", "label": "Incoming"}
                 ], true);
                 
-                d3.json("/web/graph_data/miner_hash_rates/last_" + lowerperiod, function(data) {
-                    d3.json("/web/graph_data/miner_dead_hash_rates/last_" + lowerperiod, function(dead_data) {
-                        d3.json("/web/graph_data/current_payouts/last_" + lowerperiod, function(current_payouts) {
+                d3.json("../web/graph_data/miner_hash_rates/last_" + lowerperiod, function(data) {
+                    d3.json("../web/graph_data/miner_dead_hash_rates/last_" + lowerperiod, function(dead_data) {
+                        d3.json("../web/graph_data/current_payouts/last_" + lowerperiod, function(current_payouts) {
                             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;
                             var userlist = []; for(var u in users) userlist.push(u);
                             userlist.sort();
                     });
                 });
                 
-                d3.json("/web/graph_data/desired_version_rates/last_" + lowerperiod, function(data) {
+                d3.json("../web/graph_data/desired_version_rates/last_" + lowerperiod, function(data) {
                     plot(d3.select('#desired_version_rates'), 'H/s', 'H', data_to_lines(data, function(line){ return parseInt(line.label) }), true);
                 });
                 
-                d3.json("/web/graph_data/traffic_rate/last_" + lowerperiod, function(data) {
+                d3.json("../web/graph_data/traffic_rate/last_" + lowerperiod, function(data) {
                     plot(d3.select('#traffic_rate'), 'B/s', 'B', data_to_lines(data, function(line){ return parseInt(line.label) }), true);
                 });
                 
                 plot_later(d3.select("#getwork_latency"), "s", null, [
-                    {"url": "/web/graph_data/getwork_latency/last_" + lowerperiod, "color": "#FF0000", "label": "Getwork Latency"}
+                    {"url": "../web/graph_data/getwork_latency/last_" + lowerperiod, "color": "#FF0000", "label": "Getwork Latency"}
+                ], false);
+                
+                plot_later(d3.select("#memory_usage"), "B", null, [
+                    {"url": "../web/graph_data/memory_usage/last_" + lowerperiod, "color": "#FF0000", "label": "Memory Usage"}
                 ], false);
             }
             
-            d3.json('/local_stats', function(local_stats) {
+            d3.json('../local_stats', function(local_stats) {
                 d3.select('#warnings').selectAll().data(local_stats.warnings).enter().append('p')
                     .text(function(w){ return 'Warning: ' + w })
                     .attr('style', 'color:red;border:1px solid red;padding:5px');
             if(period.length < 3) {
                 window.location.search = "Day";
             } else {
-                d3.json('/web/currency_info', function(currency_info) {
+                d3.json('../web/currency_info', function(currency_info) {
                     change_period(period, currency_info);
                 });
             }