Hugo преди 4 години
родител
ревизия
7ce08952d5
променени са 3 файла, в които са добавени 292 реда и са изтрити 10 реда
  1. 126 6
      commands/CopyController.php
  2. 160 3
      commands/SyncCompleteController.php
  3. 6 1
      commands/SyncController.php

+ 126 - 6
commands/CopyController.php

@@ -530,13 +530,14 @@ class CopyController extends Controller {
       "TV_JUA_5_1",
     ],
     "rt-MOm8-" => [
-      "2107_3_MEX",
+      "107_3_MEX",
       "MEX_CDMX_94_5",
       "MEX_CDMX_100_9",
       "105_3_MEX",
       "MEX_CDMX_90_5",
       "MEX_CDMX_96_1",
       "MEX_CDMX_104_1",
+      "MEX_CDMX_98_5",
     ],
     "S1eMpr3" => [
       "CEN88_5",
@@ -757,6 +758,83 @@ class CopyController extends Controller {
     "8Duwg4qe" => [
       "106_1_MTY",
       "106_9_MTY",
+    ],
+    "mZOHHxIN" => [
+      "AM_AGU_AGU_1130",
+      "AM_DUR_DUR_1370",
+      "AM_TAM_MAT_1420",
+      "AM_NL_MON_770",
+      "AM_NL_MON_1090",
+      "AM_NL_MON_1190",
+      "AM_NL_MON_630",
+      "AM_NL_MON_660",
+      "AM_NL_MON_540",
+      "AM_HID_PAC_1240",
+      "AM_TAM_REY_1170",
+      "AM_NL_NGG_600",
+      "AM_NL_NGG_690",
+      "AM_NL_NGG_1480",
+      "AM_PUE_SPCH_1170",
+      "AM_PUE_SPCH_1120",
+      "AM_PUE_SPCH_1210",
+      "AM_PUE_SPCH_920",
+      "AM_PUE_SPCH_1250",
+      "AM_TLA_TLA_1430"
+    ],
+    "T9ng0M4J" => [
+      "AM_CDMX_1470",
+      "AM_CDMX_1410",
+      "AM_CDMX_1380",
+      "AM_CDMX_660",
+      "AM_CDMX_1000",
+      "AM_CDMX_940",
+      "AM_CDMX_970",
+      "AM_CDMX_1530",
+      "AM_CDMX_900",
+      "AM_CDMX_730",
+      "AM_CDMX_1180",
+      "AM_CDMX_710",
+      "AM_CDMX_620",
+      "AM_CDMX_590",
+      "AM_CDMX_1350",
+      "AM_CDMX_540",
+      "AM_CDMX_560",
+      "AM_CDMX_860",
+      "AM_CDMX_1150"
+    ],
+    "lWMy70IH" => [
+      "AM_CDMX_1220",
+      "AM_CDMX_1260",
+      "AM_CDMX_1590",
+      "AM_CDMX_1650",
+      "AM_CDMX_830",
+      "AM_CDMX_690",
+      "AM_CDMX_760",
+      "AM_CDMX_1030",
+      "AM_CDMX_1440",
+      "AM_JAL_GUA_1150",
+      "AM_JAL_GUA_820",
+      "AM_JAL_GUA_1280",
+      "AM_JAL_GUA_1250",
+      "AM_JAL_GUA_700",
+      "AM_JAL_GUA_790",
+      "AM_JAL_GUA_1190",
+      "AM_OAX_OAX_990",
+      "AM_OAX_OAX_570",
+      "AM_MEX_TOL_1040",
+      "AM_MEX_TOL_1600",
+    ],
+    "5m24geWA" => [
+      "AM_SIN_CUL_750",
+      "AM_SIN_CUL_1150",
+      "AM_CHI_JUA_1490",
+      "AM_CHI_JUA_1000",
+      "AM_CHI_JUA_640",
+      "AM_CHI_JUA_1300",
+      "AM_CHI_JUA_800",
+      "AM_CHI_JUA_1240",
+      "AM_CHI_JUA_860",
+      "AM_BCS_PAZ_1180",
     ]
   ];
 
@@ -775,13 +853,13 @@ class CopyController extends Controller {
   }
 
   public function actionIndex() {
-    $dbr = \Yii::$app->dbr;
+    $db = \Yii::$app->dbw;
     while(true) {
 
       $archivos = (new Query())
         ->from("file")
         ->innerJoin("box", "box.id = file.box")
-        ->andWhere([">=", "[[timestamp]] at time zone box.timezone", new Expression("now() - interval '2 days'")])
+        ->andWhere(["between", "[[timestamp]] at time zone box.timezone", '2021-12-25 08:40:00', '2021-12-26 00:00:00']) // new Expression("now() - interval '2 days'")])
         ->orderBy(["timestamp" => SORT_ASC]);
 
       $condicion = ["OR"];
@@ -792,7 +870,7 @@ class CopyController extends Controller {
 
       // $this->stdout($archivos->createCommand()->getRawSql() . "\n");
 
-      foreach($archivos->each(100, $dbr) as $archivo) {
+      foreach($archivos->each(100, $db) as $archivo) {
         try {
           \Yii::$app->getDb()->createCommand()
             ->insert("file", [
@@ -803,9 +881,9 @@ class CopyController extends Controller {
               "timestamp" => $archivo["timestamp"]
             ])
             ->execute();
-          $this->stdout("{$archivo["hash"]} {$archivo["box"]} {$archivo["station"]} {$archivo["timestamp"]}\n");
+          $this->stdout("{$archivo["hash"]} {$archivo["timestamp"]} {$archivo["station"]}\n");
         } catch(\Exception $e) {
-          $this->stdout("{$archivo["hash"]} {$archivo["box"]} {$archivo["station"]} {$archivo["timestamp"]} ya existe\n");
+          $this->stdout("{$archivo["hash"]} {$archivo["timestamp"]} {$archivo["station"]} ya existe\n");
         }
       }
 
@@ -864,4 +942,46 @@ class CopyController extends Controller {
     $this->stdout("Proceso terminado en: {$tiempo}\n");
   }
 
+  public function actionPorFecha() {
+    $db = \Yii::$app->dbw;
+    $inicio = time();
+    $archivos = (new Query())
+      ->from("file")
+      ->innerJoin("box", "box.id = file.box")
+      ->andWhere([">=", "[[timestamp]] at time zone box.timezone", "{$this->fi} 00:00:00"])
+      ->andWhere(["<", "[[timestamp]] at time zone box.timezone", "{$this->ff} 00:00:00"])
+      ->orderBy(["timestamp" => SORT_ASC]);
+
+    // $total = (clone $archivos)->count();
+    // $this->stdout("Total: {$total}\n");
+
+    // $this->stdout($archivos->createCommand()->getRawSql() . "\n");
+    // return;
+    $cont = 0;
+    foreach($archivos->each(100, $db) as $archivo) {
+      $estacion = str_pad($archivo["station"], 20, " ", STR_PAD_RIGHT);
+      $ciudad = str_pad($archivo["box"], 12, " ", STR_PAD_RIGHT);
+      try {
+        \Yii::$app->getDb()->createCommand()
+          ->insert("file", [
+            "hash" => $archivo["hash"],
+            "box" => $archivo["box"],
+            "station" => $archivo["station"],
+            "filename" => $archivo["filename"],
+            "timestamp" => $archivo["timestamp"]
+          ])
+          ->execute();
+
+        $this->stdout("{$archivo["hash"]} {$archivo["timestamp"]} {$ciudad} {$estacion} \n");
+      } catch(\Exception $e) {
+        $this->stdout("{$archivo["hash"]} {$archivo["timestamp"]} {$ciudad} {$estacion} Error\n");
+      }
+      $cont++;
+    }
+
+    $tiempo = time() - $inicio;
+
+    $this->stdout("Proceso terminado en: {$tiempo}\n");
+  }
+
 }

+ 160 - 3
commands/SyncCompleteController.php

@@ -11,6 +11,20 @@ use yii\helpers\ArrayHelper;
 
 class SyncCompleteController extends Controller {
 
+  public $ciudad = null;
+  public $estacion = null;
+  public $fi = null;
+  public $ff = null;
+
+  public function options($actionId) {
+    return [
+      'ciudad',
+      'estacion',
+      'fi',
+      'ff'
+    ];
+  }
+
   public function actionIndex() {
     $estados = [
       'AGUASCALIENTES' => 'AGU',
@@ -78,7 +92,8 @@ class SyncCompleteController extends Controller {
         ->select("hash, box, station, filename, [[timestamp]] at time zone box.timezone as timestamp")
         ->from("file")
         ->innerJoin("box", "box.id = file.box")
-        ->andWhere([">=", "[[timestamp]] at time zone box.timezone", new Expression("now() - interval '2 day'")])
+        ->andWhere([">=", "[[timestamp]] at time zone box.timezone", '2021-12-24 00:00:00'])
+        // ->andWhere([">=", "[[timestamp]] at time zone box.timezone", new Expression("now() - interval '6 day'")])
         // ->andWhere(["<=", "[[timestamp]] at time zone box.timezone", '2021-10-01 00:00:00'])
         ->orderBy(["timestamp" => $order]);
 
@@ -137,15 +152,157 @@ class SyncCompleteController extends Controller {
             $errores = json_encode($modelo->getFirstErrors());
             $this->stdout("Error al guardar {$modelo->hash} {$errores}\n");
           }
+          $this->stdout("{$modelo->hash} {$modelo->archivo}\n");
         } catch(\Exception $e) {
-          $this->stdout("Error al guardar {$modelo->hash} {$modelo->archivo}\n");
+          $this->stdout("{$modelo->hash} {$modelo->archivo} ya existe\n");
         }
         $count++;
       }
-      $vuelta = $inicio - time();
+      $vuelta = time() - $inicio;
       $this->stdout("Vuelta: {$vuelta}\n");
     }
     return ExitCode::OK;
   }
 
+  public function actionPorFecha() {
+    if(!$this->fi || !$this->ff) {
+      $this->stdout("Fecha inicial y final requeridas\n");
+      return ExitCode::OK;
+    }
+    $estados = [
+      'AGUASCALIENTES' => 'AGU',
+      'BAJA CALIFORNIA' => 'BCN',
+      'BAJA CALIFORNIA SUR' => 'BCS',
+      'CAMPECHE' => 'CAM',
+      'CHIAPAS' => 'CHP',
+      'CHIHUAHUA' => 'CHH',
+      'CIUDAD DE MÉXICO' => 'CMX',
+      'COAHUILA' => 'COA',
+      'COLIMA' => 'COL',
+      'DURANGO' => 'DUR',
+      'GUANAJUATO' => 'GUA',
+      'GUERRERO' => 'GRO',
+      'HIDALGO' => 'HID',
+      'JALISCO' => 'JAL',
+      'MEXICO' => 'MEX',
+      'MICHOACAN' => 'MIC',
+      'MORELOS' => 'MOR',
+      'NAYARIT' => 'NAY',
+      'NUEVO LEON' => 'NLE',
+      'OAXACA' => 'OAX',
+      'PUEBLA' => 'PUE',
+      'QUERETARO' => 'QUE',
+      'QUINTANA ROO' => 'ROO',
+      'SAN LUIS POTOSI' => 'SLP',
+      'SINALOA' => 'SIN',
+      'SONORA' => 'SON',
+      'TABASCO' => 'TAB',
+      'TAMAULIPAS' => 'TAM',
+      'TLAXCALA' => 'TLA',
+      'VERACRUZ' => 'VER',
+      'YUCATAN' => 'YUC',
+      'ZACATECAS' => 'ZAC'
+    ];
+    $order = SORT_ASC;
+
+    $ciudadEstacion = (new Query())
+      ->select(["idCiudad", "idEstacion"])
+      ->from("box")
+      ->innerJoin("CiudadEstacion", "box.id = {{CiudadEstacion}}.[[idCiudad]]")
+      ->andWhere([
+        "box.activo" => true
+      ])
+      ->andWhere("[[idGrupo]] is not null")
+      ->all();
+    $idCiudades = ArrayHelper::getColumn($ciudadEstacion, "idCiudad");
+    $ciudades = (new Query())
+      ->select(["id", "nombre", "idEstado", "timezone", "tipo"])
+      ->from("box")
+      ->where(["id" => $idCiudades])
+      ->indexBy("id")
+      ->all();
+    $idEstaciones = ArrayHelper::getColumn($ciudadEstacion, "idEstacion");
+    $estaciones = (new Query())
+      ->select(["id", "clave", "siglas", "frecuencia", "descripcion"])
+      ->from("Estacion")
+      ->andWhere(["id" => $idEstaciones])
+      ->indexBy("clave")
+      ->all();
+
+    $inicio = time();
+    $archivos = (new Query())
+      ->select("hash, box, station, filename, [[timestamp]] at time zone box.timezone as timestamp")
+      ->from("file")
+      ->innerJoin("box", "box.id = file.box")
+      ->andWhere([">=", "[[timestamp]] at time zone box.timezone", "{$this->fi} 00:00:00"])
+      // ->andWhere([">=", "[[timestamp]] at time zone box.timezone", new Expression("now() - interval '6 day'")])
+      ->andWhere(["<=", "[[timestamp]] at time zone box.timezone", "{$this->ff} 00:00:00"])
+      ->orderBy(["timestamp" => $order]);
+
+    // $this->stdout("{$archivos->createCommand()->getRawSql()}\n");
+
+    $count = 0;
+    foreach($archivos->each() as $archivo) {
+      if(!isset($ciudades[$archivo["box"]]) || !isset($estaciones[$archivo["station"]])) {
+        continue;
+      }
+      $modelo = new Descarga();
+      $modelo->hash = $archivo["hash"];
+      $modelo->estacion = $archivo["station"];
+      $modelo->archivo = $archivo["filename"];
+      $modelo->ciudad = $archivo["box"];
+      $modelo->pc = null;
+      $modelo->fecha = $archivo["timestamp"];
+      $modelo->descargado = false;
+      $modelo->nombre = basename($archivo["filename"]);
+      $ciudad = $ciudades[$archivo["box"]];
+      $estacion = $estaciones[$archivo["station"]];
+      $fecha = \DateTime::createFromFormat("Y-m-d H:i:s", $archivo["timestamp"]);
+      $siglas = explode("-", $estacion["siglas"]);
+      $tipo = "";
+      $senal = $siglas[0];
+      if(isset($siglas[1])) {
+        $tipo = $siglas[1];
+      }
+      if($tipo === "") {
+        if($ciudad["tipo"] === "tv") {
+          $tipo = "TDT";
+        } elseif ($ciudad["tipo"] === "radio") {
+          $tipo = "FM";
+        } else {
+          $tipo = "AM";
+        }
+      }
+      $nombreCiudad = $ciudad["idEstado"];
+      if($tipo === "AM") {
+        $desc = explode(",", $estacion["descripcion"]);
+        $nombreCiudad = $estacion["descripcion"];
+        if(isset($desc[1])) {
+          $nombreCiudad = $desc[1];
+        }
+      }
+      if(isset($estados[$nombreCiudad])) {
+        $nombreCiudad = $estados[$nombreCiudad];
+      }
+      $nombreCiudad = str_replace(" ", "_", trim($nombreCiudad));
+      $y = $fecha->format("Y");
+      $m = $fecha->format("m");
+      $d = $fecha->format("d");
+      $modelo->ruta = "{$y}/{$tipo}/{$nombreCiudad}/{$senal}/{$m}/{$d}";
+      try {
+        if(!$modelo->save()) {
+          $errores = json_encode($modelo->getFirstErrors());
+          $this->stdout("Error al guardar {$modelo->hash} {$errores}\n");
+        }
+        $this->stdout("{$modelo->hash} {$modelo->archivo}\n");
+      } catch(\Exception $e) {
+        $this->stdout("{$modelo->hash} {$modelo->archivo} ya existe\n");
+      }
+      $count++;
+    }
+    $vuelta = time() - $inicio;
+    $this->stdout("Vuelta: {$vuelta}\n");
+    return ExitCode::OK;
+  }
+
 }

+ 6 - 1
commands/SyncController.php

@@ -16,6 +16,7 @@ class SyncController extends Controller {
   public $estacion = null;
   public $fi = null;
   public $ff = null;
+  public $pc = null;
 
   public function options($actionID) {
     return [
@@ -24,7 +25,8 @@ class SyncController extends Controller {
       'ciudad',
       'estacion',
       'fi',
-      'ff'
+      'ff',
+      'pc'
     ];
   }
 
@@ -304,6 +306,9 @@ class SyncController extends Controller {
       $modelo->archivo = $archivo["filename"];
       $modelo->ciudad = $archivo["box"];
       $modelo->pc = null;
+      if($this->pc !== null) {
+        $modelo->pc = $this->pc;
+      }
       $modelo->fecha = $archivo["timestamp"];
       $modelo->descargado = false;
       $modelo->nombre = basename($archivo["filename"]);