Преглед изворни кода

FD3-209 - Se agrega lat-lng a las ONUs en Stats, se realiza esto para añadir
nuevas funciones en un futuro cercano y tratar de optimizar algunos
comandos.

Maximiliano Schvindt пре 7 година
родитељ
комит
bfea0f81dc

+ 42 - 0
src/StatsBundle/Command/BaseCommand.php

@@ -176,4 +176,46 @@ abstract class BaseCommand extends ContainerAwareCommand
         
         return array(0=>$type,1=>(int)$value);
     }
+
+    /**
+     * @param integer $deviceServerId
+     * @return array
+     *
+     * Description: Retorna las ONUs del DeviceServer que se encuentran registradas en Device. Indexada por ponSerialNumber.
+     */
+    public function getOnusFromDevices($deviceServerId) 
+    {
+
+        $doctrine = $this->getContainer()->get('doctrine.orm.entity_manager');
+
+        $data = array();
+        $onus = $doctrine->getRepository('\StatsBundle\Entity\Device')->findBy(array('deviceServer' => $deviceServerId, 'deviceType' => 'FTTHBundle\Entity\ONU'));
+
+        foreach($onus as $k => $device) {
+
+            
+            $extra = $device->jsonExtraData();
+
+            if(isset($extra['ponSerialNumber'])) {
+
+                $sn = strtolower($extra['ponSerialNumber']);
+
+                $lat = $lng = NULL;
+                if(isset($extra['location']) && isset($extra['location']['extraData'])) 
+                {
+                    if(isset($extra['location']['extraData']['lat'])) 
+                        $lat = $extra['location']['extraData']['lat'];
+
+                    if(isset($extra['location']['extraData']['lng'])) 
+                        $lng = $extra['location']['extraData']['lng'];
+
+                }
+
+                $data[$sn] = array('deviceId' => $device->getDeviceId(), 'lat' => $lat, 'lng' => $lng);
+            }
+        }
+
+        return $data;
+
+    }
 }

+ 6 - 53
src/StatsBundle/Command/StatsGeoOnuCommand.php

@@ -77,15 +77,18 @@ class StatsGeoOnuCommand extends BaseCommand
 
             $onus = $this->getData($key_olt_scan, true);
             
-            $devices = $this->getDevices($oltServerId);
+            $devices = $this->getOnusFromDevices($oltServerId);
 
             foreach($onus as $index => $onu) {
                 $sn = $onu['serialNumber'];
                 $lowSn = strtolower($sn);
                 
-                if(!isset($devices[$lowSn])) 
+                if(!isset($devices[$lowSn])) {
                     continue;
-                
+                } elseif(is_null($devices[$lowSn]['lat']) || is_null($devices[$lowSn]['lng'])) {
+                    continue;
+                }
+
                 $row = array();
     
                 $row['type'] = "Feature";
@@ -176,54 +179,4 @@ class StatsGeoOnuCommand extends BaseCommand
         echo $process->getOutput();
 
     }
-
-    public function getDevices($oltServerId) 
-    {
-
-        $doctrine = $this->getContainer()->get('doctrine.orm.entity_manager');
-
-        $data = array();
-        $onus = $doctrine->getRepository('\StatsBundle\Entity\Device')->findBy(array('deviceServer' => $oltServerId, 'deviceType' => 'FTTHBundle\Entity\ONU'));
-
-        foreach($onus as $k => $device) {
-
-            
-            $extra = $device->jsonExtraData();
-
-            if(isset($extra['ponSerialNumber'])) {
-
-                $sn = strtolower($extra['ponSerialNumber']);
-
-                if(isset($extra['location']) && isset($extra['location']['extraData'])) 
-                {
-                    if(isset($extra['location']['extraData']['lat'])) {
-                        $lat = $extra['location']['extraData']['lat'];
-                    } else {
-                        continue;
-                    }
-
-                    if(isset($extra['location']['extraData']['lng'])) {
-                        $lng = $extra['location']['extraData']['lng'];
-                    } else {
-                        continue;
-                    }
-                    
-                    if(is_null($lat) || is_null($lng)) continue;
-
-                } else {
-                    continue;
-                }
-
-                $data[$sn] = array('deviceId' => $device->getDeviceId(), 'lat' => $lat, 'lng' => $lng);
-            }
-        }
-
-
-
-        //print_r($data);die;
-
-        return $data;
-
-    }
-
 }

