Browse Source

FD3-208 Se crea entidad PonPort con las estadísticas. Comando de
volcado. Tabla con las mismas.

Maximiliano Schvindt 7 years ago
parent
commit
400ce3ff5d

+ 130 - 0
src/StatsBundle/Admin/PonPortAdmin.php

@@ -0,0 +1,130 @@
+<?php
+
+namespace StatsBundle\Admin;
+
+use Base\AdminBundle\Admin\BaseAdmin;
+use Sonata\AdminBundle\Datagrid\DatagridMapper;
+use Sonata\AdminBundle\Datagrid\ListMapper;
+use Sonata\AdminBundle\Form\FormMapper;
+use Sonata\AdminBundle\Show\ShowMapper;
+use DeviceBundle\Utils\DeviceTypes;
+use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
+use Sonata\AdminBundle\Route\RouteCollection;
+
+class PonPortAdmin extends BaseAdmin
+{
+
+    /**
+     * @param DatagridMapper $datagridMapper
+     */
+    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
+    {
+        $datagridMapper
+            ->add('oltDeviceId')
+            ->add('deviceServer')
+            ->add('tenancyId')
+            ->add('ponPort')
+        ;
+    }
+
+    /**
+     * @param ListMapper $listMapper
+     */
+    protected function configureListFields(ListMapper $listMapper)
+    {
+        $em = $this->get("doctrine.orm.entity_manager");
+        $servers = $em->getRepository("StatsBundle:DeviceServer")->findAll();
+        
+        $olts_server = $urls_server = array();
+
+        foreach($servers as $deviceServer) {
+            $urls = $this->get('webservice')->getData($deviceServer->getUrl());
+            $urls_server[$deviceServer->getId()] = $urls;
+            $olts = $em->getRepository("StatsBundle:device")->findBy(array('deviceServer'=>$deviceServer, 'deviceType' => 'FTTHBundle\Entity\OLT'));
+            $olts_server[$deviceServer->getId()] = array();
+            foreach($olts as $olt) {
+                $data = $olt->jsonExtraData();
+                $name = null;
+                if(isset($data['name'])) $name = $data['name'];
+                $olts_server[$deviceServer->getId()][$olt->getDeviceId()] = $name;
+            }
+        }
+
+        //print_r($urls_server);die;
+        $this->parameters = array('urls_server' => $urls_server, 'olts_server' => $olts_server);
+
+
+        $listMapper
+            ->add('deviceServer')
+            ->add('oltDeviceId', 'string', array('template' => 'StatsBundle:Onu:base_list_field_olt.html.twig'))
+            ->add('tenancyId')
+            ->addIdentifier('ponPort')
+            ->add('txPower', 'string', array('template' => 'StatsBundle:Onu:base_list_field_tx.html.twig'))
+            ->add('arrayRxPower', 'ponport-rx-power', array('template' => 'StatsBundle:PonPort:base_list_field_rx.html.twig'))
+            ->add('voltage', 'string', array('template' => 'StatsBundle:Onu:base_list_field_voltage.html.twig'))
+            ->add('temperature', 'string', array('template' => 'StatsBundle:Onu:base_list_field_temperature.html.twig'))
+            ->add('biasCurrent')
+            /* ->add('updated') */
+        ;
+    }
+
+    /**
+     * @param FormMapper $formMapper
+     */
+    protected function configureFormFields(FormMapper $formMapper)
+    {
+    }
+
+    /**
+     * @param ShowMapper $showMapper
+     */
+    protected function configureShowFields(ShowMapper $showMapper)
+    {
+        $showMapper
+            /* ->add('oltDeviceId')
+            ->add('ponSerialNumber') */
+            ->add('ponPort')
+            ->add('txPower', 'string', array('template' => 'StatsBundle:Onu:base_show_field_tx.html.twig'))
+            /* ->add('rxPower', 'string', array('template' => 'StatsBundle:Onu:base_show_field_rx.html.twig')) */
+            ->add('voltage', 'string', array('template' => 'StatsBundle:Onu:base_show_field_voltage.html.twig'))
+            ->add('temperature', 'string', array('template' => 'StatsBundle:Onu:base_show_field_temperature.html.twig'))
+            ->add('biasCurrent')
+            /* ->add('updated', 'string', array('template' => 'StatsBundle:Onu:base_show_field_uptime.html.twig')) */
+        ;
+    }
+
+    /**
+     * @param string $action
+     * @param Object $object
+     * 
+     * @return array
+     */
+    public function configureActionButtons($action, $object = null)
+    {
+
+        $actions = parent::configureActionButtons($action, $object);
+        /* if($action == "list") {
+            $actions['show_in_map'] = array('template' => 'StatsBundle:Onu:map_button.html.twig');
+        } elseif($action == "show") {
+            $deviceServer = $object->getDeviceServer();
+            $urls = $this->get('webservice')->getData($deviceServer->getUrl());
+            if(isset($urls['url_ftth'])) {
+                $deviceId = $object->getDeviceId();
+                $url = "{$urls['url_ftth']}/admin/ftth/onu/{$deviceId}/show";
+                $this->parameters = array('url_ftth' => $url);
+                $actions['show_in_ftth'] = array('template' => 'StatsBundle:Onu:ftth_button.html.twig');
+            }
+            
+        } */
+
+        return $actions;
+    }
+
+    protected function configureRoutes(RouteCollection $collection)
+    {
+        $collection->remove('delete');
+        $collection->remove('create');
+        $collection->remove('edit');
+    }
+
+}

