From 7ba81d21eebb1486c894194e20a5703618e526f8 Mon Sep 17 00:00:00 2001
From: "Eduardo L. Buratti" <elb09@c3sl.ufpr.br>
Date: Wed, 30 Oct 2013 13:32:16 -0200
Subject: [PATCH] web: Fix net_usage charts (remove pie and hist chart, fix
 queries)

Signed-off-by: Eduardo L. Buratti <elb09@c3sl.ufpr.br>
---
 .../partials/attendance.network_usage.html    |  8 +-
 web/assets/js/attendance.js                   | 87 ++-----------------
 web/queries/tlbr/net_usage/sub_regions.sql    |  6 +-
 web/queries/tlbr/net_usage/sub_states.sql     |  9 +-
 web/server.js                                 |  2 +-
 5 files changed, 18 insertions(+), 94 deletions(-)

diff --git a/web/app/partials/attendance.network_usage.html b/web/app/partials/attendance.network_usage.html
index 5a16748..85e2ccb 100644
--- a/web/app/partials/attendance.network_usage.html
+++ b/web/app/partials/attendance.network_usage.html
@@ -3,9 +3,5 @@
 <p>Clique no gráfico de barras para visualizar a situação das máquinas no próximo nível.</p>
 
 <div class="row">
-    <div class="col-lg-6" style="min-height: 300px" mc-chart="barChart"></div>
-    <div class="col-lg-6" style="min-height: 300px" mc-chart="pieChart"></div>
-</div>
-<div class="row">
-    <div class="col-lg-10 col-lg-offset-1" style="height: 300px" mc-chart="histChart"></div>
-</div>
+    <div class="col-lg-8 col-lg-offset-2" style="min-height: 300px" mc-chart="barChart"></div>
+</div>
\ No newline at end of file
diff --git a/web/assets/js/attendance.js b/web/assets/js/attendance.js
index 77ab9a4..ff12315 100644
--- a/web/assets/js/attendance.js
+++ b/web/assets/js/attendance.js
@@ -287,9 +287,8 @@ angular.module('datasid.attendance', []).
 
                 NetworkUsageFactory.query(options, function (data) {
                     var categories = [],
-                        green = [],
-                        yellow = [],
-                        red = [];
+                        down = [],
+                        up = [];
 
                     $scope.barChart.chart.options.chart.defaultSeriesType = 'column';
                     $scope.barChart.chart.options.chart.height = 300;
@@ -301,86 +300,16 @@ angular.module('datasid.attendance', []).
                     for (var i=0; i<data.length; i++) {
                         var d = data[i];
                         categories.push(d.cat);
-                        green.push(parseInt(d.green));
-                        yellow.push(parseInt(d.yellow));
-                        red.push(parseInt(d.red));
+                        down.push(parseInt(d.down));
+                        up.push(parseInt(d.up));
                     }
 
                     $scope.barChart.chart = new Highcharts.Chart($scope.barChart.chart.options);
                     $scope.barChart.chart.render();
 
                     $scope.barChart.chart.xAxis[0].setCategories(categories);
-                    $scope.barChart.chart.series[0].setData(green);
-                    $scope.barChart.chart.series[1].setData(yellow);
-                    $scope.barChart.chart.series[2].setData(red);
-                });
-            }
-        };
-
-        $scope.pieChart = {
-            render: function (element) {
-                var config = DefaultCharts.pieChart;
-                config.chart.renderTo = element[0];
-
-                $scope.pieChart.chart = new Highcharts.Chart(config);
-                $scope.pieChart.load();
-            },
-
-            load: function () {
-                var options = {
-                    type: 'net_usage_current',
-                    region: $state.params.region || null,
-                    state: $state.params.state || null,
-                    city: $state.params.city || null,
-                    id_telecenter: $state.params.id_telecenter || null
-                };
-
-                NetworkUsageFactory.query(options, function (data) {
-                    $scope.pieChart.chart.series[0].setData([
-                        ['Menos de\n10 dias', parseInt(data[0].green)],
-                        ['Entre 11\ne 30 dias', parseInt(data[0].yellow)],
-                        ['Mais de\n30 dias', parseInt(data[0].red)]
-                    ]);
-                });
-            }
-        };
-
-        $scope.histChart = {
-            render: function (element) {
-                var config = DefaultCharts.histChart;
-                config.chart.renderTo = element[0];
-
-                $scope.histChart.chart = new Highcharts.Chart(config);
-                $scope.histChart.load();
-            },
-
-            load: function () {
-                var options = {
-                    type: 'net_usage_hist',
-                    region: $state.params.region || null,
-                    state: $state.params.state || null,
-                    city: $state.params.city || null,
-                    id_telecenter: $state.params.id_telecenter || null
-                };
-
-                NetworkUsageFactory.query(options, function (data) {
-                    var categories = [],
-                        green = [],
-                        yellow = [],
-                        red = [];
-
-                    for (var i=0; i<data.length; i++) {
-                        var d = data[i];
-                        categories.push(d.month);
-                        green.push(parseInt(d.green));
-                        yellow.push(parseInt(d.yellow));
-                        red.push(parseInt(d.red));
-                    }
-
-                    $scope.histChart.chart.xAxis[0].setCategories(categories);
-                    $scope.histChart.chart.series[0].setData(green);
-                    $scope.histChart.chart.series[1].setData(yellow);
-                    $scope.histChart.chart.series[2].setData(red);
+                    $scope.barChart.chart.series[0].setData(down);
+                    $scope.barChart.chart.series[1].setData(up);
                 });
             }
         };
