|
@@ -6,7 +6,8 @@ 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;
|
|
|
+use Symfony\Component\Process\Process;
|
|
|
+use Symfony\Component\Process\Exception\ProcessFailedException;
|
|
|
|
|
|
class StatsGeoOnuCommand extends BaseCommand
|
|
|
{
|
|
@@ -18,7 +19,6 @@ class StatsGeoOnuCommand extends BaseCommand
|
|
|
->setDescription('Update ONU Stats')
|
|
|
->setHelp('Genera un geoJson con las stats de las ONUs')
|
|
|
->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)
|
|
|
))
|
|
|
;
|
|
@@ -32,90 +32,144 @@ class StatsGeoOnuCommand extends BaseCommand
|
|
|
{
|
|
|
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');
|
|
|
+ $path = $this->getContainer()->getParameter('geoserver_path_shapes');
|
|
|
|
|
|
- $deviceOlt = $doctrine->getRepository('\StatsBundle\Entity\Device')->findOneBy(array('deviceId' => $oltDeviceId, 'deviceServer' => $oltServerId, 'deviceType' => 'FTTHBundle\Entity\OLT'));
|
|
|
-
|
|
|
- $tenancyId = $deviceOlt->getTenancyId();
|
|
|
- $deviceServerId = $oltServerId;
|
|
|
-
|
|
|
- $key_olt_scan = "olt_scan_d_{$oltDeviceId}_s_{$oltServerId}";
|
|
|
-
|
|
|
+ $devicesOlt = $doctrine->getRepository('\StatsBundle\Entity\Device')->findBy(array('deviceServer' => $oltServerId, 'deviceType' => 'FTTHBundle\Entity\OLT'));
|
|
|
$metrics = array("tx" => "onu_tx_", "rx" => "onu_rx_", "temp" => "onu_temperature_", "volt" => "onu_voltage_", "status" => "onu_status_");
|
|
|
- $data = $stats = array();
|
|
|
-
|
|
|
- foreach($metrics as $m => $metric) {
|
|
|
- $key_onu_stats = "{$metric}d_{$oltDeviceId}_s_{$oltServerId}";
|
|
|
- $stats[$metric] = $this->getData($key_onu_stats, true);
|
|
|
- }
|
|
|
-
|
|
|
- $onus = $this->getData($key_olt_scan, true);
|
|
|
-
|
|
|
- $devices = $this->getDevices($oltServerId);
|
|
|
-
|
|
|
- $geo = array();
|
|
|
- $geo['type'] = "FeatureCollection";
|
|
|
- $geo['totalFeatures'] = 0;
|
|
|
- $geo['features'] = array();
|
|
|
|
|
|
+ $data = array();
|
|
|
|
|
|
- $count = 0;
|
|
|
-
|
|
|
- foreach($onus as $index => $onu) {
|
|
|
- $sn = $onu['serialNumber'];
|
|
|
- $lowSn = strtolower($sn);
|
|
|
-
|
|
|
- if(!isset($devices[$lowSn]))
|
|
|
- continue;
|
|
|
+ foreach($devicesOlt as $k => $deviceOlt) {
|
|
|
+ $oltDeviceId = $deviceOlt->getDeviceId();
|
|
|
+ $tenancyId = $deviceOlt->getTenancyId();
|
|
|
|
|
|
- $row = array();
|
|
|
+ if(isset($data[$tenancyId])) {
|
|
|
+ $geo = $data[$tenancyId];
|
|
|
+ } else {
|
|
|
+ $geo = array();
|
|
|
+ $geo['type'] = "FeatureCollection";
|
|
|
+ $geo['totalFeatures'] = 0;
|
|
|
+ $geo['features'] = array();
|
|
|
+ $geo['crs'] = array('type' => "name", 'properties' => array('name' => "urn:ogc:def:crs:EPSG::4326"));
|
|
|
+ $data[$tenancyId] = $geo;
|
|
|
+ }
|
|
|
|
|
|
- $row['type'] = "Feature";
|
|
|
- $row['id'] = "onu.{$lowSn}";
|
|
|
-
|
|
|
-
|
|
|
- $lat = $devices[$lowSn]['lat'];
|
|
|
- $lng = $devices[$lowSn]['lng'];
|
|
|
+ $deviceServerId = $oltServerId;
|
|
|
|
|
|
- $row['geometry'] = array('type' => "Point", 'coordinates' => array(0 => $lng, 1 => $lat));
|
|
|
- $row['geometry_name'] = "the_geom";
|
|
|
+ $key_olt_scan = "olt_scan_d_{$oltDeviceId}_s_{$oltServerId}";
|
|
|
|
|
|
- $row['properties'] = array();
|
|
|
+ $stats = array();
|
|
|
|
|
|
foreach($metrics as $m => $metric) {
|
|
|
- if(isset($stats[$metric][$sn])) {
|
|
|
- $row['properties'][$m] = $stats[$metric][$sn];
|
|
|
- } else {
|
|
|
- $row['properties'][$m] = "null";
|
|
|
+ $key_onu_stats = "{$metric}d_{$oltDeviceId}_s_{$oltServerId}";
|
|
|
+ $stats[$metric] = $this->getData($key_onu_stats, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ $onus = $this->getData($key_olt_scan, true);
|
|
|
+
|
|
|
+ $devices = $this->getDevices($oltServerId);
|
|
|
+
|
|
|
+ foreach($onus as $index => $onu) {
|
|
|
+ $sn = $onu['serialNumber'];
|
|
|
+ $lowSn = strtolower($sn);
|
|
|
+
|
|
|
+ if(!isset($devices[$lowSn]))
|
|
|
+ continue;
|
|
|
+
|
|
|
+ $row = array();
|
|
|
+
|
|
|
+ $row['type'] = "Feature";
|
|
|
+ $row['id'] = "onu.{$lowSn}";
|
|
|
+
|
|
|
+
|
|
|
+ $lat = $devices[$lowSn]['lat'];
|
|
|
+ $lng = $devices[$lowSn]['lng'];
|
|
|
+
|
|
|
+ $row['geometry'] = array('type' => "Point", 'coordinates' => array(0 => $lng, 1 => $lat));
|
|
|
+ $row['geometry_name'] = "the_geom";
|
|
|
+
|
|
|
+ $row['properties'] = array();
|
|
|
+
|
|
|
+ foreach($metrics as $m => $metric) {
|
|
|
+ if(isset($stats[$metric][$sn])) {
|
|
|
+ $row['properties'][$m] = $stats[$metric][$sn];
|
|
|
+ } else {
|
|
|
+ $row['properties'][$m] = "null";
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ $geo['features'][] = $row;
|
|
|
}
|
|
|
+
|
|
|
+ $geo['totalFeatures'] = count($geo['features']);
|
|
|
|
|
|
- $geo['features'][] = $row;
|
|
|
- $count++;
|
|
|
+
|
|
|
+ $data[$tenancyId] = $geo;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- $geo['totalFeatures'] = $count;
|
|
|
- $geo['crs'] = array('type' => "name", 'properties' => array('name' => "urn:ogc:def:crs:EPSG::4326"));
|
|
|
+ //print_r($data);
|
|
|
|
|
|
+ foreach($data as $tenancy => $geoData) {
|
|
|
+ if($geoData['totalFeatures'] > 0) {
|
|
|
|
|
|
- if($count > 0) {
|
|
|
- $data = json_encode($geo);
|
|
|
-
|
|
|
- $file_name = time().".json";
|
|
|
- $dir = "/var/flowdat/geoFd3/{$oltDeviceId}_{$oltServerId}";
|
|
|
- if(!is_dir($dir))
|
|
|
- mkdir($dir);
|
|
|
-
|
|
|
- $file = fopen($dir."/".$file_name, "a+");
|
|
|
- fwrite($file, $data);
|
|
|
-
|
|
|
+ $geoJson = json_encode($geoData);
|
|
|
+
|
|
|
+ $file_name = "onu_stats_tenancy_{$tenancy}".".json";
|
|
|
+ $shape_name = "onu_stats_tenancy_{$tenancy}".".shp";
|
|
|
+ $dir = "$path/deviceServer_{$oltServerId}";
|
|
|
+
|
|
|
+ if(!is_dir($dir)) {
|
|
|
+ mkdir($dir);
|
|
|
+ chown($dir, "www-data");
|
|
|
+ }
|
|
|
+
|
|
|
+ $file = fopen($dir."/".$file_name, "a+");
|
|
|
+ fwrite($file, $geoJson);
|
|
|
+
|
|
|
+
|
|
|
+ if($this->getContainer()->getParameter('geoserver_service') && file_exists($dir."/".$file_name)) {
|
|
|
+ $this->generateShapes($dir, $file_name, $shape_name);
|
|
|
+ $workspace = "deviceServer_{$oltServerId}";
|
|
|
+
|
|
|
+ $geoserver = $this->getContainer()->get('geoserver.api');
|
|
|
+ $geoserver->createWorkspace($workspace);
|
|
|
+ $geoserver->updateShape($workspace);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ public function generateShapes($dir, $file_name, $shape_name)
|
|
|
+ {
|
|
|
+ $process = new Process("ogr2ogr -f 'ESRI Shapefile' {$dir}/{$shape_name} {$dir}/{$file_name}");
|
|
|
+
|
|
|
+ //$process->run();
|
|
|
+ $process->start();
|
|
|
|
|
|
+ while ($process->isRunning()) {
|
|
|
+ // waiting for process to finish
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$process->isSuccessful()) {throw new ProcessFailedException($process);}
|
|
|
+
|
|
|
+ echo $process->getOutput();
|
|
|
+
|
|
|
+ $files = scandir($dir);
|
|
|
+ foreach($files as $file)
|
|
|
+ {
|
|
|
+ if(is_file($dir."/".$file)) {
|
|
|
+ chmod($dir."/".$file, 0777);
|
|
|
+ chgrp($dir."/".$file, "www-data");
|
|
|
+ chown($dir."/".$file, "www-data");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public function getDevices($oltServerId)
|