Código PHP:
<?php
date_default_timezone_set('America/Mexico_City');
set_time_limit(0);
include("conexion.php");
$sql="SET SESSION wait_timeout = 28800";
mysql_query($sql,$conexion);
$sql="SET session max_allowed_packet = 134217728";
mysql_query($sql,$conexion);
$mhoy=date('n');
$can_dias=1;
$fecha_maniana=date('Y-m-d', strtotime("$dia_maniana + $can_dias days"));
$fecha_maniana2=strtotime($fecha_maniana);
$mmaniana=date("n", $fecha_maniana2);
//if($mhoy!=$mmaniana)
//{
/*Hacer una limpieza de las tablas*/
$sql="delete from resultados";
if(mysql_query($sql,$conexion))
{
echo"ok $sql";
}
else
{
echo mysql_error();
}
echo"<br/>";
//unset($sql);
$sql="insert into resultados (id_cuenta,Fans,PRRD) select a.acc_num, count(screen_name_id), sum(d.count_account) from acc_profile a left join (select * from analitico_replies1 union select * from analitico_replies2 union select * from analitico_replies3 union select * from analitico_replies4) d on d.id_cuenta=a.acc_num group by a.acc_user";
//mysql_query('commit');
if(mysql_query($sql,$conexion))
{
echo"exito en el primero";
}
else
{
echo mysql_error();
}
echo"$sql <br/>";
//unset($sql);
include("limpiar.php");
/*Coeficiente de conversación */
//Cantidad de replies calculado
$sql="update resultados set repliesdados=(select count(*) from analitico_twitts b where b.id_cuenta=resultados.id_cuenta and b.to_screen_name<>'')";
if(mysql_query($sql,$conexion))
{
echo "bien $sql";
}
else
{
echo "mal";
}
//unset($sql);
//Cantidad de twitts calculado
$sql="update resultados set twitts=(select count(*) from analitico_twitts e where e.id_cuenta=resultados.id_cuenta)";
if(mysql_query($sql,$conexion))
{
echo "bien2 $sql";
}
else
{
echo "mal2";
}
//unset($sql);
/*Fan1----------------------------------->*/
$sql="update resultados set Fan1=(select b.screen_name_id from (select * from analitico_replies1 union select * from analitico_replies2 union select * from analitico_replies3 union select * from analitico_replies4) b where b.id_cuenta=resultados.id_cuenta order by b.count_account desc limit 0,1)";
if(mysql_query($sql,$conexion))
{
echo "bien3 $sql";
}
else
{
echo "mal3";
}
//unset($sql);
/*Fan2----------------------------------->*/
$sql="update resultados set Fan2=(select b.screen_name_id from (select * from analitico_replies1 union select * from analitico_replies2 union select * from analitico_replies3 union select * from analitico_replies4) b where b.id_cuenta=resultados.id_cuenta order by b.count_account desc limit 1,1)";
if(mysql_query($sql,$conexion))
{
echo "bien4 $sql";
}
else
{
echo "mal4";
}
//unset($sql);
/*Fan3----------------------------------->*/
$sql="update resultados set Fan3=(select b.screen_name_id from (select * from analitico_replies1 union select * from analitico_replies2 union select * from analitico_replies3 union select * from analitico_replies4) b where b.id_cuenta=resultados.id_cuenta order by b.count_account desc limit 2,1)";
if(mysql_query($sql,$conexion))
{
echo "bien5 $sql";
}
else
{
echo "mal5";
}
//unset($sql);
/* Las 3 cuentas con las que mas conversa */
$sql="update resultados set to1=(select temp1.to_screen_name from (select a.id_cuenta, a.to_screen_name, count(a.id_cuenta) as NO from analitico_twitts a where a.to_screen_name is not null group by a.to_screen_name) temp1 where temp1.id_cuenta=resultados.id_cuenta order by NO desc limit 0,1)";
if(mysql_query($sql,$conexion))
{
echo "bien6 $sql";
}
else
{
echo "mal6";
}
//unset($sql);
$sql="update resultados set to2=(select temp1.to_screen_name from (select a.id_cuenta, a.to_screen_name, count(a.id_cuenta) as NO from analitico_twitts a where a.to_screen_name is not null group by a.to_screen_name) temp1 where temp1.id_cuenta=resultados.id_cuenta order by NO desc limit 1,1)";
if(mysql_query($sql,$conexion))
{
echo "bien7 $sql";
}
else
{
echo "mal7";
}
//unset($sql);
$sql="update resultados set to3=(select temp1.to_screen_name from (select a.id_cuenta, a.to_screen_name, count(a.id_cuenta) as NO from analitico_twitts a where a.to_screen_name is not null group by a.to_screen_name) temp1 where temp1.id_cuenta=resultados.id_cuenta order by NO desc limit 2,1)";
if(mysql_query($sql,$conexion))
{
echo "bien8 $sql";
}
else
{
echo "mal8";
}
//unset($sql);
/*Copiar los resultados */
$sql="insert into acc_data (acc_num,acc_fans,acc_twitts,acc_cc,acc_rrd,acc_by1,acc_by2,acc_by3,acc_to1,acc_to2,acc_to3,acc_date,acc_status,acc_time) select id_cuenta, fans, twitts, ROUND(repliesdados*100/twitts,1), ROUND(PRRD/30,1), fan1, fan2, fan3, to1, to2, to3, curdate(), case b.visible when 'si' then 1 else 0 end, twitts*30 from resultados a inner join acc_profile b on a.id_cuenta=b.acc_num";
if(mysql_query($sql,$conexion))
{
echo "bien9 $sql";
}
else
{
echo "mal9";
}
//unset($sql);
/*Preparar rankings*/
//$sql="insert into ranking (rank_coun,rank_cat,rank_date,rank_order,rank_factor,rank_status) select cat_country, cat_id, date_format(curdate(),'%X-%m-%d'), 'DESC', 'fans', 'no' from cat";
if(mysql_query($sql,$conexion))
{
echo "bien10 $sql";
}
else
{
echo "mal10";
}
//unset($sql);
//}
//else
//{
//echo"<h2>No es ultimo dia</h2>";
//}
mysql_close($conexion);
?>
Código PHP:
<?php
set_time_limit(0);
//include("conexion.php");
/*Inicializar tabla analitico_top40*/
$sql="delete from analitico_top40;";
if(mysql_query($sql))
{
echo"ok";
}
else
{
echo"fail";
}
echo"<br/>";
//unset($sql);
$sql=mysql_query("SELECT cat_id FROM cat");
$I=0;
while($fila=mysql_fetch_array($sql))
{
echo "categoria ".$fila['cat_id']."";
/*Extraer el top40 de cada categoria*/
$sql2="insert into analitico_top40 (id_cuenta) select a.id_cuenta from resultados a inner join acc_profile b on a.id_cuenta=b.acc_num inner join cat c on b.acc_cat like concat('%[',c.cat_id,']%') where c.cat_id=".$fila['cat_id']." order by a.fans desc limit 40";
if(mysql_query($sql2))
{
echo "bien$I";
}
else
{
echo "".mysql_error()."$I";
}
$I++;
echo"<br/>";
}
//unset($sql,$sql2);
/*Borrar resultados que no sirven*/
$sql="delete from resultados where id_cuenta not in (select a.id_cuenta from analitico_top40 a)";
if(mysql_query($sql))
{
echo"ok2";
}
else
{
echo"fail2";
}
echo"<br/>";
//unset($sql);
/*Borrar analitico_replies1 que no sirven*/
$sql="delete from analitico_replies1 where id_cuenta not in (select a.id_cuenta from analitico_top40 a)";
if(mysql_query($sql))
{
echo"ok3";
}
else
{
echo"fail3";
}
echo"<br/>";
//unset($sql);
/*Borrar analitico_replies2 que no sirven*/
$sql="delete from analitico_replies2 where id_cuenta not in (select a.id_cuenta from analitico_top40 a)";
if(mysql_query($sql))
{
echo"ok4";
}
else
{
echo"fail4";
}
echo"<br/>";
//unset($sql);
/*Borrar analitico_replies3 que no sirven*/
$sql="delete from analitico_replies3 where id_cuenta not in (select a.id_cuenta from analitico_top40 a)";
if(mysql_query($sql))
{
echo"ok5";
}
else
{
echo"fail5";
}
echo"<br/>";
//unset($sql);
/*Borrar analitico_replies4 que no sirven*/
$sql="delete from analitico_replies4 where id_cuenta not in (select a.id_cuenta from analitico_top40 a)";
if(mysql_query($sql))
{
echo"ok6";
}
else
{
echo"fail6";
}
echo"<br/>";
//unset($sql);
/*Borrar analitico_twitts que no sirven*/
$sql="delete from analitico_twitts where id_cuenta not in (select a.id_cuenta from analitico_top40 a)";
if(mysql_query($sql))
{
echo"ok7";
}
else
{
echo"fail7";
}
echo"<br/>";
//unset($sql);
//mysql_close($conexion);