+ 5 - 51
src/StatsBundle/Command/StatsGeoPonPortCommand.php

@@ -50,7 +50,7 @@ class StatsGeoPonPortCommand extends BaseCommand
         
         $data = array();
 
-        $devices = $this->getDevices($oltServerId);
+        $devices = $this->getOnusFromDevices($oltServerId);
         
         foreach($devicesOlt as $k => $deviceOlt) {
 
@@ -105,8 +105,11 @@ class StatsGeoPonPortCommand extends BaseCommand
                     $lowSn = strtolower($sn);
                     $pon = explode("/", $onu->getPonPort());
                     
-                    if(!isset($devices[$lowSn])) 
+                    if(!isset($devices[$lowSn])) {
                         continue;
+                    } elseif(is_null($devices[$lowSn]['lat']) || is_null($devices[$lowSn]['lng'])) {
+                        continue;
+                    }
 
                     $row = array();
                     $row['type'] = "Feature";
@@ -208,53 +211,4 @@ class StatsGeoPonPortCommand extends BaseCommand
 
     }
 
-    public function getDevices($oltServerId) 
-    {
-
-        $doctrine = $this->getContainer()->get('doctrine.orm.entity_manager');
-
-        $data = array();
-        $onus = $doctrine->getRepository('\StatsBundle\Entity\Device')->findBy(array('deviceServer' => $oltServerId, 'deviceType' => 'FTTHBundle\Entity\ONU'));
-
-        foreach($onus as $k => $device) {
-
-            
-            $extra = $device->jsonExtraData();
-
-            if(isset($extra['ponSerialNumber'])) {
-
-                $sn = strtolower($extra['ponSerialNumber']);
-
-                if(isset($extra['location']) && isset($extra['location']['extraData'])) 
-                {
-                    if(isset($extra['location']['extraData']['lat'])) {
-                        $lat = $extra['location']['extraData']['lat'];
-                    } else {
-                        continue;
-                    }
-
-                    if(isset($extra['location']['extraData']['lng'])) {
-                        $lng = $extra['location']['extraData']['lng'];
-                    } else {
-                        continue;
-                    }
-                    
-                    if(is_null($lat) || is_null($lng)) continue;
-
-                } else {
-                    continue;
-                }
-
-                $data[$sn] = array('deviceId' => $device->getDeviceId(), 'lat' => $lat, 'lng' => $lng);
-            }
-        }
-
-
-
-        //print_r($data);die;
-
-        return $data;
-
-    }
-
 }

+ 9 - 26
src/StatsBundle/Command/StatsOnuCommand.php

@@ -56,7 +56,7 @@ class StatsOnuCommand extends BaseCommand
 
         $onus = $this->getData($key_olt_scan, true);
 
-        $devices = $this->getDevices($oltServerId);
+        $devices = $this->getOnusFromDevices($oltServerId);
 
         foreach($onus as $index => $onu) {
             $sn = $onu['serialNumber'];
@@ -64,8 +64,11 @@ class StatsOnuCommand extends BaseCommand
             $row = array();
             $row['deviceServer'] = $deviceServerId;
             
+            $lat = $lng = "NULL";
             if(isset($devices[$lowSn])) {
-                $row['deviceId'] = $devices[$lowSn];
+                $row['deviceId'] = $devices[$lowSn]['deviceId'];
+                $lat = $devices[$lowSn]['lat'];
+                $lng = $devices[$lowSn]['lng'];
             } else {
                 $row['deviceId'] = "NULL";
             }
@@ -87,11 +90,13 @@ class StatsOnuCommand extends BaseCommand
 
             $row['uptime'] = "NULL";
             $row['update'] = "'".date("Y-m-d H:i:s")."'";
+            
+            $row['lat'] = $lat;
+            $row['lng'] = $lng;
 
             $data[] = "(".implode(",",$row).")".PHP_EOL;
         }
 
