diff --git a/planetstack/hpc_wizard/planetstack_analytics.py b/planetstack/hpc_wizard/planetstack_analytics.py
index 2afacb3..840d247 100644
--- a/planetstack/hpc_wizard/planetstack_analytics.py
+++ b/planetstack/hpc_wizard/planetstack_analytics.py
@@ -38,9 +38,9 @@
 
         return [slice.name for slice in slices]
 
-    def compose_query(self, slice=None, site=None, node=None, service=None, timeBucket="60", avg=[], sum=[], count=[], computed=[], val=[], groupBy=["Time"], orderBy=["Time"], tableName="demoevents", latest=False, max_age=60*60):
-        max_age = max_age * 1000
-        tablePart = "[%s.%s@-%d--1]" % ("vicci", tableName, max_age)
+    def compose_query(self, slice=None, site=None, node=None, service=None, timeBucket="60", avg=[], sum=[], count=[], computed=[], val=[], groupBy=["Time"], orderBy=["Time"], tableName="demoevents", latest=False, maxAge=60*60):
+        maxAge = maxAge * 1000
+        tablePart = "[%s.%s@-%d--1]" % ("vicci", tableName, maxAge)
 
         fields = []
         fieldNames = []
@@ -286,7 +286,7 @@
 
         format = req.GET.get("format", "json_dicts")
 
-        timeField = req.GET.get("timeBucket", "60")
+        timeBucket = int(req.GET.get("timeBucket", 60))
         avg = self.get_list_from_req(req, "avg")
         sum = self.get_list_from_req(req, "sum")
         count = self.get_list_from_req(req, "count")
@@ -297,9 +297,11 @@
         maxRows = req.GET.get("maxRows", None)
         mergeDataModelSites = req.GET.get("mergeDataModelSites", None)
 
+        maxAge = int(req.GET.get("maxAge", 60*60))
+
         cached = req.GET.get("cached", None)
 
-        q = self.compose_query(slice, site, node, service, timeField, avg, sum, count, computed, [], groupBy, orderBy)
+        q = self.compose_query(slice, site, node, service, timeBucket, avg, sum, count, computed, [], groupBy, orderBy, maxAge=maxAge)
 
         print q
 