@@ -406,8 +335,8 @@ angular.module('datasid.attendance', []).
                 };
 
                 NetworkUsageFactory.query(options, function (data) {
-                    // $scope.barChart.chart.series[0].setData(data.download);
-                    // $scope.barChart.chart.series[1].setData(data.upload);
+                    // $scope.barChart.chart.series[0].setData(data.down);
+                    // $scope.barChart.chart.series[1].setData(data.up);
                 });
             }
         };
diff --git a/web/queries/tlbr/net_usage/sub_regions.sql b/web/queries/tlbr/net_usage/sub_regions.sql
index 0bbaf93..5962e76 100644
--- a/web/queries/tlbr/net_usage/sub_regions.sql
+++ b/web/queries/tlbr/net_usage/sub_regions.sql
@@ -1,7 +1,7 @@
 SELECT
-    region
-    , AVG(kbits_five_min_to_mbits_sec(down_kbits)) AS down_kbits
-    , AVG(kbits_five_min_to_mbits_sec(up_kbits)) AS up_kbits
+    region AS cat
+    , AVG(kbits_five_min_to_mbits_sec(down_kbits)) AS down
+    , AVG(kbits_five_min_to_mbits_sec(up_kbits)) AS up
 FROM
     fact_net_usage_telecenter
 GROUP BY
diff --git a/web/queries/tlbr/net_usage/sub_states.sql b/web/queries/tlbr/net_usage/sub_states.sql
index c4c0e16..8d328e9 100644
--- a/web/queries/tlbr/net_usage/sub_states.sql
+++ b/web/queries/tlbr/net_usage/sub_states.sql
@@ -1,12 +1,11 @@
 SELECT
-    city
-    , id_city
-    , AVG(kbits_five_min_to_mbits_sec(down_kbits)) AS down_kbits
-    , AVG(kbits_five_min_to_mbits_sec(up_kbits)) AS up_kbits
+    city AS cat
+    , AVG(kbits_five_min_to_mbits_sec(down_kbits)) AS down
+    , AVG(kbits_five_min_to_mbits_sec(up_kbits)) AS up
 FROM
     fact_net_usage_telecenter
 WHERE
-    state = $1::text
+    region = $1::text
 GROUP BY
     city
     , id_city
diff --git a/web/server.js b/web/server.js
index 635945c..1e5ef42 100755
--- a/web/server.js
+++ b/web/server.js
@@ -20,7 +20,7 @@ db.config(config.db_config);
 app.all('/api/points', db.connect, points.list);
 app.all('/api/points/count', db.connect, points.count);
 
-app.all('/api/telecenters/:state?/:city_id?/:telecenter_id?', db.connect, telecenters.list);
+app.all('/api/telecenters/:region?/:state?/:city_id?/:telecenter_id?', db.connect, telecenters.list);
 
 app.get('/api/:project/:type', db.connect, charts.get_data);
 app.get('/api/:project/:type/:region', db.connect, charts.get_data);
-- 
GitLab