Bläddra i källkod

FD3-233 Se crea el apartado report para las OLTs, se comienzan a añadir
stats.

Maximiliano Schvindt 7 år sedan
förälder
incheckning
3026ba373c

+ 2 - 2
composer.lock

@@ -1417,7 +1417,7 @@
             "source": {
                 "type": "git",
                 "url": "ssh://git@infra.flowdat.com:222/VendorSoftwareFlowdat3/BaseAdmin.git",
-                "reference": "53d81ce96e6b94af88c2546c5470fc3ad050a7bc"
+                "reference": "18768c8f06804463fd263513cc942cb56e99a85c"
             },
             "type": "library",
             "autoload": {
@@ -1432,7 +1432,7 @@
                 "bootstrap",
                 "sonata"
             ],
-            "time": "2017-10-27 15:27:11"
+            "time": "2017-11-10 15:00:33"
         },
         {
             "name": "ik/device-bundle",

+ 41 - 6
src/StatsBundle/Controller/OltReportController.php

@@ -8,27 +8,62 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\Response;
 use Sonata\AdminBundle\Admin\Pool;
+use StatsBundle\Admin\OltAdmin;
 
 class OltReportController extends Controller
 {
 
     /**
-     * @Route("/olt/{deviceId}/report", name="admin_stats_olt_list")
+     * @Route("admin/stats/olt/{oltServerId}/{oltDeviceId}/report", name="admin_stats_olt_report")
      */
-    public function mapReport($mapId) {
+    public function oltReport($oltServerId, $oltDeviceId) {
 
         $adminPool = $this->get('sonata.admin.pool');
 
+        $filter = array('deviceId' => $oltDeviceId, 'deviceServer' => $oltServerId, 'deviceType' => 'FTTHBundle\Entity\OLT');
         $em = $this->get('doctrine')->getManager();
-        $map = $em->getRepository('MapBundle:Map')->findOneById($mapId);
+        $device = $em->getRepository('StatsBundle:Device')->findOneBy($filter);
+        $data = $device->jsonExtraData();
 
-        return $this->render('MapBundle:Map:report.html.twig', array(
+        return $this->render('StatsBundle:Device:report.html.twig', array(
             'base_template' => $adminPool->getTemplate('layout'),
             'admin_pool' => $adminPool,
-            'admin' => $adminPool->getAdminByClass("StatsBundle\Entity\Device"),
-            'map' => $map
+            'admin' => $adminPool->getAdminByAdminCode("stats.admin.olt"),
+            'device' => $device,
+            'data' => $data
         ));
     }
 
+    public function onuStateCountAction($oltServerId, $oltDeviceId) {
+        
+        $em = $this->get('doctrine')->getManager();
+        $onuStateCount = array();
+        $count = $em->getRepository('StatsBundle:Onu')->createQueryBuilder('o')
+            ->select('o.status','COUNT(o)')
+            ->where('o.deviceServer = :oltServerId')
+            ->andWhere('o.oltDeviceId = :oltDeviceId')
+            ->setParameter('oltServerId', $oltServerId)
+            ->setParameter('oltDeviceId', $oltDeviceId)
+            ->groupBy('o.status')
+            ->getQuery()->getScalarResult();
+        
+        foreach($count as $c) {
+            $status = "Offline";
+            $color = "#F82929";
+            if($c['status']) {
+                $status = "Online";
+                $color = "#53D356";
+            }
+            $onuStateCount[$status] = array('count' => $c[1], 'color' => $color);
+            //$onuStateCount[$status] = $c[1];
+        }
+
+        //print_r($onuStateCount);die;
+
+        return $this->render('StatsBundle:Device:Report/onuStateCount.html.twig', array(
+            'onuStateCount' => $onuStateCount
+        ));
+        
+    }
     
 }

+ 5 - 1
src/StatsBundle/Resources/translations/StatsBundle.es.yml

@@ -124,4 +124,8 @@ msg_no_registered_in_ftth: La ONU no se encuentra registrada en FTTH. Puede agre
 msg_no_exist_map: No se encuentra el mapa solicitado.
 action_olt_show_report: Informe
 action_olt_show_onu: ONUs
-action_olt_show_ponport: PonPorts
+action_olt_show_ponport: PonPorts
+onu_count_title: Cantidad de ONUs
+onu_state: Estado
+onu_state_count: Cantidad
+onu_total_count: Total

+ 13 - 0
src/StatsBundle/Resources/views/Device/Report/default.html.twig

@@ -0,0 +1,13 @@
+<div class="box box-widget">
+    <div class="box-header">
+        <h3 class="box-title">Cargando...</h3>
+        <div class="box-tools pull-right">
+            <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
+        </div>
+    </div>
+    <div class="box-body" style="min-height: 100px;">
+        <div class="overlay">
+            <i class="fa fa-refresh fa-spin"></i>
+        </div>
+    </div>
+</div>

+ 67 - 0
src/StatsBundle/Resources/views/Device/Report/onuStateCount.html.twig

@@ -0,0 +1,67 @@
+<div class="box box-widget">
+    <div class="box-header">
+        <h4 class="box-title">{{ 'onu_count_title'|trans({}, 'StatsBundle') }}</h4>
+        <div class="box-tools pull-right">
+            <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
+        </div>
+    </div>
+    <div class="box-body">
+        {% if onuStateCount|length > 0  %}
+        <canvas id="onuStateCountChart"></canvas>
+        <br />
+        <table class="table table-hover table-condensed table-striped table-bordered">
+            <thead>
+                <tr>
+                    <th>{{ 'onu_state'|trans({}, 'StatsBundle') }}</th>
+                    <th>{{ 'onu_state_count'|trans({}, 'StatsBundle') }}</th>
+                </tr>
+            </thead>
+            <tbody>
+                {% set total = 0 %}
+                {% for state,data in onuStateCount %}
+                    {% set total = total + data.count %}
+                    <tr>
+                        <td> <i class="fa fa-square" aria-hidden="true" style="color:{{data.color}}"></i>&nbsp;&nbsp;{{ state }}</td>
+                        <td style="text-align: right">{{ data.count }}</td>
+                    </tr>
+                {% endfor %}
+            </tbody>
+        </table>
+    </div>
+    <div class="box-footer ">
+        <h5 class="pull-right">{{ 'onu_total_count'|trans({}, 'StatsBundle') }}: <b>{{ total }}</b></h5>
+    </div>
+
+
+    {% else %}
+    {{ 'action_olt_show_report'|trans({}, 'StatsBundle') }}
+    {% endif %}
+</div>
+
+{% if onuStateCount|length > 0  %}
+    {% set items, labels, colors = [], [], [] %}
+    {% for state, d in onuStateCount %}
+        {% set items = items|merge([d.count]) %}
+        {% set colors = colors|merge([d.color]) %}
+        {% set labels = labels|merge([state]) %}
+    {% endfor %}
+
+    <script>
+    var $onuStateCountChart = $('#onuStateCountChart');
+    var occhart = new Chart($onuStateCountChart, {
+        type: 'doughnut',
+        data: {
+            datasets: [{
+                data: [{{ items|join(',') }}],
+                backgroundColor: ["{{ colors|join('","')|raw }}"]
+            }],
+            labels: ["{{ labels|join('","')|raw }}"]
+        },
+        options: {
+            legend: {
+                display: false
+            }
+        }
+    });
+    </script>
+{% endif %}

+ 1 - 1
src/StatsBundle/Resources/views/Device/action_olt_show_report.html.twig

@@ -1,4 +1,4 @@
-<a href="#?filter[oltDeviceId][value]={{object.getDeviceId}}" class="btn btn-sm btn-default view_link" title="{{ 'action_olt_show_report'|trans({}, 'StatsBundle') }}">
+<a href="{{path('admin_stats_olt_report',{'oltServerId': object.getDeviceServer.getId(), 'oltDeviceId': object.getDeviceId()})}}" class="btn btn-sm btn-default view_link" title="{{ 'action_olt_show_report'|trans({}, 'StatsBundle') }}">
     <i class="fa fa-area-chart" aria-hidden="true" style="font-size: 14px; vertical-align: bottom;"></i>
     {{ 'action_olt_show_report'|trans({}, 'StatsBundle') }}
 </a>

+ 10 - 10
src/StatsBundle/Resources/views/Device/report.html.twig

@@ -2,42 +2,42 @@
 
 {% block javascripts %}
 {{ parent() }}
-<script src="{{ asset('js/hinclude.js') }}"></script>
-<script src="{{ asset('js/randomColor.js') }}"></script>
-<script src="{{ asset('js/chart.min.js') }}"></script>
+<script src="{{ asset('bundles/baseadmin/report/hinclude.js') }}"></script>
+<script src="{{ asset('bundles/baseadmin/report/randomColor.js') }}"></script>
+<script src="{{ asset('bundles/baseadmin/report/chart.min.js') }}"></script>
 {% endblock %}
 
 {% block content %}
     <div class="box box-primary">
         <div class="box-header">
-            <h3 class="box-title">{{ map.name }}</h3>
+            <h3 class="box-title">{{ data['name'] }}</h3>
         </div>
         <div class="box-body">
             <div class="col-sm-4">
-                {{ render_hinclude(controller("MapBundle:MapReport:objectTypeCount", {'mapId': map.id}),
-                    {'default':  include('@Map/Map/Report/default.html.twig')})
+                {{ render_hinclude(controller("StatsBundle:OltReport:onuStateCount", {'oltServerId': device.getDeviceServer.getId(), 'oltDeviceId': device.getDeviceId()}),
+                    {'default':  include("@Stats/Device/Report/default.html.twig")})
                 }}
             </div>
             <div class="col-sm-4">
 
-                {{ render_hinclude(controller("MapBundle:MapReport:linkObjectsLength", {'mapId': map.id}),
+                {# {{ render_hinclude(controller("MapBundle:MapReport:linkObjectsLength", {'mapId': map.id}),
                     {'default':  include('@Map/Map/Report/default.html.twig')})
                 }}
 
                 {{ render_hinclude(controller("MapBundle:MapReport:spliceClosureObjectsCount", {'mapId': map.id}),
                     {'default':  include('@Map/Map/Report/default.html.twig')})
-                }}
+                }} #}
 
             </div>
             <div class="col-sm-4">
 
-                {{ render_hinclude(controller("MapBundle:MapReport:splitterObjectsCount", {'mapId': map.id}),
+                {# {{ render_hinclude(controller("MapBundle:MapReport:splitterObjectsCount", {'mapId': map.id}),
                     {'default':  include('@Map/Map/Report/default.html.twig')})
                 }}
 
                 {{ render_hinclude(controller("MapBundle:MapReport:napObjectsCount", {'mapId': map.id}),
                     {'default':  include('@Map/Map/Report/default.html.twig')})
-                }}
+                }} #}
 
             </div>
         </div>