diff --git a/planetstack/templates/admin/dashboard/hpc_historical.html b/planetstack/templates/admin/dashboard/hpc_historical.html
index b6763b4..8f0702f 100644
--- a/planetstack/templates/admin/dashboard/hpc_historical.html
+++ b/planetstack/templates/admin/dashboard/hpc_historical.html
@@ -8,162 +8,162 @@
     <script type="text/javascript">
 
      var options = {
-         width: 600,
-         height: 400,
-         showRowNumber: false,
-         pages: true,
-         numRows: 9,
-         backgroundColor: "black"
-     };
-
-     // ask django for a data source URL to use for the graphs
-
-     function updateDataSourceUrl() {
-         var sliceName = $("#historical_slicename :selected").text();
-         var queryString = "/analytics/bigquery/?sum=@bytes_sent&avg=@cpu&groupBy=Time,city,@hostname,@site&slice=" + sliceName;
-
-         $.ajax({
-             url: queryString,
-             dataType: 'json',
-             type: 'GET',
-             success: function (newData) {
-                 sendAndDraw(newData["dataSourceUrl"])
-             }
-         });
-     }
-
-     TIME_COL = 0;
-     BANDWIDTH_COL = 2;
-     CPU_COL = 1;
-     CITY_COL = 3;
-     NODE_COL = 4;
-     SITE_COL = 5;
-
-     google.setOnLoadCallback(function () {
-         $('#historical_slicename').change(function()
-         {
-             updateDataSourceUrl();
-         });
-
-         updateDataSourceUrl();
-     });
-
-     function showSiteTimeAgg(dt) {
-         var lineChart = new google.visualization.ChartWrapper({
-             'chartType': 'LineChart',
-             'containerId': 'chart-site-time',
-             'options': {
-                 'width': 320,
-                 'height': 300,
-                 'title': 'Network-wide usage',
-                 'pages': true,
-                 'numRows': 9
-             },
-             'view': {
-                 'columns': [0, 1, 2]
-             }
-         });
-         lineChart.setDataTable(dt);
-         lineChart.draw();
-     }
-
-     function showSiteAgg(dt) {
-         var barChart = new google.visualization.ChartWrapper({
-             'chartType': 'ColumnChart',
-             'containerId': 'chart-site-agg',
-             'options': {
-                 'width': 670,
-                 'height': 300,
-                 'title': 'Site-wise usage',
-                 'pages': true,
-                 'numRows': 9
-             },
-             'view': {
-                 'columns': [1, 2, 3]
-             }
-         });
-         barChart.setDataTable(dt);
-         barChart.draw();
-         var geoChart = new google.visualization.ChartWrapper({
-             'chartType': 'GeoChart',
-             'containerId': 'chart-geo',
-             'options': {
-                 'width': 320,
-                 'height': 300,
-                 'displayMode': 'markers',
-                 'region': '021',
-                 'title': 'Usage map',
-                 colorAxis: {
-                     colors: ['green', 'purple', 'red']
-                 }
-             },
-             'view': {
-                 'columns': [0, 2, 3]
-             }
-         });
-         geoChart.setDataTable(dt);
-         geoChart.draw();
-
-/*         var histogram = new google.visualization.ChartWrapper({
-             'chartType': 'Histogram',
-             'containerId': 'chart-histo',
-             'options': {
-                 'width': 300,
-                 'height': 300,
-             },
-             'title': 'Sites by load',
-             'view': {
-                 'columns': [1, 2]
-             }
-         });
-         histogram.setDataTable(dt);
-         histogram.draw();  */
-
-     }
-
-     function handleResponse(response) {
-         var timeSlider = new google.visualization.ControlWrapper({
-             'controlType': 'DateRangeFilter',
-             'containerId': 'control1',
-             'options': {
-                 'filterColumnLabel': 'Time',
-                 ui: {
-                     ticks: 10,
-                     step: "minute"
-                 }
-             }
-         });
-
-         var categoryPicker = new google.visualization.ControlWrapper({
-             'controlType': 'CategoryFilter',
-             'allowMultiple': true,
-             'containerId': 'control2',
-             'options': {
-                 'filterColumnLabel': 'site',
-                 'ui': {
-                     'labelStacking': 'vertical',
-                     'allowTyping': false
-                 }
-             }
-         });
-
-         var proxy = new google.visualization.ChartWrapper({
-             'chartType': 'Table',
-             'containerId': 'chart7',
-             'options': {
-                 'width': 800,
-                 'height': 300,
-                 pageSize: 5,
-                 page: 'enable',
-                 'legend': 'none',
-                 'title': 'Nodes'
-             },
-             'view': {
-                 'columns': [0, 1, 2, 3, 4, 5]
-             }
-         });
-
-         function avg_bandwidth(arr) {
+         width: 600,
+         height: 400,
+         showRowNumber: false,
+         pages: true,
+         numRows: 9,
+         backgroundColor: "black"
+     };
+
+     // ask django for a data source URL to use for the graphs
+
+     function updateDataSourceUrl() {
+         var sliceName = $("#historical_slicename :selected").text();
+         var queryString = "/analytics/bigquery/?timeBucket=600&maxAge=86400&sum=@bytes_sent&avg=@cpu&groupBy=Time,city,@hostname,@site&slice=" + sliceName;
+
+         $.ajax({
+             url: queryString,
+             dataType: 'json',
+             type: 'GET',
+             success: function (newData) {
+                 sendAndDraw(newData["dataSourceUrl"])
+             }
+         });
+     }
+
+     TIME_COL = 0;
+     BANDWIDTH_COL = 2;
+     CPU_COL = 1;
+     CITY_COL = 3;
+     NODE_COL = 4;
+     SITE_COL = 5;
+
+     google.setOnLoadCallback(function () {
+         $('#historical_slicename').change(function()
+         {
+             updateDataSourceUrl();
+         });
+
+         updateDataSourceUrl();
+     });
+
+     function showSiteTimeAgg(dt) {
+         var lineChart = new google.visualization.ChartWrapper({
+             'chartType': 'LineChart',
+             'containerId': 'chart-site-time',
+             'options': {
+                 'width': 320,
+                 'height': 300,
+                 'title': 'Network-wide usage',
+                 'pages': true,
+                 'numRows': 9
+             },
+             'view': {
+                 'columns': [0, 1, 2]
+             }
+         });
+         lineChart.setDataTable(dt);
+         lineChart.draw();
+     }
+
+     function showSiteAgg(dt) {
+         var barChart = new google.visualization.ChartWrapper({
+             'chartType': 'ColumnChart',
+             'containerId': 'chart-site-agg',
+             'options': {
+                 'width': 670,
+                 'height': 300,
+                 'title': 'Site-wise usage',
+                 'pages': true,
+                 'numRows': 9
+             },
+             'view': {
+                 'columns': [1, 2, 3]
+             }
+         });
+         barChart.setDataTable(dt);
+         barChart.draw();
+         var geoChart = new google.visualization.ChartWrapper({
+             'chartType': 'GeoChart',
+             'containerId': 'chart-geo',
+             'options': {
+                 'width': 320,
+                 'height': 300,
+                 'displayMode': 'markers',
+                 'region': '021',
+                 'title': 'Usage map',
+                 colorAxis: {
+                     colors: ['green', 'purple', 'red']
+                 }
+             },
+             'view': {
+                 'columns': [0, 2, 3]
+             }
+         });
+         geoChart.setDataTable(dt);
+         geoChart.draw();
+
+/*         var histogram = new google.visualization.ChartWrapper({
+             'chartType': 'Histogram',
+             'containerId': 'chart-histo',
+             'options': {
+                 'width': 300,
+                 'height': 300,
+             },
+             'title': 'Sites by load',
+             'view': {
+                 'columns': [1, 2]
+             }
+         });
+         histogram.setDataTable(dt);
+         histogram.draw();  */
+
+     }
+
+     function handleResponse(response) {
+         var timeSlider = new google.visualization.ControlWrapper({
+             'controlType': 'DateRangeFilter',
+             'containerId': 'control1',
+             'options': {
+                 'filterColumnLabel': 'Time',
+                 ui: {
+                     ticks: 10,
+                     step: "minute"
+                 }
+             }
+         });
+
+         var categoryPicker = new google.visualization.ControlWrapper({
+             'controlType': 'CategoryFilter',
+             'allowMultiple': true,
+             'containerId': 'control2',
+             'options': {
+                 'filterColumnLabel': 'site',
+                 'ui': {
+                     'labelStacking': 'vertical',
+                     'allowTyping': false
+                 }
+             }
+         });
+
+         var proxy = new google.visualization.ChartWrapper({
+             'chartType': 'Table',
+             'containerId': 'chart7',
+             'options': {
+                 'width': 800,
+                 'height': 300,
+                 pageSize: 5,
+                 page: 'enable',
+                 'legend': 'none',
+                 'title': 'Nodes'
+             },
+             'view': {
+                 'columns': [0, 1, 2, 3, 4, 5]
+             }
+         });
+
+         function avg_bandwidth(arr) {
                 var ret = 0;
                 for (var i = 0; i < arr.length; i++) {
                         ret+=arr[i]*8.0/1024.0/1024.0/1024.0;
@@ -172,100 +172,100 @@
                     return 0;
                 }
                 return ret/arr.length;
-         }
-
-         function sum_bytes_sent_as_bw(arr) {
+         }
+
+         function sum_bytes_sent_as_bw(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/60.0;
-         }
-
-         function sum_bytes_sent_as_GB(arr) {
+         }
+
+         function sum_bytes_sent_as_GB(arr) {
                 var ret = 0;
                 for (var i = 0; i < arr.length; i++) {
                         ret+=arr[i]/1024.0/1024.0/1024.0;
                 }
                 return ret;
-         }
-
-         function fixDate2(unixDate) {
-             // not completely sure why we have to do this, as the data was in
-             // javascript Date() objects to start with. If we don't do it,
-             // then the horizontal axis will be blank.
+         }
+
+         function fixDate2(unixDate) {
+             // not completely sure why we have to do this, as the data was in
+             // javascript Date() objects to start with. If we don't do it,
+             // then the horizontal axis will be blank.
              return new Date(unixDate);
-         }
-
-         var format0dp = new google.visualization.NumberFormat({fractionDigits:0});
-         var format2dp = new google.visualization.NumberFormat({fractionDigits:2});
-
-         // Create a group for charts that will have a horizontal axis that is
-         // time.
-
-         google.visualization.events.addListener(proxy, 'ready', function () {
-             var dt = proxy.getDataTable();
-             var groupedData1 = google.visualization.data.group(dt, [{
+         }
+
+         var format0dp = new google.visualization.NumberFormat({fractionDigits:0});
+         var format2dp = new google.visualization.NumberFormat({fractionDigits:2});
+
+         // Create a group for charts that will have a horizontal axis that is
+         // time.
+
+         google.visualization.events.addListener(proxy, 'ready', function () {
+             var dt = proxy.getDataTable();
+             var groupedData1 = google.visualization.data.group(dt, [{
                  column: TIME_COL,
                  type: 'datetime',
                  modifier: fixDate2,
-             }], [{
-                 column: CPU_COL,
-                 type: 'number',
-                 label: "avg cpu",
-                 aggregation: google.visualization.data.avg
-             }, {
-                 column: BANDWIDTH_COL,
-                 type: 'number',
-                 label: "Gbps",
-                 aggregation: sum_bytes_sent_as_bw
-             }]);
-
-             format0dp.format(groupedData1,1);
-             format2dp.format(groupedData1,2);
-
-             showSiteTimeAgg(groupedData1);
-         });
-
-         // Create a group for charts that will have a horizontal axis that is
-         // city or site.
-
-         google.visualization.events.addListener(proxy, 'ready', function () {
-             var dt = proxy.getDataTable();
-             var groupedData0 = google.visualization.data.group(dt, [CITY_COL, SITE_COL], [{
-                 column: CPU_COL,
-                 type: 'number',
-                 label: 'avg cpu',
-                 aggregation: google.visualization.data.avg
-             }, {
-                 column: BANDWIDTH_COL,
-                 type: 'number',
-                 label: "GB sent",
-                 aggregation: sum_bytes_sent_as_GB
-             }]);
-
-             format0dp.format(groupedData0,2);
-             format2dp.format(groupedData0,3);
-
-             showSiteAgg(groupedData0);
-         });
-
-         data = response.getDataTable();
-         new google.visualization.Dashboard(document.getElementById('dashboard')).
-         // Establish bindings, declaring the both the slider and the category
-         // picker will drive both charts.
-         bind([categoryPicker, timeSlider], [proxy]).
-         // Draw the entire dashboard.
-         draw(data);
-
-     }
-
-     function sendAndDraw(queryString) {
-         query = new google.visualization.Query(queryString)
-         query && query.abort();
-         query.send(function (response) {
-             handleResponse(response);
-         });
+             }], [{
+                 column: CPU_COL,
+                 type: 'number',
+                 label: "avg cpu",
+                 aggregation: google.visualization.data.avg
+             }, {
+                 column: BANDWIDTH_COL,
+                 type: 'number',
+                 label: "Gbps",
+                 aggregation: sum_bytes_sent_as_bw
+             }]);
+
+             format0dp.format(groupedData1,1);
+             format2dp.format(groupedData1,2);
+
+             showSiteTimeAgg(groupedData1);
+         });
+
+         // Create a group for charts that will have a horizontal axis that is
+         // city or site.
+
+         google.visualization.events.addListener(proxy, 'ready', function () {
+             var dt = proxy.getDataTable();
+             var groupedData0 = google.visualization.data.group(dt, [CITY_COL, SITE_COL], [{
+                 column: CPU_COL,
+                 type: 'number',
+                 label: 'avg cpu',
+                 aggregation: google.visualization.data.avg
+             }, {
+                 column: BANDWIDTH_COL,
+                 type: 'number',
+                 label: "GB sent",
+                 aggregation: sum_bytes_sent_as_GB
+             }]);
+
+             format0dp.format(groupedData0,2);
+             format2dp.format(groupedData0,3);
+
+             showSiteAgg(groupedData0);
+         });
+
+         data = response.getDataTable();
+         new google.visualization.Dashboard(document.getElementById('dashboard')).
+         // Establish bindings, declaring the both the slider and the category
+         // picker will drive both charts.
+         bind([categoryPicker, timeSlider], [proxy]).
+         // Draw the entire dashboard.
+         draw(data);
+
+     }
+
+     function sendAndDraw(queryString) {
+         query = new google.visualization.Query(queryString)
+         query && query.abort();
+         query.send(function (response) {
+             handleResponse(response);
+         });
      }
 
     </script>
