Add options to better use by declencheur
This commit is contained in:
parent
4dbea7f861
commit
92aca6deb4
@ -1,7 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* Calcul des scores sur la base S&D
|
||||
* Le script utilise de nombreuses ressources processeurs (1 thread à 100%) et mémoire jusqu'à 4 Go
|
||||
* Déclencheur
|
||||
* - "bilans1" à 7h
|
||||
* - "ajout" à 8h, 22h
|
||||
* - "insee" à 8h
|
||||
* - "dirigeants" à 9h
|
||||
* - "bodacc" à 13h
|
||||
* - "collecte" à 13h30
|
||||
*
|
||||
* Crontab
|
||||
* 0 12 * * 1-5 /home/scores/batch/scripts/calculScoreSurv.php >> /home/data/sources/log/calculScoreSurv.log
|
||||
@ -36,12 +42,13 @@ $application = new Zend_Application(
|
||||
//Options
|
||||
try {
|
||||
$opts = new Zend_Console_Getopt(array(
|
||||
'help|?' => "Displays usage information.",
|
||||
'tout|t' => "Calculer tous les scores",
|
||||
'verbose|v' => "Mode bavard ou debug",
|
||||
'ancien|a' => "Recalculer tous les scores avec indiscore>0 et un encours à 0 !",
|
||||
'list|l' => "Lister les déclencheurs existants pour le recalcul des scores",
|
||||
'help|?' => "Displays usage information.",
|
||||
'tout|t' => "Calculer tous les scores",
|
||||
'verbose|v' => "Mode bavard ou debug",
|
||||
'ancien|a' => "Recalculer tous les scores avec indiscore>0 et un encours à 0 !",
|
||||
'list|l' => "Lister les déclencheurs existants pour le recalcul des scores",
|
||||
'declencheur|d=s' => "Lancer le calcul des scores pour le déclencheur XXX",
|
||||
'max=s' => "Nombre max d'unités à calculer pour un déclencheur",
|
||||
));
|
||||
$opts->parse();
|
||||
} catch (Zend_Console_Getopt_Exception $e) {
|
||||
@ -59,40 +66,42 @@ if( isset($opts->help) || count($opts->getOptions())==0 )
|
||||
|
||||
$strSelect="s.siren, s.actif, s.procol, s.indiScore, s.indiScore20, s.encours, s.indiScoreDate, scoreSolv, scoreConf, scoreDir, scoreZ, scoreCH, scoreAfdcc1, scoreAfdcc2, scoreAfdcc2note, scoreAltman, scoreAltmanCote, scoreCCF, situFi, infoNote, noteStruct, noteFin, tendance, nbModifs, s.dateUpdate, s.cs, s.csMoisMaj, s.csMoisFin";
|
||||
|
||||
$tableSurvTmp = 'tmp.scores_surveillance';
|
||||
|
||||
$tabQueries = array(
|
||||
/* Bilans Asso déposé(s) */
|
||||
'bilansasso' => "SELECT $strSelect, 'bilansasso' as source FROM jo.scores_surveillance_tmp s, jo.asso_bilans b WHERE b.siren>1000 AND s.siren=b.siren AND b.dateInsert>s.dateUpdate AND s.procol NOT IN('P') GROUP BY siren",
|
||||
'bilansasso' => "SELECT $strSelect, 'bilansasso' as source FROM ".$tableSurvTmp."_bilansasso s, jo.asso_bilans b WHERE b.siren>1000 AND s.siren=b.siren AND b.dateInsert>s.dateUpdate /*AND s.procol NOT IN('P')*/ GROUP BY siren",
|
||||
//asso_bilans', 'dateCloture, dateCloture*1 as dateClotureNum', "siren=$siren ORDER BY DESC LIMIT 0,5", true, MYSQL_ASSOC);
|
||||
/* Privileges Infogreffe */
|
||||
'privileges' => "SELECT $strSelect, 'privileges' AS source FROM jo.scores_surveillance_tmp s, jo.greffes_privileges p WHERE p.siren>1000 AND s.siren = p.siren AND (p.dateInsert>s.dateUpdate OR p.dateUpdate>s.dateUpdate) AND s.procol NOT IN('P') GROUP BY siren",
|
||||
'privileges' => "SELECT $strSelect, 'privileges' AS source FROM ".$tableSurvTmp."_privileges s, jo.greffes_privileges p WHERE p.siren>1000 AND s.siren = p.siren AND (p.dateInsert>s.dateUpdate OR p.dateUpdate>s.dateUpdate) /*AND s.procol NOT IN('P')*/ GROUP BY siren",
|
||||
/* Privileges Facto */
|
||||
'privileges2' => "SELECT $strSelect, 'privileges2' AS source FROM jo.scores_surveillance_tmp s, sdv1.ge_cs2 p WHERE p.siren>1000 AND s.siren = p.siren AND (p.dateInsert>=s.dateUpdate OR p.dateConf>=s.dateUpdate) AND p.cs='P' AND s.procol NOT IN('P') GROUP BY siren",
|
||||
'privileges2' => "SELECT $strSelect, 'privileges2' AS source FROM ".$tableSurvTmp."_privileges2 s, sdv1.ge_cs2 p WHERE p.siren>1000 AND s.siren = p.siren AND (p.dateInsert>=s.dateUpdate OR p.dateConf>=s.dateUpdate) AND p.cs='P' /*AND s.procol NOT IN('P')*/ GROUP BY siren",
|
||||
/* IMPAYES Facto */
|
||||
'impayes' => "SELECT $strSelect, 'impayes' AS source FROM jo.scores_surveillance_tmp s, sdv1.ge_cs2 p WHERE p.siren>1000 AND s.siren = p.siren AND (p.dateInsert>=s.dateUpdate OR p.dateConf>=s.dateUpdate) AND p.cs='I' AND s.procol NOT IN('P') GROUP BY siren",
|
||||
'impayes' => "SELECT $strSelect, 'impayes' AS source FROM ".$tableSurvTmp."_impayes s, sdv1.ge_cs2 p WHERE p.siren>1000 AND s.siren = p.siren AND (p.dateInsert>=s.dateUpdate OR p.dateConf>=s.dateUpdate) AND p.cs='I' /*AND s.procol NOT IN('P')*/ GROUP BY siren",
|
||||
/* Ajout d'un nouveau score */
|
||||
'ajout' => "SELECT $strSelect, 'ajout' AS source FROM jo.scores_surveillance_tmp s WHERE s.siren>1000 AND ((DATEDIFF(NOW(),s.indiScoreDate) IS NULL AND s.dateUpdate<DATE(NOW()) OR s.indiScoreDate=0)) GROUP BY siren",
|
||||
'ajout' => "SELECT $strSelect, 'ajout' AS source FROM ".$tableSurvTmp."_ajout s WHERE s.siren>1000 AND ((DATEDIFF(NOW(),s.indiScoreDate) IS NULL AND s.dateUpdate<DATE(NOW()) OR s.indiScoreDate=0)) GROUP BY siren",
|
||||
/* IndiScores demandés ce jour */
|
||||
//'jour' => "SELECT $strSelect, 'jour' AS source FROM scores_surveillance_tmp s, sdv1.`logs` l WHERE l.siren>1000 AND s.siren=l.siren AND l.page='indiscore' AND l.dateHeure>s.dateUpdate AND s.procol NOT IN('P') GROUP BY siren",
|
||||
//'jour' => "SELECT $strSelect, 'jour' AS source FROM ".$tableSurvTmp."_jour s, sdv1.`logs` l WHERE l.siren>1000 AND s.siren=l.siren AND l.page='indiscore' AND l.dateHeure>s.dateUpdate AND s.procol NOT IN('P') GROUP BY siren",
|
||||
/* Dirigeants */
|
||||
'dirigeants' => "SELECT $strSelect, 'dirigeants' AS source FROM jo.scores_surveillance_tmp s, jo.rncs_dirigeants d WHERE d.siren>1000 AND s.siren = d.siren AND (d.dateInsert>s.dateUpdate OR d.dateUpdate>s.dateUpdate) AND (d.dateInsert>'2013-03-15 00:00:00' OR d.dateUpdate>'2013-03-15 00:00:00') AND s.procol NOT IN('P') GROUP BY siren",
|
||||
'dirigeants' => "SELECT $strSelect, 'dirigeants' AS source FROM ".$tableSurvTmp."_dirigeants s, jo.rncs_dirigeants d WHERE d.siren>1000 AND s.siren = d.siren AND (d.dateInsert>s.dateUpdate OR d.dateUpdate>s.dateUpdate) AND (d.dateInsert>'2013-03-15 00:00:00' OR d.dateUpdate>'2013-03-15 00:00:00') /*AND s.procol NOT IN('P')*/ GROUP BY siren",
|
||||
/* Evenements INSEE */
|
||||
'insee' => "SELECT $strSelect, 'insee' as source FROM jo.scores_surveillance_tmp s, insee.insee_even i WHERE i.insSIREN>1000 AND s.siren=i.insSIREN AND i.dateInsert>s.dateUpdate /*AND s.procol NOT IN('P') AND i.insEVE IN ('400','410','420','425')*/ AND i.insSIEGE=1 GROUP BY siren",
|
||||
'insee' => "SELECT $strSelect, 'insee' as source FROM ".$tableSurvTmp."_insee s, insee.insee_even i WHERE i.insSIREN>1000 AND s.siren=i.insSIREN AND i.dateInsert>s.dateUpdate /*AND s.procol NOT IN('P') AND i.insEVE IN ('400','410','420','425')*/ AND i.insSIEGE=1 GROUP BY siren",
|
||||
/* Entreprises RNCS */
|
||||
//'rncs' => "SELECT $strSelect, 'rncs' as source FROM scores_surveillance_tmp s, rncs_entrep r WHERE s.siren>1000 AND s.siren=r.siren AND (r.dateInsert>s.dateUpdate OR r.dateUpdate>s.dateUpdate) /*AND (d.dateInsert>'2013-03-15 00:00:00' OR d.dateUpdate>'2013-03-15 00:00:00')*/ AND s.procol NOT IN('P') GROUP BY siren",
|
||||
/* Bodacc */
|
||||
'bodacc' => "SELECT $strSelect, 'bodacc' as source FROM jo.scores_surveillance_tmp s, jo.bodacc_detail b WHERE b.siren>1000 AND s.siren=b.siren AND( b.dateInsert>s.dateUpdate OR b.dateUpdate>s.dateUpdate) /*AND s.procol NOT IN('P')*/ AND b.Rubrique NOT IN('creations','comptes') GROUP BY siren",
|
||||
'bodacc' => "SELECT $strSelect, 'bodacc' as source FROM ".$tableSurvTmp."_bodacc s, jo.bodacc_detail b WHERE b.siren>1000 AND s.siren=b.siren AND( b.dateInsert>s.dateUpdate OR b.dateUpdate>s.dateUpdate) /*AND s.procol NOT IN('P')*/ AND b.Rubrique NOT IN('creations','comptes') GROUP BY siren",
|
||||
/* Collecte */
|
||||
'collecte' => "SELECT $strSelect, 'collecte' as source FROM jo.scores_surveillance_tmp s, jo.annonces b WHERE b.siren>1000 AND s.siren=b.siren AND b.dateInsert>s.dateUpdate /*AND s.procol NOT IN('P') AND b.typeEven NOT IN(3200)*/ GROUP BY siren",
|
||||
'collecte' => "SELECT $strSelect, 'collecte' as source FROM ".$tableSurvTmp."_collecte s, jo.annonces b WHERE b.siren>1000 AND s.siren=b.siren AND b.dateInsert>s.dateUpdate /*AND s.procol NOT IN('P') AND b.typeEven NOT IN(3200)*/ GROUP BY siren",
|
||||
/* Bilans en base */
|
||||
'bilans1' => "SELECT $strSelect, 'bilans1' as source FROM jo.scores_surveillance_tmp s, jo.bilans b WHERE b.siren>1000 AND s.siren=b.siren AND b.dateInsert>s.dateUpdate AND (DATEDIFF(b.dateExercice,s.dateBilan)>1 OR DATEDIFF(b.dateExercice,s.dateBilan) IS NULL) AND s.procol NOT IN('P') GROUP BY siren",
|
||||
'bilans1' => "SELECT $strSelect, 'bilans1' as source FROM ".$tableSurvTmp."_bilans1 s, jo.bilans b WHERE b.siren>1000 AND s.siren=b.siren AND b.dateInsert>s.dateUpdate AND (DATEDIFF(b.dateExercice,s.dateBilan)>1 OR DATEDIFF(b.dateExercice,s.dateBilan) IS NULL) /*AND s.procol NOT IN('P')*/ GROUP BY siren",
|
||||
/* Défaut divers Facto (D:Défaut, 24:Groupe en diff, 31:Cessation Annoncée, 50:Terrorisme)*/
|
||||
'defaut' => "SELECT $strSelect, 'defaut' AS source FROM jo.scores_surveillance_tmp s, sdv1.ge_cs2 p WHERE p.siren>1000 AND s.siren = p.siren AND (p.dateInsert>=s.dateUpdate OR p.dateConf>=s.dateUpdate) AND p.cs IN ('D','24','31','50') AND s.procol NOT IN('P') GROUP BY siren",
|
||||
'defaut' => "SELECT $strSelect, 'defaut' AS source FROM ".$tableSurvTmp."_defaut s, sdv1.ge_cs2 p WHERE p.siren>1000 AND s.siren = p.siren AND (p.dateInsert>=s.dateUpdate OR p.dateConf>=s.dateUpdate) AND p.cs IN ('D','24','31','50') /*AND s.procol NOT IN('P')*/ GROUP BY siren",
|
||||
/* RAS Facto */
|
||||
'regulier' => "SELECT $strSelect, 'regulier' AS source FROM jo.scores_surveillance_tmp s, sdv1.ge_cs2 p WHERE p.siren>1000 AND s.siren = p.siren AND (p.dateInsert>=s.dateUpdate OR p.dateConf>=s.dateUpdate) AND p.cs='00' AND s.procol NOT IN('P') GROUP BY siren",
|
||||
'regulier' => "SELECT $strSelect, 'regulier' AS source FROM ".$tableSurvTmp."_regulier s, sdv1.ge_cs2 p WHERE p.siren>1000 AND s.siren = p.siren AND (p.dateInsert>=s.dateUpdate OR p.dateConf>=s.dateUpdate) AND p.cs='00' AND s.procol NOT IN('P') GROUP BY siren ORDER BY siren ASC",
|
||||
// Rajouter AND (DATEDIFF(NOW(),s.indiScoreDate)>365
|
||||
// et vérifier si ça en enlève en recalcul régulier
|
||||
/* Scores trop anciens */
|
||||
'ancien' => "SELECT $strSelect, 'ancien' AS source FROM jo.scores_surveillance_tmp s WHERE s.siren>1000 AND (DATEDIFF(NOW(),s.indiScoreDate)>365 /*OR DATEDIFF(NOW(),s.indiScoreDate) IS NULL*/) AND s.procol NOT IN('P') AND s.dateUpdate<DATE(NOW()) GROUP BY siren",
|
||||
'ancien' => "SELECT $strSelect, 'ancien' AS source FROM ".$tableSurvTmp."_ancien s WHERE s.siren>1000 AND (DATEDIFF(NOW(),s.indiScoreDate)>365 /*OR DATEDIFF(NOW(),s.indiScoreDate) IS NULL*/) AND s.procol NOT IN('P') AND s.dateUpdate<DATE(NOW()) GROUP BY siren ORDER BY siren DESC",
|
||||
/** @todo A revoir **/
|
||||
/* Bilans déposés */
|
||||
//'bilans2'=>"SELECT s.siren, s.actif, s.procol, s.indiScore, s.indiScore20, s.encours, s.indiScoreDate, scoreSolv, scoreConf, scoreDir, scoreZ, scoreCH, scoreAfdcc1, scoreAfdcc2, scoreAfdcc2note, scoreAltman, scoreAltmanCote, scoreCCF, situFi, infoNote, noteStruct, noteFin, tendance, nbModifs, 'bilans2' as source, s.dateUpdate FROM scores_surveillance_tmp s, bilans_deposes b WHERE b.siren>1000 AND s.siren=b.siren AND b.dateInsert>s.dateUpdate AND s.procol NOT IN('P') GROUP BY siren",
|
||||
@ -120,7 +129,6 @@ if ($opts->declencheur) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
$c = new Zend_Config($application->getOptions());
|
||||
$db = Zend_Db::factory($c->profil->db->metier);
|
||||
Zend_Db_Table_Abstract::setDefaultAdapter($db);
|
||||
@ -150,6 +158,7 @@ $dateJour=date('Y-m-d');
|
||||
|
||||
function wsLog($service, $siret='', $ref='') {}
|
||||
|
||||
$message = '';
|
||||
echo date('Y/m/d - H:i:s') ." - DEBUT du programme de calcul des scores en surveillance...".PHP_EOL;
|
||||
|
||||
/**
|
||||
@ -176,22 +185,20 @@ $nbScoresSans=$nbScoresModif=$nbScoresNouv=$nbScoresProcol=$iRow=$nbRowsTot=0;
|
||||
$iInsee=new MInsee();
|
||||
foreach ($tabQueries as $declencheur=>$query)
|
||||
{
|
||||
$tableName = $tableSurvTmp . '_' . $declencheur;
|
||||
echo date('Y/m/d - H:i:s') ." - Copie de la table ".$tableName.PHP_EOL;
|
||||
|
||||
echo date('Y/m/d - H:i:s') ." - Copie de la table scores_surveillance";
|
||||
try {
|
||||
$res = $db->query("DROP TABLE IF EXISTS jo.scores_surveillance_tmp;");
|
||||
$res = $db->query("CREATE TABLE $tableName LIKE jo.scores_surveillance;");
|
||||
} catch(Zend_Db_Adapter_Exception $e) {
|
||||
echo $e->getMessage() . PHP_EOL;
|
||||
//If the table exist an other scripts is running
|
||||
$message.= "Lancement du calcul des scores ignoré $declencheur, vérifier qu'il y a bien eu un calcul récement!".PHP_EOL;
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$res = $db->query("CREATE TABLE jo.scores_surveillance_tmp LIKE jo.scores_surveillance;");
|
||||
} catch(Zend_Db_Adapter_Exception $e) {
|
||||
echo $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
$res = $db->query("INSERT IGNORE INTO jo.scores_surveillance_tmp SELECT * FROM jo.scores_surveillance;");
|
||||
$res = $db->query("INSERT IGNORE INTO $tableName SELECT * FROM jo.scores_surveillance;");
|
||||
} catch(Zend_Db_Adapter_Exception $e) {
|
||||
echo $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
@ -225,11 +232,7 @@ foreach ($tabQueries as $declencheur=>$query)
|
||||
$sourceModif = $entrep['source'];
|
||||
$procol = $entrep['procol'];
|
||||
$nbModifs = ($entrep['nbModifs']*1)+1;
|
||||
/*if ($procol=='P') {
|
||||
$nbScoresProcol++;
|
||||
if ($opts->verbose) echo date('Y/m/d - H:i:s') ." - Ligne $iRow/$nbRowsTot - Siren $siren : $indiScorePre / 100 ($encoursPre EUR) inchangé depuis $dateScore (Source=$sourceModif) car ProCol.".PHP_EOL;
|
||||
continue;
|
||||
}*/
|
||||
|
||||
//echo date('Y/m/d - H:i:s') ." - Siren $siren : AVANT SCORE".PHP_EOL;
|
||||
$tabScore = calculIndiScore($siren, $nic, false, 0, false, 'scores', $declencheur);
|
||||
//echo date('Y/m/d - H:i:s') ." - Siren $siren : APRES SCORE".PHP_EOL;
|
||||
@ -244,34 +247,55 @@ foreach ($tabQueries as $declencheur=>$query)
|
||||
} else {
|
||||
if ($dateScore==0) {
|
||||
$nbScoresNouv++;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$nbScoresModif++;
|
||||
$tabNbScoresModif[$declencheur]++;
|
||||
}
|
||||
echo date('Y/m/d - H:i:s') ." - Ligne $iRow/$nbRowsTot - Siren $siren : $indiScore<>$indiScorePre OU $encours<>$encoursPre (Source=$sourceModif) !".PHP_EOL;
|
||||
}
|
||||
if (date('Hi')*1>=430 && date('Hi')*1<=700 && !$opts->verbose) break 2;
|
||||
|
||||
//Arrêt de l'execution à 4h30 ou 7h00
|
||||
if ( date('Hi')*1>=430 && date('Hi')*1<=700 && !$opts->verbose ) break;
|
||||
|
||||
// Arret sur indicateur maximum
|
||||
if ( $opts->max && $iRow >= $opts->max) break;
|
||||
}
|
||||
}
|
||||
|
||||
//Delete the remporary table
|
||||
try {
|
||||
$res = $db->query("DROP TABLE IF EXISTS $tableName;");
|
||||
} catch(Zend_Db_Adapter_Exception $e) {
|
||||
echo $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rapport
|
||||
*/
|
||||
$message =date ('Y/m/d - H:i:s') . " - Nombre de scores inchangés .................. $nbScoresSans / $nbRowsTot.".PHP_EOL;
|
||||
$message.=date ('Y/m/d - H:i:s') . " - Nombre de scores inchangés car procol ....... $nbScoresProcol / $nbRowsTot.".PHP_EOL;
|
||||
$message.=date ('Y/m/d - H:i:s') . " - Nombre de scores ajoutés .................... $nbScoresNouv / $nbRowsTot.".PHP_EOL;
|
||||
$message.=date ('Y/m/d - H:i:s') . " - Nombre de scores modifiées .................. $nbScoresModif / $nbRowsTot.".PHP_EOL;
|
||||
$message.=PHP_EOL;
|
||||
$message.= date ('Y/m/d - H:i:s') . " - Nombre de scores inchangés .................. $nbScoresSans / $nbRowsTot.".PHP_EOL;
|
||||
$message.= date ('Y/m/d - H:i:s') . " - Nombre de scores inchangés car procol ....... $nbScoresProcol / $nbRowsTot.".PHP_EOL;
|
||||
$message.= date ('Y/m/d - H:i:s') . " - Nombre de scores ajoutés .................... $nbScoresNouv / $nbRowsTot.".PHP_EOL;
|
||||
$message.= date ('Y/m/d - H:i:s') . " - Nombre de scores modifiées .................. $nbScoresModif / $nbRowsTot.".PHP_EOL;
|
||||
$message.= PHP_EOL;
|
||||
$nbCalc = $nbScoresSans + $nbScoresProcol + $nbScoresNouv + $nbScoresModif;
|
||||
foreach($tabNbRows as $declencheur=>$nbTot) {
|
||||
$nbModifs=$tabNbScoresModif[$declencheur]*1;
|
||||
$message.=date ('Y/m/d - H:i:s') . " - Nombre de modifs par '$declencheur'\t...... $nbModifs / $nbTot.".PHP_EOL;
|
||||
$nbModifs = $tabNbScoresModif[$declencheur]*1;
|
||||
$message.= date ('Y/m/d - H:i:s') . " - Nombre de modifs par '$declencheur'\t...... $nbModifs / $nbTot.".PHP_EOL;
|
||||
}
|
||||
echo $message;
|
||||
|
||||
$duree=round(microtime(true)-$tDeb);
|
||||
sendMail('supportdev@scores-decisions.com', 'suivi@scores-decisions.com', "[CHARGEMENT] Calculs des IndiScores ($nbCalc/$nbRowsTot en $duree s)", $message);
|
||||
|
||||
$subject = "[CHARGEMENT] Calculs des IndiScores ($nbCalc/$nbRowsTot en $duree s)";
|
||||
|
||||
$mail = new Zend_Mail('UTF-8');
|
||||
$tr = new Zend_Mail_Transport_Sendmail();
|
||||
$mail->setDefaultTransport($tr);
|
||||
$mail->setBodyText($message);
|
||||
$mail->setFrom('supportdev@scores-decisions.com', 'Machine');
|
||||
$mail->addTo('suivi@scores-decisions.com', 'Suivi');
|
||||
$mail->setSubject($subject);
|
||||
$mail->send();
|
||||
|
||||
echo date('Y/m/d - H:i:s') ." - Fin du traitement.".PHP_EOL;
|
Loading…
x
Reference in New Issue
Block a user