From 7c972e5a58c477739a021b518ec723c53e9fadfa Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Fri, 21 Mar 2014 16:47:09 -0700 Subject: [PATCH] convert MBps to Gbps in bandwidth graph --- planetstack/core/static/planetstack_graphs.js | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/planetstack/core/static/planetstack_graphs.js b/planetstack/core/static/planetstack_graphs.js index ca8458e..8177d8d 100644 --- a/planetstack/core/static/planetstack_graphs.js +++ b/planetstack/core/static/planetstack_graphs.js @@ -1,6 +1,6 @@ google.load('visualization', '1', {'packages' : ['controls','table','corechart','geochart']}); -function renderChart(origQuery, yColumn, xColumn, title) { +function renderChart(origQuery, yColumn, xColumn, title, aggFunc) { $('#graph').empty(); $('#chartsModal').modal('show'); $('.modal-body').scrollTop(0) @@ -14,13 +14,21 @@ function renderChart(origQuery, yColumn, xColumn, title) { var query = new google.visualization.Query(dataSourceUrl) query && query.abort(); console.log("query.send") - query.send(function(response) {handleResponse_psg(response, yColumn, xColumn, title);}); + query.send(function(response) {handleResponse_psg(response, yColumn, xColumn, title, aggFunc);}); console.log("query.sent") } // NOTE: appended _psg to showLine() and handleResponse() to prevent conflict // with Sapan's analytics page. +function agg_bandwidth(arr) { + var ret = 0; + for (var i = 0; i < arr.length; i++) { + ret+=arr[i]*8.0/1024.0/1024.0/1024.0; + } + return ret; +} + function showLine_psg(dt, title) { console.log("showline") var lineChart = new google.visualization.ChartWrapper({ @@ -51,7 +59,7 @@ function fixDate(unixDate) { return new Date(unixDate*1000); } -function handleResponse_psg(response, yColumn, xColumn, title) { +function handleResponse_psg(response, yColumn, xColumn, title, aggFunc) { console.log("handleResponse") var supportedClasses = { @@ -88,7 +96,7 @@ function handleResponse_psg(response, yColumn, xColumn, title) { column: xColumn, type: 'number', label: dt.getColumnLabel(xColumn), - aggregation: google.visualization.data.sum}]); + aggregation: aggFunc}]); showLine_psg(groupedData1, title); @@ -107,15 +115,15 @@ function handleResponse_psg(response, yColumn, xColumn, title) { $('.nodesLabel, .nodesValue').click(function() { var jsonData = window.pageAnalyticsData; - renderChart(jsonData.query, 0, 2, "Node Count"); + renderChart(jsonData.query, 0, 2, "Node Count", google.visualization.data.sum); //renderChartJson(jsonData, "MinuteTime", "count_hostname", "Node Count"); }); $('.cpuLabel, .cpuValue').click(function() { var jsonData = window.pageAnalyticsData; - renderChart(jsonData.query, 0, 1, "Average CPU"); + renderChart(jsonData.query, 0, 1, "Average CPU", google.visualization.data.sum); }); $('.bandwidthLabel, .bandwidthValue').click(function() { var jsonData = window.pageBandData; - renderChart(jsonData.query, 0, 1, "Total Bandwidth"); + renderChart(jsonData.query, 0, 1, "Total Bandwidth", agg_bandwidth); }); -- 2.47.0