+ 111 - 0
src/StatsBundle/Command/StatsPonPortCommand.php

@@ -0,0 +1,111 @@
+<?php
+
+namespace StatsBundle\Command;
+
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use StatsBundle\Services\DeviceManager;
+
+class StatsPonPortCommand extends BaseCommand
+{
+
+    protected function configure()
+    {
+        $this
+            ->setName('stats:ponport')
+            ->setDescription('Update PonPort Stats')
+            ->setHelp('Actualiza la tabla PonPort con los datos obtenidos del OLT definido')
+            ->setDefinition(array(
+                new InputOption('olt-device-id', null, InputOption::VALUE_OPTIONAL, "DeviceId de la OLT", 1),
+                new InputOption('olt-server-id', null, InputOption::VALUE_OPTIONAL, "ServerDevice de la OLT", 1)
+            ))
+        ;
+    }
+
+    /**
+     * @param InputInterface $input
+     * @param OutputInterface $output
+     */
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        parent::execute($input, $output);
+
+        $oltDeviceId = (int) $input->getOption('olt-device-id');
+        $oltServerId = (int) $input->getOption('olt-server-id');
+
+        $now = date("d-m-Y H:i:s");
+
+        $doctrine = $this->getContainer()->get('doctrine.orm.entity_manager');
+        
+        $deviceOlt = $doctrine->getRepository('\StatsBundle\Entity\Device')->findOneBy(array('deviceId' => $oltDeviceId, 'deviceServer' => $oltServerId, 'deviceType' => 'FTTHBundle\Entity\OLT'));
+        
+        $tenancyId = $deviceOlt->getTenancyId();
+        $deviceServerId = $oltServerId;
+        
+        $flag = "olt_scan_pons_d_{$oltDeviceId}_s_{$oltServerId}.lock";
+        
+        $key_pon_stats = "olt_stats_pons_d_{$oltDeviceId}_s_{$oltServerId}";
+        
+        /* Control de bloqueo */
+        if($this->lock($flag)) {return;}
+        
+        $ponsCached = $this->getData($key_pon_stats, true);
+        
+        if(empty($ponsCached)) {
+            $this->output->writeln("Se requiere {$key_pon_stats}.");
+            $this->removeLock($flag);
+            return true;
+        }
+
+        $ponPorts = $doctrine->getRepository('\StatsBundle\Entity\PonPort')->findBy(array('oltDeviceId' => $oltDeviceId, 'deviceServer' => $oltServerId));
+        $_ponPorts = array();
+        foreach($ponPorts as $k => $pp) {
+            $_ponPorts[$pp->getPonPort()] = $pp->getId();
+        }
+
+        
+        foreach($ponsCached as $index => $stats) {
+            
+            $row = array();
+            $ponPort = $stats['ponPort'];
+
+            if(isset($_ponPorts[$ponPort])) {
+                $row['id'] = $_ponPorts[$ponPort];
+            } else {
+                $row['id'] = "NULL";
+            }
+            $row['deviceServer'] = $deviceServerId;
+            $row['ponPort'] = "'{$ponPort}'";
+            $row['oltDeviceId'] = $oltDeviceId;
+            $row['tenancyId'] = $tenancyId;
+            $row['update'] = "'".date("Y-m-d H:i:s")."'";
+            
+            
+            (isset($stats['txPower']))? $row['txPower'] = $stats['txPower'] : $row['txPower'] = "NULL";
+            (empty($stats['rxPower']))? $row['rxPower'] = "NULL" : $row['rxPower'] = "'".str_replace('"','\"',json_encode($stats['rxPower']))."'";
+            (isset($stats['voltage']))? $row['voltage'] = $stats['voltage'] : $row['voltage'] = "NULL";
+            (isset($stats['temperature']))? $row['temperature'] = $stats['temperature'] : $row['temperature'] = "NULL";
+            (isset($stats['biasCurrent']))? $row['biasCurrent'] = $stats['biasCurrent'] : $row['biasCurrent'] = "NULL";
+            
+            $data[] = "(".implode(",",$row).")".PHP_EOL;
+        }
+
+        $conn = $doctrine->getConnection();
+        $sql = "DELETE FROM `pon_port` WHERE device_server_id = {$deviceServerId} AND olt_device_id = {$oltDeviceId};";
+        $conn->query($sql);
+        $conn->close();
+
+        $conn = $doctrine->getConnection();
+        $sql = "INSERT LOW_PRIORITY IGNORE INTO `pon_port` (`id`,`device_server_id`,`pon_port`,`olt_device_id`,`tenancy_id`,`updated`,`tx_power`,`rx_power`,`voltage`,`temperature`,`bias_current`) VALUES ".  implode(",", $data).";";
+        
+        //print_r($sql);
+        $conn->query($sql);
+        $conn->close();
+        
+
+    }
+
+
+}