-        //print_r($data);
 
         $conn = $doctrine->getConnection();
         $sql = "DELETE FROM `onu` WHERE device_server_id = {$deviceServerId} AND olt_device_id = {$oltDeviceId};";
@@ -99,32 +104,10 @@ class StatsOnuCommand extends BaseCommand
         $conn->close();
 
         $conn = $doctrine->getConnection();
-        $sql = "INSERT LOW_PRIORITY IGNORE INTO `onu` (`device_server_id`,`device_id`,`olt_device_id`,`tenancy_id`,`ip`,`mac`,`serial_number`,`pon_serial_number`,`pon_port`,`tx_power`,`rx_power`,`temperature`,`voltage`,`status`,`uptime`,`updated`) VALUES ".  implode(",", $data).";";
+        $sql = "INSERT LOW_PRIORITY IGNORE INTO `onu` (`device_server_id`,`device_id`,`olt_device_id`,`tenancy_id`,`ip`,`mac`,`serial_number`,`pon_serial_number`,`pon_port`,`tx_power`,`rx_power`,`temperature`,`voltage`,`status`,`uptime`,`updated`,`lat`,`lng`) VALUES ".  implode(",", $data).";";
         $conn->query($sql);
         $conn->close();
         
 
     }
-
-    public function getDevices($oltServerId) 
-    {
-
-        $doctrine = $this->getContainer()->get('doctrine.orm.entity_manager');
-
-        $data = array();
-        $onus = $doctrine->getRepository('\StatsBundle\Entity\Device')->findBy(array('deviceServer' => $oltServerId, 'deviceType' => 'FTTHBundle\Entity\ONU'));
-
-        foreach($onus as $k => $device) {
-
-            $extra = $device->jsonExtraData();
-            if(isset($extra['ponSerialNumber'])) {
-                $sn = strtolower($extra['ponSerialNumber']);
-                $data[$sn] = $device->getDeviceId();
-            }
-        }
-
-        return $data;
-
-    }
-
 }

+ 54 - 0
src/StatsBundle/Entity/Onu.php

@@ -121,6 +121,16 @@ class Onu implements TenancyIdTraitInterface
      */
     protected $updated;
 
+    /**
+     * @ORM\Column(type="decimal", precision=10, scale=7, nullable=true)
+     */
+    public $lat;
+    
+    /**
+     * @ORM\Column(type="decimal", precision=10, scale=7, nullable=true)
+     */
+    public $lng;
+
 
     /**
      * @return int
@@ -463,4 +473,48 @@ class Onu implements TenancyIdTraitInterface
         return $this->uptime;
     }
 
+    /**
+     * Set lat
+     *
+     * @param decimal $lat
+     * @return ONU
+     */
+    public function setLat($lat)
+    {
+        $this->lat = $lat;
+        return $this;
+    }
+ 
+    /**
+     * Get lat
+     *
+     * @return decimal 
+     */
+    public function getLat()
+    {
+        return $this->lat;
+    }
+    
+    /**
+     * Set lng
+     *
+     * @param decimal $lng
+     * @return ONU
+     */
+    public function setLng($lng)
+    {
+        $this->lng = $lng;
+        return $this;
+    }
+ 
+    /**
+     * Get lng
+     *
+     * @return decimal 
+     */
+    public function getLng()
+    {
+        return $this->lng;
+    }
+
 }