|
|
@@ -4,18 +4,19 @@ namespace v1\controllers;
|
|
|
|
|
|
use common\rest\AuthController;
|
|
|
use common\rest\JsonController;
|
|
|
+use DateTime;
|
|
|
use yii\db\Query;
|
|
|
|
|
|
class ReporteGlobalController extends JsonController {
|
|
|
|
|
|
public function actionIndex() {
|
|
|
$fechas = [
|
|
|
- ["2022-08-01 00:00:00", "2022-08,31 23:59:59"],
|
|
|
- ["2022-09-01 00:00:00", "2022-09,30 23:59:59"],
|
|
|
- ["2022-10-01 00:00:00", "2022-10,31 23:59:59"],
|
|
|
- ["2022-11-01 00:00:00", "2022-11,30 23:59:59"],
|
|
|
- ["2022-12-01 00:00:00", "2022-12,31 23:59:59"],
|
|
|
- ["2023-01-01 00:00:00", "2023-01,31 23:59:59"],
|
|
|
+ ["2022-08-01 00:00:00", "2022-08-01 00:00:00","2022-08-31 23:59:59"],
|
|
|
+ ["2022-08-01 00:00:00", "2022-09-01 00:00:00","2022-09-30 23:59:59"],
|
|
|
+ ["2022-08-01 00:00:00", "2022-10-01 00:00:00","2022-10-31 23:59:59"],
|
|
|
+ ["2022-08-01 00:00:00", "2022-11-01 00:00:00","2022-11-30 23:59:59"],
|
|
|
+ ["2022-08-01 00:00:00", "2022-12-01 00:00:00","2022-12-31 23:59:59"],
|
|
|
+ ["2022-08-01 00:00:00", "2023-01-01 00:00:00","2023-01-31 23:59:59"],
|
|
|
];
|
|
|
|
|
|
$query = (new Query())
|
|
|
@@ -43,12 +44,14 @@ class ReporteGlobalController extends JsonController {
|
|
|
->innerJoin("UsuarioGrupo", "{{UsuarioGrupo}}.[[idUsuario]] = {{Usuario}}.id")
|
|
|
->innerJoin("Grupo", "{{Grupo}}.id = {{UsuarioGrupo}}.[[idGrupo]]")
|
|
|
->innerJoin("EventoGrupo", "{{EventoGrupo}}.[[idGrupo]] = {{Grupo}}.id")
|
|
|
+ ->innerJoin("Evento", "{{Evento}}.id = {{EventoGrupo}}.[[idEvento]]")
|
|
|
->leftJoin("Resultado", "{{Resultado}}.[[idUsuario]] = {{Usuario}}.id and {{Resultado}}.[[idEvento]] = {{Evento}}.id")
|
|
|
+ ->andWhere(["{{Usuario}}.eliminado" => null])
|
|
|
->groupBy(["{{Usuario}}.verificado", "facebook", "facebookVerificado", "twitter", "twitterVerificado", "instagram", "instagramVerificado", "uId"]);
|
|
|
|
|
|
$query2 = (new Query())
|
|
|
->select([
|
|
|
- "verificado",
|
|
|
+ // "verificado",
|
|
|
"[[eventosFacebook]]",
|
|
|
"[[participacionesFacebook]]",
|
|
|
"[[eventosTwitter]]",
|
|
|
@@ -65,31 +68,106 @@ class ReporteGlobalController extends JsonController {
|
|
|
foreach($fechas as $_fechas) {
|
|
|
$queryClon = (clone $query)->andWhere([
|
|
|
"AND",
|
|
|
- [">=", "{{Evento}}.[[fechaInicio]]", $_fechas[0]],
|
|
|
- ["<=", "{{Evento}}.[[fechaInicio]]", $_fechas[1]],
|
|
|
- [">=", "verificado", $_fechas[0]],
|
|
|
- ["<=", "verificado", $_fechas[1]],
|
|
|
+ [">=", "{{Evento}}.[[fechaInicio]]", $_fechas[1]],
|
|
|
+ ["<=", "{{Evento}}.[[fechaInicio]]", $_fechas[2]],
|
|
|
+ [">=", "{{Usuario}}.verificado", $_fechas[0]],
|
|
|
+ ["<=", "{{Usuario}}.verificado", $_fechas[2]],
|
|
|
]);
|
|
|
- $mes = (clone $query2)->from(["t" => $queryClon])->one();
|
|
|
+
|
|
|
+ $mes = (clone $query2)->from(["t" => $queryClon]);
|
|
|
+
|
|
|
+ $contadorPorcentajesFacebook = 0;
|
|
|
+ $porcentajesFacebook = 0;
|
|
|
+ $contadorPorcentajesTwitter = 0;
|
|
|
+ $porcentajesTwitter = 0;
|
|
|
+ $contadorPorcentajesInstagram = 0;
|
|
|
+ $porcentajesInstagram = 0;
|
|
|
+ foreach($mes->each() as $_mes){
|
|
|
+ $eventosFacebook = $_mes["eventosFacebook"];
|
|
|
+ $participacionesFacebook = $_mes["participacionesFacebook"];
|
|
|
+ $eventosTwitter = $_mes["eventosTwitter"];
|
|
|
+ $participacionesTwitter = $_mes["participacionesTwitter"];
|
|
|
+ $eventosInstagram = $_mes["eventosInstagram"];
|
|
|
+ $participacionesInstagram = $_mes["participacionesInstagram"];
|
|
|
+
|
|
|
+ $porcentajeParticipacionFacebook = 0;
|
|
|
+ if ($eventosFacebook > 0) {
|
|
|
+ $contadorPorcentajesFacebook += 1;
|
|
|
+ $porcentajeParticipacionFacebook = ($participacionesFacebook/$eventosFacebook)*100;
|
|
|
+ $porcentajesFacebook += $porcentajeParticipacionFacebook;
|
|
|
+ }
|
|
|
+
|
|
|
+ $porcentajeParticipacionTwitter = 0;
|
|
|
+ if ($eventosTwitter > 0) {
|
|
|
+ $contadorPorcentajesTwitter += 1;
|
|
|
+ $porcentajeParticipacionTwitter = ($participacionesTwitter/$eventosTwitter)*100;
|
|
|
+ $porcentajesTwitter += $porcentajeParticipacionTwitter;
|
|
|
+ }
|
|
|
+
|
|
|
+ $porcentajeParticipacionInstagram = 0;
|
|
|
+ if ($eventosInstagram > 0) {
|
|
|
+ $contadorPorcentajesInstagram += 1;
|
|
|
+ $porcentajeParticipacionInstagram = ($participacionesInstagram/$eventosInstagram)*100;
|
|
|
+ $porcentajesInstagram += $porcentajeParticipacionInstagram;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $totalPorcentajesFacebook = 0;
|
|
|
+ $totalPorcentajesTwitter = 0;
|
|
|
+ $totalPorcentajesInstagram = 0;
|
|
|
|
|
|
- $meses[] = $mes;
|
|
|
+ if ($contadorPorcentajesFacebook > 0) {
|
|
|
+ $totalPorcentajesFacebook = $porcentajesFacebook/$contadorPorcentajesFacebook;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($contadorPorcentajesTwitter > 0) {
|
|
|
+ $totalPorcentajesTwitter = $porcentajesTwitter/$contadorPorcentajesTwitter;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($contadorPorcentajesInstagram > 0) {
|
|
|
+ $totalPorcentajesInstagram = $porcentajesInstagram/$contadorPorcentajesInstagram;
|
|
|
+ }
|
|
|
+
|
|
|
+ $porcentajeMaximo = 0;
|
|
|
+ if($totalPorcentajesFacebook > $totalPorcentajesTwitter) {
|
|
|
+ if ($totalPorcentajesFacebook > $totalPorcentajesInstagram) {
|
|
|
+ $porcentajeMaximo = $totalPorcentajesFacebook;
|
|
|
+ } else {
|
|
|
+ $porcentajeMaximo = $totalPorcentajesInstagram;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if ($totalPorcentajesTwitter > $totalPorcentajesInstagram) {
|
|
|
+ $porcentajeMaximo = $totalPorcentajesTwitter;
|
|
|
+ } else {
|
|
|
+ $porcentajeMaximo = $totalPorcentajesInstagram;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $meses[] = [
|
|
|
+ "fechaInicio" => $_fechas[0],
|
|
|
+ "fechaFinal" => $_fechas[1],
|
|
|
+ "totalParticipantesFacebook" => $contadorPorcentajesFacebook,
|
|
|
+ "porcentajesParticipacionFacebook" => $totalPorcentajesFacebook,
|
|
|
+ "totalParticipantesTwitter" => $contadorPorcentajesTwitter,
|
|
|
+ "porcentajesParticipacionTwitter" => $totalPorcentajesTwitter,
|
|
|
+ "totalParticipantesInstagram" => $contadorPorcentajesInstagram,
|
|
|
+ "porcentajesParticipacionInstagram" => $totalPorcentajesInstagram,
|
|
|
+ "porcentajeParticipacionGlobal" => $totalPorcentajesFacebook+$totalPorcentajesTwitter+$totalPorcentajesInstagram,
|
|
|
+ "porcentajeMaximoGlobal" => $porcentajeMaximo
|
|
|
+ ];
|
|
|
}
|
|
|
|
|
|
return $meses;
|
|
|
}
|
|
|
|
|
|
- public function actionGuardar() {
|
|
|
- $metodo = "";
|
|
|
- $fechaInicio = trim($this->req->getBodyParam("fechaInicio", ""));
|
|
|
- $fechaFinal = trim($this->req->getBodyParam("fechaFinal", ""));
|
|
|
-
|
|
|
+ public function actionCsv() {
|
|
|
$fechas = [
|
|
|
- ["2022-08-01 00:00:00", "2022-08,31 23:59:59"],
|
|
|
- ["2022-09-01 00:00:00", "2022-09,30 23:59:59"],
|
|
|
- ["2022-10-01 00:00:00", "2022-10,31 23:59:59"],
|
|
|
- ["2022-11-01 00:00:00", "2022-11,30 23:59:59"],
|
|
|
- ["2022-12-01 00:00:00", "2022-12,31 23:59:59"],
|
|
|
- ["2023-01-01 00:00:00", "2023-01,31 23:59:59"],
|
|
|
+ ["2022-08-01 00:00:00", "2022-08-01 00:00:00","2022-08-31 23:59:59"],
|
|
|
+ ["2022-08-01 00:00:00", "2022-09-01 00:00:00","2022-09-30 23:59:59"],
|
|
|
+ ["2022-08-01 00:00:00", "2022-10-01 00:00:00","2022-10-31 23:59:59"],
|
|
|
+ ["2022-08-01 00:00:00", "2022-11-01 00:00:00","2022-11-30 23:59:59"],
|
|
|
+ ["2022-08-01 00:00:00", "2022-12-01 00:00:00","2022-12-31 23:59:59"],
|
|
|
+ ["2022-08-01 00:00:00", "2023-01-01 00:00:00","2023-01-31 23:59:59"],
|
|
|
];
|
|
|
|
|
|
$query = (new Query())
|
|
|
@@ -117,12 +195,14 @@ class ReporteGlobalController extends JsonController {
|
|
|
->innerJoin("UsuarioGrupo", "{{UsuarioGrupo}}.[[idUsuario]] = {{Usuario}}.id")
|
|
|
->innerJoin("Grupo", "{{Grupo}}.id = {{UsuarioGrupo}}.[[idGrupo]]")
|
|
|
->innerJoin("EventoGrupo", "{{EventoGrupo}}.[[idGrupo]] = {{Grupo}}.id")
|
|
|
+ ->innerJoin("Evento", "{{Evento}}.id = {{EventoGrupo}}.[[idEvento]]")
|
|
|
->leftJoin("Resultado", "{{Resultado}}.[[idUsuario]] = {{Usuario}}.id and {{Resultado}}.[[idEvento]] = {{Evento}}.id")
|
|
|
+ ->andWhere(["{{Usuario}}.eliminado" => null])
|
|
|
->groupBy(["{{Usuario}}.verificado", "facebook", "facebookVerificado", "twitter", "twitterVerificado", "instagram", "instagramVerificado", "uId"]);
|
|
|
|
|
|
$query2 = (new Query())
|
|
|
->select([
|
|
|
- "verificado",
|
|
|
+ // "verificado",
|
|
|
"[[eventosFacebook]]",
|
|
|
"[[participacionesFacebook]]",
|
|
|
"[[eventosTwitter]]",
|
|
|
@@ -139,15 +219,125 @@ class ReporteGlobalController extends JsonController {
|
|
|
foreach($fechas as $_fechas) {
|
|
|
$queryClon = (clone $query)->andWhere([
|
|
|
"AND",
|
|
|
- [">=", "{{Evento}}.[[fechaInicio]]", $_fechas[0]],
|
|
|
- ["<=", "{{Evento}}.[[fechaInicio]]", $_fechas[1]],
|
|
|
- [">=", "verificado", $_fechas[0]],
|
|
|
- ["<=", "verificado", $_fechas[1]],
|
|
|
+ [">=", "{{Evento}}.[[fechaInicio]]", $_fechas[1]],
|
|
|
+ ["<=", "{{Evento}}.[[fechaInicio]]", $_fechas[2]],
|
|
|
+ [">=", "{{Usuario}}.verificado", $_fechas[0]],
|
|
|
+ ["<=", "{{Usuario}}.verificado", $_fechas[2]],
|
|
|
]);
|
|
|
- $mes = (clone $query2)->from(["t" => $queryClon])->one();
|
|
|
+
|
|
|
+ $mes = (clone $query2)->from(["t" => $queryClon]);
|
|
|
+
|
|
|
+ $contadorPorcentajesFacebook = 0;
|
|
|
+ $porcentajesFacebook = 0;
|
|
|
+ $contadorPorcentajesTwitter = 0;
|
|
|
+ $porcentajesTwitter = 0;
|
|
|
+ $contadorPorcentajesInstagram = 0;
|
|
|
+ $porcentajesInstagram = 0;
|
|
|
+ foreach($mes->each() as $_mes){
|
|
|
+ $eventosFacebook = $_mes["eventosFacebook"];
|
|
|
+ $participacionesFacebook = $_mes["participacionesFacebook"];
|
|
|
+ $eventosTwitter = $_mes["eventosTwitter"];
|
|
|
+ $participacionesTwitter = $_mes["participacionesTwitter"];
|
|
|
+ $eventosInstagram = $_mes["eventosInstagram"];
|
|
|
+ $participacionesInstagram = $_mes["participacionesInstagram"];
|
|
|
+
|
|
|
+ $porcentajeParticipacionFacebook = 0;
|
|
|
+ if ($eventosFacebook > 0) {
|
|
|
+ $contadorPorcentajesFacebook += 1;
|
|
|
+ $porcentajeParticipacionFacebook = ($participacionesFacebook/$eventosFacebook)*100;
|
|
|
+ $porcentajesFacebook += $porcentajeParticipacionFacebook;
|
|
|
+ }
|
|
|
+
|
|
|
+ $porcentajeParticipacionTwitter = 0;
|
|
|
+ if ($eventosTwitter > 0) {
|
|
|
+ $contadorPorcentajesTwitter += 1;
|
|
|
+ $porcentajeParticipacionTwitter = ($participacionesTwitter/$eventosTwitter)*100;
|
|
|
+ $porcentajesTwitter += $porcentajeParticipacionTwitter;
|
|
|
+ }
|
|
|
+
|
|
|
+ $porcentajeParticipacionInstagram = 0;
|
|
|
+ if ($eventosInstagram > 0) {
|
|
|
+ $contadorPorcentajesInstagram += 1;
|
|
|
+ $porcentajeParticipacionInstagram = ($participacionesInstagram/$eventosInstagram)*100;
|
|
|
+ $porcentajesInstagram += $porcentajeParticipacionInstagram;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $totalPorcentajesFacebook = 0;
|
|
|
+ $totalPorcentajesTwitter = 0;
|
|
|
+ $totalPorcentajesInstagram = 0;
|
|
|
|
|
|
- $meses[] = $mes;
|
|
|
+ if ($contadorPorcentajesFacebook > 0) {
|
|
|
+ $totalPorcentajesFacebook = $porcentajesFacebook/$contadorPorcentajesFacebook;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($contadorPorcentajesTwitter > 0) {
|
|
|
+ $totalPorcentajesTwitter = $porcentajesTwitter/$contadorPorcentajesTwitter;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($contadorPorcentajesInstagram > 0) {
|
|
|
+ $totalPorcentajesInstagram = $porcentajesInstagram/$contadorPorcentajesInstagram;
|
|
|
+ }
|
|
|
+
|
|
|
+ $porcentajeMaximo = 0;
|
|
|
+ if($totalPorcentajesFacebook > $totalPorcentajesTwitter) {
|
|
|
+ if ($totalPorcentajesFacebook > $totalPorcentajesInstagram) {
|
|
|
+ $porcentajeMaximo = $totalPorcentajesFacebook;
|
|
|
+ } else {
|
|
|
+ $porcentajeMaximo = $totalPorcentajesInstagram;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if ($totalPorcentajesTwitter > $totalPorcentajesInstagram) {
|
|
|
+ $porcentajeMaximo = $totalPorcentajesTwitter;
|
|
|
+ } else {
|
|
|
+ $porcentajeMaximo = $totalPorcentajesInstagram;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $meses[] = [
|
|
|
+ "fechaInicio" => $_fechas[1],
|
|
|
+ "fechaFinal" => $_fechas[2],
|
|
|
+ "totalParticipantesFacebook" => $contadorPorcentajesFacebook,
|
|
|
+ "porcentajesParticipacionFacebook" => $totalPorcentajesFacebook,
|
|
|
+ "totalParticipantesTwitter" => $contadorPorcentajesTwitter,
|
|
|
+ "porcentajesParticipacionTwitter" => $totalPorcentajesTwitter,
|
|
|
+ "totalParticipantesInstagram" => $contadorPorcentajesInstagram,
|
|
|
+ "porcentajesParticipacionInstagram" => $totalPorcentajesInstagram,
|
|
|
+ "porcentajeParticipacionGlobal" => $totalPorcentajesFacebook+$totalPorcentajesTwitter+$totalPorcentajesInstagram,
|
|
|
+ "porcentajeMaximoGlobal" => $porcentajeMaximo
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ $texto = ",VERIFICADOS FACEBOOK,VERIFICADOS INSTAGRAM,VERIFICADOS TWITTER,PORCENTAJE DE PARTICIPACIÓN GLOBAL,PORCENTAJE DE PARTICIPACIÓN - FACEBOOK,PORCENTAJE DE PARTICIPACIÓN - INSTAGRAM,PORCENTAJE DE PARTICIPACIÓN - TWITTER,PORCENTAJE MÁXIMO DE PARTICIPACIÓN GLOBAL\n";
|
|
|
+
|
|
|
+ foreach($meses as $mes) {
|
|
|
+ $fechaInicio = (DateTime::createFromFormat("Y-m-d H:i:s", $mes["fechaInicio"]))->format('d-m-Y');
|
|
|
+ $fechaFinal = (DateTime::createFromFormat("Y-m-d H:i:s", $mes["fechaFinal"]))->format('d-m-Y');
|
|
|
+ $texto .= "".
|
|
|
+ $fechaInicio." - ".$fechaFinal.
|
|
|
+ ",".$mes["totalParticipantesFacebook"].
|
|
|
+ ",".$mes["totalParticipantesInstagram"].
|
|
|
+ ",".$mes["totalParticipantesTwitter"].
|
|
|
+ ",".$mes["porcentajeParticipacionGlobal"].
|
|
|
+ ",".$mes["porcentajesParticipacionFacebook"].
|
|
|
+ ",".$mes["porcentajesParticipacionInstagram"].
|
|
|
+ ",".$mes["porcentajesParticipacionTwitter"].
|
|
|
+ ",".$mes["porcentajeMaximoGlobal"]."\n";
|
|
|
}
|
|
|
+
|
|
|
+ return \Yii::$app->getResponse()->sendContentAsFile($texto, "reporte_global.csv");
|
|
|
+ }
|
|
|
+
|
|
|
+ public function actionGuardar() {
|
|
|
+ $metodo = "";
|
|
|
+ if(\Yii::$app->request->isPost) {
|
|
|
+ $metodo = "POST";
|
|
|
+ }
|
|
|
+ if(\Yii::$app->request->isPut) {
|
|
|
+ $metodo = "PUT";
|
|
|
+ }
|
|
|
+
|
|
|
+ return "Ejemplo de un método {$metodo}";
|
|
|
}
|
|
|
|
|
|
public function actionEliminar() {
|