+ 341 - 0
src/StatsBundle/Entity/PonPort.php

@@ -0,0 +1,341 @@
+<?php
+
+namespace StatsBundle\Entity;
+
+use Doctrine\ORM\Mapping as ORM;
+use ExtraDataBundle\Entity\Traits\ExtraDataTrait;
+use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
+use Symfony\Component\Validator\Constraints as Assert;
+use Symfony\Component\Workflow\Exception\ExceptionInterface;
+
+
+/**
+ * @ORM\Table
+ * @ORM\Entity
+ * @UniqueEntity(fields={"deviceServer", "oltDeviceId", "ponPort"}, message="errors.duplicate_key")
+ * @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(name="unique_idx", columns={"device_server_id", "olt_device_id", "pon_port"})})
+ * 
+ */
+class PonPort
+{
+
+    /**
+     * @var int
+     *
+     * @ORM\Column(name="id", type="integer")
+     * @ORM\Id
+     * @ORM\GeneratedValue(strategy="AUTO")
+     */
+     private $id;
+
+    /**
+     * @var string
+     *
+     * @ORM\Column(type="string", length=25, nullable=true)
+     */
+    private $ponPort;
+
+    /**
+     * @var int
+     *
+     * @ORM\Column(type="integer", nullable=true)
+     * 
+     */
+    private $oltDeviceId;
+     
+    /**
+     * @ORM\ManyToOne(targetEntity="DeviceServer", inversedBy="devices", fetch="EXTRA_LAZY")
+     * 
+     */
+    protected $deviceServer;
+
+    /**
+     * @var int
+     *
+     * @ORM\Column(type="integer", nullable=false, options={"default":1})
+     */
+    protected $tenancyId = 1;
+    
+    /**
+     * @ORM\Column(type="datetime")
+     */
+    protected $updated;
+
+    /**
+     * @ORM\Column(type="decimal", precision=6, scale=3, nullable=true)
+     */
+    public $txPower;
+     
+    /**
+     * @ORM\Column(type="text", nullable=true)
+     */
+    public $rxPower;
+     
+    /**
+     * @ORM\Column(type="decimal", precision=6, scale=3, nullable=true)
+     */
+    public $voltage;
+     
+    /**
+     * @ORM\Column(type="decimal", precision=6, scale=3, nullable=true)
+     */
+    public $temperature;
+    
+    /**
+     * @ORM\Column(type="decimal", precision=6, scale=3, nullable=true)
+     */
+    public $biasCurrent;
+
+    /**
+     * @return int
+     */
+    public function getId()
+    {
+        return $this->id;
+    }
+
+    /**
+     * @return string
+     */
+    public function __toString()
+    {
+        return sprintf('%s', strtoupper($this->ponPort));
+    }
+
+    /**
+     * Set ponPort
+     *
+     * @param string $ponPort
+     *
+     * @return PonPort
+     */
+    public function setPonPort($ponPort)
+    {
+        $this->ponPort = $ponPort;
+
+        return $this;
+    }
+
+    /**
+     * Get ponPort
+     *
+     * @return string
+     */
+    public function getPonPort()
+    {
+        return $this->ponPort;
+    }
+
+    /**
+     * @param int $oltDeviceId
+     *
+     * @return PonPort
+     */
+    public function setOltDeviceId($oltDeviceId)
+    {
+        $this->oltDeviceId = $oltDeviceId;
+
+        return $this;
+    }
+
+    /**
+     * @return int
+     */
+    public function getOltDeviceId()
+    {
+        return $this->oltDeviceId;
+    }
+
+    /**
+     * @param DeviceServer $deviceServer
+     *
+     * @return PonPort
+     */
+    public function setDeviceServer($deviceServer)
+    {
+        $this->deviceServer = $deviceServer;
+
+        return $this;
+    }
+
+    /**
+     * @return DeviceServer
+     */
+    public function getDeviceServer()
+    {
+        return $this->deviceServer;
+    }
+
+    /**
+     * Set tenancyId
+     *
+     * @param int $tenancyId
+     *
+     * @return PonPort
+     */
+    public function setTenancyId($tenancyId)
+    {
+        $this->tenancyId = $tenancyId;
+
+        return $this;
+    }
+
+    /**
+     * Get tenancyId
+     *
+     * @return int
+     */
+    public function getTenancyId()
+    {
+        return $this->tenancyId;
+    }
+
+    /**
+     * Set updated
+     *
+     * @param Datetime $tenancyId
+     *
+     * @return PonPort
+     */
+    public function setUpdated($updated)
+    {
+        $this->updated = $updated;
+
+        return $this;
+    }
+
+    /**
+     * Get updated
+     *
+     * @return \DateTime
+     */
+    public function getUpdated()
+    {
+        return $this->updated;
+    }
+
+    /**
+     * Set txPower
+     *
+     * @param decimal $txPower
+     * @return PonPort
+     */
+    public function setTxPower($txPower)
+    {
+        $this->txPower = $txPower;
+        return $this;
+    }
+ 
+    /**
+     * Get txPower
+     *
+     * @return decimal 
+     */
+    public function getTxPower()
+    {
+        return $this->txPower;
+    }
+ 
+    /**
+     * Set rxPower
+     *
+     * @param string $rxPower
+     * @return PonPort
+     */
+    public function setRxPower($rxPower)
+    {
+        $this->rxPower = $rxPower;
+        return $this;
+    }
+
+    /**
+     * Get rxPower
+     *
+     * @return string
+     */
+    public function getRxPower()
+    {
+        return $this->rxPower;
+    }
+
+    /**
+     * Get rxPower
+     *
+     * @return string
+     */
+    public function getArrayRxPower()
+    {
+        if($this->rxPower) {
+            return json_decode($this->rxPower, true);
+        }
+
+        return array();
+    }
+ 
+    /**
+     * Set voltage
+     *
+     * @param decimal $voltage
+     * @return PonPort
+     */
+    public function setVoltage($voltage)
+    {
+        $this->voltage = $voltage;
+        return $this;
+    }
+
+    /**
+     * Get voltage
+     *
+     * @return decimal 
+     */
+    public function getVoltage()
+    {
+        return $this->voltage;
+    }
+ 
+    /**
+     * Set temperature
+     *
+     * @param decimal $temperature
+     * @return PonPort
+     */
+    public function setTemperature($temperature)
+    {
+        $this->temperature = $temperature;
+        return $this;
+    }
+
+    /**
+     * Get temperature
+     *
+     * @return decimal 
+     */
+    public function getTemperature()
+    {
+        return $this->temperature;
+    }
+    
+    /**
+     * Set biasCurrent
+     *
+     * @param decimal $biasCurrent
+     * @return PonPort
+     */
+    public function setBiasCurrent($biasCurrent)
+    {
+        $this->biasCurrent = $biasCurrent;
+        return $this;
+    }
+
+    /**
+     * Get biasCurrent
+     *
+     * @return decimal 
+     */
+    public function getBiasCurrent()
+    {
+        return $this->biasCurrent;
+    }
+
+}

