|
@@ -11,6 +11,20 @@ use yii\helpers\ArrayHelper;
|
|
|
|
|
|
|
|
class SyncCompleteController extends Controller {
|
|
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() {
|
|
public function actionIndex() {
|
|
|
$estados = [
|
|
$estados = [
|
|
|
'AGUASCALIENTES' => 'AGU',
|
|
'AGUASCALIENTES' => 'AGU',
|
|
@@ -78,7 +92,8 @@ class SyncCompleteController extends Controller {
|
|
|
->select("hash, box, station, filename, [[timestamp]] at time zone box.timezone as timestamp")
|
|
->select("hash, box, station, filename, [[timestamp]] at time zone box.timezone as timestamp")
|
|
|
->from("file")
|
|
->from("file")
|
|
|
->innerJoin("box", "box.id = file.box")
|
|
->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'])
|
|
// ->andWhere(["<=", "[[timestamp]] at time zone box.timezone", '2021-10-01 00:00:00'])
|
|
|
->orderBy(["timestamp" => $order]);
|
|
->orderBy(["timestamp" => $order]);
|
|
|
|
|
|
|
@@ -137,15 +152,157 @@ class SyncCompleteController extends Controller {
|
|
|
$errores = json_encode($modelo->getFirstErrors());
|
|
$errores = json_encode($modelo->getFirstErrors());
|
|
|
$this->stdout("Error al guardar {$modelo->hash} {$errores}\n");
|
|
$this->stdout("Error al guardar {$modelo->hash} {$errores}\n");
|
|
|
}
|
|
}
|
|
|
|
|
+ $this->stdout("{$modelo->hash} {$modelo->archivo}\n");
|
|
|
} catch(\Exception $e) {
|
|
} catch(\Exception $e) {
|
|
|
- $this->stdout("Error al guardar {$modelo->hash} {$modelo->archivo}\n");
|
|
|
|
|
|
|
+ $this->stdout("{$modelo->hash} {$modelo->archivo} ya existe\n");
|
|
|
}
|
|
}
|
|
|
$count++;
|
|
$count++;
|
|
|
}
|
|
}
|
|
|
- $vuelta = $inicio - time();
|
|
|
|
|
|
|
+ $vuelta = time() - $inicio;
|
|
|
$this->stdout("Vuelta: {$vuelta}\n");
|
|
$this->stdout("Vuelta: {$vuelta}\n");
|
|
|
}
|
|
}
|
|
|
return ExitCode::OK;
|
|
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;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|