2023-05-24 10:42:52 +02:00
< ? php
$tc = microtime ( true );
// Comprova els arguments, en cas de no existir presenta l'ajuda.
if ( ! empty ( $_SERVER [ " argv " ][ 1 ])){
$argument = $_SERVER [ " argv " ][ 1 ];
} else {
// Presenta l'ajuda
2024-08-21 20:50:34 +02:00
echo " \ e[0;31;40mNO HE REBUT la variable. \ e[0m \n " ;
2023-05-24 10:42:52 +02:00
exit ;
}
$lloc = $argument ;
// ara podrá carregar la configuració i el logger
include ( " " . $lloc . " /configuracio/bot_plus_cfg.php " );
include ( " " . $lloc . " /utils/bot_plus_funcions.php " );
require_once ( " " . $lloc . " /lib/logger.php " );
// inicia el log
$log = new Logging ();
$log -> lfile ( '' . $log_fitxer . '' );
$a = 0 ;
$b = 0 ;
$c = 0 ;
$d = 0 ;
2024-08-21 20:50:34 +02:00
$fitx_json = $lloc . " /fitxers/impulsos.json " ;
$json_dec = json_decode ( file_get_contents ( $fitx_json ), true );
$registres = count ( $json_dec );
2023-05-24 10:42:52 +02:00
2024-08-21 20:50:34 +02:00
if ( $registres > 0 ) {
2023-05-24 10:42:52 +02:00
//$impuls_resum = exec("cat ".$lloc."/fitxers/impulsos/impulsos.txt", $eix_resu, $resp_resu);
$impuls_resum = exec ( " cat " . $lloc . " /fitxers/impulsos.txt | grep 'reblog' | awk ' { print $ 2}' " , $eix_ir , $resp_ir );
2024-08-21 20:50:34 +02:00
//print_r($eix_ir);
/**
// va be. a desenrrollar.
$criteri = " reblog " ;
//$criteri = "favourite";
$impuls_resum = array_filter ( $json_dec , function ( $json_dec ) use ( $criteri ) {
if ( stripos ( $json_dec [ 'mencio' ], $criteri ) !== false ) {
return true ;
}
return false ;
});
print_r ( $impuls_resum );
exit ;
**/
2023-05-24 10:42:52 +02:00
//echo "impuls resum: \n".$impuls_resum."\n";
2024-08-21 20:50:34 +02:00
//$impul_resum = explode("\n",$impuls_resum);
2023-05-24 10:42:52 +02:00
/**
echo " feta matriu \n " ;
print_r ( $impuls_resum );
**/
//echo "contant valors:\n";
2024-08-21 20:50:34 +02:00
echo " \ e[1;37;40mESTADÍSTIQUES. \ e[0m \n " ;
echo " \n \ e[96mIMPULSOS \ e[0m \n " ;
2023-05-24 10:42:52 +02:00
$ferono_rebs = count ( $eix_ir );
2024-08-21 20:50:34 +02:00
//$ferono_rebs = count($impuls_resum);
2023-05-24 10:42:52 +02:00
if ( $ferono_rebs > 0 ) {
$mat_reb = array_count_values ( $eix_ir );
//print_r($mat_reb);
2024-08-21 20:50:34 +02:00
echo " \ e[92m--USUARIS \ e[0m \n " ;
2023-05-24 10:42:52 +02:00
//echo "valors dels impulsos ordenats\n";
//$mat_reb_ord = arsort($mat_reb);
//var_dump($mat_reb_ord);
//print_r($mat_reb_ord);
arsort ( $mat_reb );
$a = 0 ;
foreach ( $mat_reb as $clau => $valor ) {
echo " $clau = $valor\n " ;
$mat_reb_f [] = array ( 'nom' => $clau , 'nombre' => $valor );
$a ++ ;
}
echo $a . " " . (( $a <> 1 ) ? " persones han " : " persona ha " ) . " impulsat \n " ;
//echo "matriu ordenada:\n";
//print_r($mat_reb_f);
// quants tenen els mateix nombre que el primer?
$primera = $mat_reb_f [ 0 ][ 'nombre' ];
//echo $primer."\n";
$acabau = count ( $mat_reb_f );
for ( $i = 0 ; $i < $acabau ; $i ++ ) {
if ( $mat_reb_f [ $i ][ 'nombre' ] == $primera ) {
$mat_reb_fp [] = array ( 'article' => $clau , 'nombre' => $valor );
}
}
$usu_imp_primers = count ( $mat_reb_fp );
2024-08-21 20:50:34 +02:00
echo " \ e[4mN'hi ha " . $usu_imp_primers . " " . (( $usu_imp_primers <> 1 ) ? " persones " : " persona " ) . " amb el mateix nombre. \ e[0m \n \n " ;
2023-05-24 10:42:52 +02:00
2024-08-21 20:50:34 +02:00
echo " \ e[92m--TUT \ e[0m \n " ;
2023-05-24 10:42:52 +02:00
$public_resum_r = exec ( " cat " . $lloc . " /fitxers/impulsos.txt | grep 'reblog' | awk ' { print $ 4}' " , $eix_pr , $resp_pr );
//echo "contant valors:\n";
$mat_res = array_count_values ( $eix_pr );
//print_r($mat_res);
//echo "valors ordenats\n";
$b = 0 ;
arsort ( $mat_res );
foreach ( $mat_res as $clau => $valor ) {
echo " $clau = $valor\n " ;
$mat_res_f [] = array ( 'article' => $clau , 'nombre' => $valor );
$b ++ ;
}
echo $b . " " . (( $b <> 1 ) ? " tuts impulsats " : " tut impulsat " ) . " \n " ;
// quants tenen els mateix nombre que el primer?
$primer = $mat_res_f [ 0 ][ 'nombre' ];
//echo $primer."\n";
$acabaa = count ( $mat_res_f );
for ( $i = 0 ; $i < $acabaa ; $i ++ ) {
if ( $mat_res_f [ $i ][ 'nombre' ] == $primer ) {
$mat_res_fp [] = array ( 'article' => $clau , 'nombre' => $valor );
}
}
$tuts_imp_primers = count ( $mat_res_fp );
echo " N'hi ha " . $tuts_imp_primers . " amb el mateix nombre. \n \n " ;
} else {
2024-08-21 20:50:34 +02:00
echo " \ e[1;37;40mEncara sense dades. \ e[0m \n \n " ;
2023-05-24 10:42:52 +02:00
$tuts_imp_primers = 0 ;
$usu_imp_primers = 0 ;
}
2024-08-21 20:50:34 +02:00
echo " \ e[96mFAVORITS \ e[0m \n " ;
2023-05-24 10:42:52 +02:00
$favorits_resum = exec ( " cat " . $lloc . " /fitxers/impulsos.txt | grep 'favourite' | awk ' { print $ 2}' " , $eix_frs , $resp_frs );
$ferono_favs = count ( $eix_frs );
if ( $ferono_favs > 0 ) {
2024-08-21 20:50:34 +02:00
echo " \ e[92m--USUARIS \ e[0m \n " ;
2023-05-24 10:42:52 +02:00
$mat_fav = array_count_values ( $eix_frs );
arsort ( $mat_fav );
$c = 0 ;
foreach ( $mat_fav as $clau => $valor ) {
echo " $clau = $valor\n " ;
$mat_fav_f [] = array ( 'nom' => $clau , 'nombre' => $valor );
$c ++ ;
}
//echo $c. " persones han fet favorit.\n";
echo $c . " " . (( $c <> 1 ) ? " persones han " : " persona ha " ) . " fet favorit \n " ;
// quants tenen els mateix nombre que el primer?
2024-08-21 20:50:34 +02:00
$primer_f = $mat_fav_f [ 0 ][ 'nombre' ];
2023-05-24 10:42:52 +02:00
//echo $primer."\n";
$acabar = count ( $mat_fav_f );
for ( $i = 0 ; $i < $acabar ; $i ++ ) {
2024-08-21 20:50:34 +02:00
if ( $mat_fav_f [ $i ][ 'nombre' ] == $primer_f ) {
2023-05-24 10:42:52 +02:00
$mat_fav_fs [] = array ( 'article' => $clau , 'nombre' => $valor );
}
}
$usu_fav_primers = count ( $mat_fav_fs );
echo " N'hi ha " . $usu_fav_primers . " " . (( $usu_fav_primers <> 1 ) ? " persones " : " persona " ) . " amb el mateix nombre. \n \n " ;
2024-08-21 20:50:34 +02:00
echo " \ e[92m--TUT \ e[0m \n " ;
2023-05-24 10:42:52 +02:00
$public_resum_f = exec ( " cat " . $lloc . " /fitxers/impulsos.txt | grep 'favourite' | awk ' { print $ 4}' " , $eix_fr , $resp_pr );
//print_r($eix_fr);
$mat_favs = array_count_values ( $eix_fr );
arsort ( $mat_favs );
$d = 0 ;
foreach ( $mat_favs as $clau => $valor ) {
echo " $clau = $valor\n " ;
$mat_fav_fsb [] = array ( 'article' => $clau , 'nombre' => $valor );
$d ++ ;
}
echo $d . " " . (( $d <> 1 ) ? " tuts favorits " : " tut favorit " ) . " \n " ;
//print_r($mat_fav_fbs);
// quants tenen els mateix nombre que el primer?
2024-08-21 20:50:34 +02:00
$primer_r = $mat_fav_fsb [ 0 ][ 'nombre' ];
2023-05-24 10:42:52 +02:00
//echo "valor del primer: ".$primer."\n";
$acabat = count ( $mat_fav_fsb );
for ( $i = 0 ; $i < $acabat ; $i ++ ) {
2024-08-21 20:50:34 +02:00
if ( $mat_fav_fsb [ $i ][ 'nombre' ] == $primer_r ) {
$mat_fav_fsba [] = array ( 'article' => $mat_fav_fsb [ $i ][ " article " ], 'nombre' => $mat_fav_fsb [ $i ][ " nombre " ]);
2023-05-24 10:42:52 +02:00
}
}
//print_r($mat_fav_fsba);
$tuts_fav_primers = count ( $mat_fav_fsba );
echo " N'hi ha " . $tuts_fav_primers . " amb el mateix nombre. \n \n " ;
2024-08-21 20:50:34 +02:00
$usu_favs_primers = 0 ;
2023-05-24 10:42:52 +02:00
} else {
2024-08-21 20:50:34 +02:00
echo " \ e[1;37;40mEncara sense dades. \ e[0m \n \n " ;
$usu_fav_primers = 0 ;
$tuts_fav_primers = 0 ;
2023-05-24 10:42:52 +02:00
}
if ( isset ( $mat_reb_f )){
$us_imp = array_values ( $mat_reb_f )[ 0 ][ 'nom' ];
$nu_imp = array_values ( $mat_reb_f )[ 0 ][ 'nombre' ];
} else {
$us_imp = 0 ;
$nu_imp = 0 ;
}
if ( isset ( $mat_res_f )) {
$mes_comp_id = array_values ( $mat_res_f )[ 0 ][ 'article' ];
$mes_comp_vl = array_values ( $mat_res_f )[ 0 ][ 'nombre' ];
} else {
$mes_comp_id = 0 ;
$mes_comp_vl = 0 ;
}
if ( isset ( $mat_fav_f )){
$us_fav = array_values ( $mat_fav_f )[ 0 ][ 'nom' ];
$nu_fav = array_values ( $mat_fav_f )[ 0 ][ 'nombre' ];
} else {
$us_fav = 0 ;
$nu_fav = 0 ;
}
if ( isset ( $mat_fav_fs )) {
$mes_fav_id = array_values ( $mat_fav_fs )[ 0 ][ 'article' ];
$mes_fav_vl = array_values ( $mat_fav_fs )[ 0 ][ 'nombre' ];
} else {
$mes_fav_id = 0 ;
$mes_fav_vl = 0 ;
}
if ( isset ( $mat_fav_fsb )) {
$mes_fav_id = array_values ( $mat_fav_fsb )[ 0 ][ 'article' ];
$mes_fav_vl = array_values ( $mat_fav_fsb )[ 0 ][ 'nombre' ];
} else {
$mes_fav_id = 0 ;
$mes_fav_vl = 0 ;
}
if ( isset ( $tuts_fav_primers )) {
} else {
$tuts_fav_primers = 0 ;
}
if ( isset ( $usu_fav_primers )) {
} else {
$usu_fav_primers = 0 ;
}
// llegeix el nombre de seguidors
$nseg_lle = fopen ( $lloc . " /fitxers/seg_cont.txt " , " r " ) or die ( " No puc obrir el nombre seguidors! " );
$nseg_ant = fread ( $nseg_lle , filesize ( $lloc . " /fitxers/seg_cont.txt " ));
fclose ( $nseg_lle );
echo " \n " ;
2024-08-21 20:50:34 +02:00
echo " \ e[1mRESUM ESTADÍSTIQUES \ e[0m \n " .
2023-05-24 10:42:52 +02:00
" Tuts favorits \t \t -> " . $d . " " . (( $d <> 1 ) ? " tuts " : " tut " ) . " \n " .
" Han fet favorits \t \t -> " . $c . " " . (( $c <> 1 ) ? " persones " : " persona " ) . " \n " .
" El tut més favorit ( " . $tuts_fav_primers . " ) \t \t -> " . $mes_fav_id . " : " . $mes_fav_vl . " " . (( $mes_fav_vl <> 1 ) ? " voltes " : " volta " ) . " \n " .
" Usuari més favorits ( " . $usu_fav_primers . " ) \t \t -> " . $us_fav . " : " . $nu_fav . " " . (( $nu_fav <> 1 ) ? " favorits " : " favorit " ) . " \n " .
" Ha participat un " . round ( (( $c / $nseg_ant ) * 100 ), 2 ) . " % sobre el total dels seguidors. \n " .
" Tuts impulsats \t \t -> " . $b . " " . (( $b <> 1 ) ? " tuts " : " tut " ) . " \n " .
" Han impulsat \t \t -> " . $a . " " . (( $a <> 1 ) ? " persones " : " persona " ) . " \n " .
" Tut més impulsat ( " . $tuts_imp_primers . " ) \t \t -> " . $mes_comp_id . " : " . $mes_comp_vl . " " . (( $mes_comp_vl <> 1 ) ? " voltes " : " volta " ) . " \n " .
" Usuari més ha impulsat ( " . $usu_imp_primers . " ) \t -> " . $us_imp . " : " . $nu_imp . " " . (( $nu_imp <> 1 ) ? " impulsos " : " impuls " ) . " \n " .
" Ha participat un " . round ( (( $a / $nseg_ant ) * 100 ), 2 ) . " % sobre el total dels seguidors. \n " ;
//(($nu_imp<>1)?"publicacions":"publicació")
} else {
2024-08-21 20:50:34 +02:00
echo " \ e[1;37;40mEncara no hi ha dades \ e[0m " ;
2023-05-24 10:42:52 +02:00
}
2024-08-21 20:50:34 +02:00
echo " \n " ;
$impuls_inst = shell_exec ( " php -f proves/proves_estadistiques_inst_impulsos_nopub.php " . $lloc . " 01010 0 " );
echo $impuls_inst . " \n " ;
2023-05-24 10:42:52 +02:00
$temps_imp = strtotime ( " now " );
$espera_ob = fopen ( $lloc . " /fitxers/impulsos_temps.txt " , " r " ) or die ( " No puc obrir la darrera data! " );
$espera_ll = fread ( $espera_ob , filesize ( $lloc . " /fitxers/impulsos_temps.txt " ));
$espera_imp = $espera_ll ;
fclose ( $espera_ob );
echo " \n Propera publicació \n " ;
2024-08-21 20:50:34 +02:00
setlocale ( LC_ALL , 'ca_ES.UTF-8' );
//echo setlocale(LC_ALL, 'ca_ES');
//echo(strftime("%B %d %Y, %X %Z",$espera_imp)."<br>");
//echo "strfotime\n";
echo " La propera publicació la faré el " . ( strftime ( " %A %d/%m/%Y a les %H:%M:%S " , $espera_imp )) . " \n " ;
//echo "".$espera_imp." | ".date("r",($espera_imp))."\n";
2023-05-24 10:42:52 +02:00
//echo "Manquen ".date("d",($espera_imp - $temps_imp))." dies i ".date("H:i:s",($espera_imp - $temps_imp))." hores.\n";
2024-08-21 20:50:34 +02:00
//$temps_cal = ($espera_imp - $temps_imp)-(86400);
2023-05-24 10:42:52 +02:00
$temps_cal = ( $espera_imp - $temps_imp );
echo " " . ( gmdate ( " d " , $temps_cal ) <> 1 ? " Manquen " . gmdate ( 'd' , $temps_cal ) . " dies i " . gmdate ( 'H:i:s' , $temps_cal ) . " hores. " : " No manca cap dia i " . gmdate ( 'H:i:s' , $temps_cal ) . " hores. \n " );
$tcf = microtime ( true );
$dc = $tcf - $tc ;
echo " \n Temps impulsos: " . round ( $dc , 4 ) . " \n " ;
//$log->lwrite("Temps impulsos: ".round($dc,4)."");
?>