+ 9 - 0
src/StatsBundle/Resources/config/services.yml

@@ -29,3 +29,12 @@ services:
         calls:    
             - [setTranslationDomain, [StatsBundle]]
             - [setTemplate, ['show','StatsBundle:Onu:base_show.html.twig']]
+    
+    stats.admin.pon_port:
+        class: StatsBundle\Admin\PonPortAdmin
+        arguments: [~, StatsBundle\Entity\PonPort, SonataAdminBundle:CRUD]
+        tags:
+            - { name: sonata.admin, manager_type: orm, group: List, label: PonPort, label_catalogue: StatsBundle, label_translator_strategy: sonata.admin.label.strategy.underscore }
+        calls:    
+            - [setTranslationDomain, [StatsBundle]]
+            - [setTemplate, ['show','StatsBundle:PonPort:base_show.html.twig']]

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

@@ -5,6 +5,7 @@ breadcrumb:
     link_device_list: Listado de Dispositivos
     link_device_create: Crear Dispositivo
     link_onu_list: Listado de ONUs
+    link_pon_port_list: Listado de PonPorts
 
 filter:
     label_name: Nombre
@@ -26,6 +27,8 @@ filter:
     label_temperature: Temperatura
     label_uptime: Uptime
     label_updated: Actualizado
