NxTIC/automate.php

129 lines
3.1 KiB
PHP
Raw Normal View History

<?php define('__ROOT__', dirname(__FILE__) );
require_once __ROOT__.'/manager/autoloader.php';
use \manager\ModuleRequest;
use \manager\ResourceDispatcher;
use \manager\ManagerError;
use \manager\Repo;
debug();
2016-04-04 12:04:36 +00:00
/* PARSAGE DE JOURNAUX D'APPEL
*
*
*/
2016-04-04 12:04:36 +00:00
function parseCallLog(){
2016-04-04 12:04:36 +00:00
/* [1] On recupere le journal d'appel
=========================================================*/
$filename = 'calllog.xml';
$file = simplexml_load_file( $filename );
2016-04-04 12:04:36 +00:00
/* [2] On parcours chaque ligne
=========================================================*/
$names = array(); // Contiendra les correspondances num/names
$msms = array(); // Contiendra les personnes utilisant SMS/MMS
$call = array(); // Contiendra les personnes utilisant CALL
2016-04-04 12:04:36 +00:00
/* [3] On parcours chaque ligne
=========================================================*/
foreach($file->Item as $log){
// On recupere le numero en string
$num = (string) $log['Number'];
2016-04-04 12:04:36 +00:00
// On formatte le numero
if( preg_match("/^(?:\+33|33|0)(.+)/", $num, $m) )
$num = '0'.$m[1];
2016-04-04 12:29:53 +00:00
// Si pas un numero, on sort de la boucle
else
continue;
2016-04-04 12:04:36 +00:00
/* (1) Si le type est MMS ou SMS */
if( $log['Type'] == 'SMS' || $log['Type'] == 'MMS' ){
2016-04-04 12:04:36 +00:00
// Si la personne n'est pas referencee, on l'ajoute
// Sinon on incremente son nombre d'apparition
if( isset($msms[$num]) )
$msms[$num]+= 1;
else
$msms[$num] = 1;
// On enregistre le nom si c'est pas fait
if( !isset($names[$num]) ) $names[$num] = $log['Name'];
2016-04-04 12:04:36 +00:00
/* (2) Si le type est PHONE */
}else if( $log['Type'] == 'PHONE' ){
2016-04-04 12:04:36 +00:00
// Si la personne n'est pas referencee, on l'ajoute
// Sinon on incremente son nombre d'apparition
if( isset($call[$num]) )
$call[$num]+= 1;
else
$call[$num] = 1;
// On enregistre le nom si c'est pas fait
if( !isset($names[$num]) ) $names[$num] = $log['Name'];
2016-04-04 12:04:36 +00:00
}
2016-04-04 12:04:36 +00:00
// var_dump( $log );
}
2016-04-04 12:04:36 +00:00
/* [4] On trie par nombre de contacts
=========================================================*/
2016-04-04 12:29:53 +00:00
$tmp = $msms;
/* (2) Tri des appels */
$maxMSMS = array();
for( $i = 0 ; $i < 10 ; $i++ ){
$maxval = max($tmp);
$maxkey = array_search($maxval, $tmp);
array_push( $maxMSMS, array($maxkey, $maxval) );
unset($tmp[$maxkey]);
}
2016-04-04 12:56:38 +00:00
2016-04-04 12:29:53 +00:00
$tmp = $call;
/* (2) Tri des appels */
$maxCalls = array();
for( $i = 0 ; $i < 10 ; $i++ ){
$maxval = max($tmp);
$maxkey = array_search($maxval, $tmp);
array_push( $maxCalls, array($maxkey, $maxval) );
unset($tmp[$maxkey]);
}
2016-04-04 12:04:36 +00:00
/* [5] On debug les donnees recues
=========================================================*/
echo "Il y a ".count($names)." personnes :<br>";
echo "- ".count($msms)." par SMS/MMS<br>";
echo "- ".count($call)." par telephone<br><br>";
echo "TOP 10 DES APPELS<br>";
echo "=================<br>";
2016-04-04 12:29:53 +00:00
foreach($maxCalls as $v)
var_dump( $v[0] ." (".$names[$v[0]].") \t\t\t". $v[1] ." appels");
echo "TOP 10 DES MMS/SMS<br>";
echo "==================<br>";
foreach($maxMSMS as $v)
var_dump( $v[0] ." (".$names[$v[0]].") \t\t\t". $v[1] ." appels");
2016-04-04 12:04:36 +00:00
// var_dump( $call );
2016-04-04 12:04:36 +00:00
return 0;
}
2016-04-04 12:04:36 +00:00
parseCallLog();
?>