+    label_bias_current: Bias Current
+    label_array_rx_power: Rx Power
 
 form:
     label_name: Nombre
@@ -37,6 +40,8 @@ form:
     label_device_server: Servidor
     label_short_type: Tipo
     label_tenancy_id: Tenencia
+    label_bias_current: Bias Current
+    label_array_rx_power: Rx Power
 
 show:
     label_name: Nombre
@@ -58,6 +63,8 @@ show:
     label_temperature: Temperatura
     label_uptime: Uptime
     label_updated: Actualizado
+    label_bias_current: Bias Current
+    label_array_rx_power: Rx Power
 
 list:
     label_name: Nombre
@@ -80,6 +87,8 @@ list:
     label_temperature: Temperatura
     label_uptime: Uptime
     label_updated: Actualizado
+    label_bias_current: Bias Current
+    label_array_rx_power: Rx Power
     
 help:
     url: Url a consultar dispositivos
@@ -89,14 +98,12 @@ Stats: Estadísticas
 DeviceServer: Servidor Dispositivos
 StatsDevice: Dispositivo
 Device: Dispositivo
-
-link_action_update_devices: Actualizar dispositivos
-
 Statistics: Estadísticas
 macroFields:
     notavailable: 'NULL'
 List: Listados
 ONU: ONU
-link_action_show_onu_in_map: Ver en Mapa
 Mapa ONUs: Mapa ONUs
-link_action_show_onu_in_ftth: Ver configuración
+link_action_show_onu_in_map: Ver en Mapa
+link_action_show_onu_in_ftth: Ver configuración
+link_action_update_devices: Actualizar dispositivos

+ 35 - 0
src/StatsBundle/Resources/views/PonPort/base_list_field_rx.html.twig

@@ -0,0 +1,35 @@
+{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
+
+{% block field %}
+    {% set rx = object.getArrayRxPower() %}
+    {% if rx is null or rx|length == 0 %}
+        <span class="text_column_stats">{{ 'macroFields.notavailable'|trans({},'StatsBundle') }}</span>
+    {% else %}
+        <div class="ponport_div_rx_power">
+        <table><tr>
+        {% for key,value in rx %}
+            {% set style = "rx_ftth_bordo" %}
+            {% if value < -30 %}
+                {% set style = "rx_ftth_bordo" %}
+            {% elseif value >= -30 and value < -28 %}
+                {% set style = "rx_ftth_rojo" %}
+            {% elseif value >= -28 and value < -26 %}
+                {% set style = "rx_ftth_amarillo" %}
+            {% elseif value >= -26 and value < -20 %}
+                {% set style = "rx_ftth_verde" %}
+            {% elseif value >= -20 and value < -15 %}
+                {% set style = "rx_ftth_amarillo" %}
+            {% elseif value >= -15 and value < -13 %}
+                {% set style = "rx_ftth_rojo" %}
+            {% endif %}
+            <td class="ponport_td_rx_power">
+            <span class="ponport_td_span_rx_power">{{key}} <span class="{{style}}"> {{ value|number_format(2, '.', ',')}}</span></span>
+            </td>
+        
+        {% endfor %}
+        </tr></table>
+        </div>
+
+        
+    {% endif %}
+{% endblock %}

+ 8 - 0
src/StatsBundle/Resources/views/PonPort/base_show.html.twig

@@ -0,0 +1,8 @@
+{% extends 'SonataAdminBundle:CRUD:base_show.html.twig' %}
+
+{% block show %}
+    {{ parent() }}
+    
+    {# {{ render(controller('StatsBundle:Stats:grafanaPonPort', { 'ponSerialNumber':object.ponSerialNumber })) }} #}
+    
+{% endblock %}