Test calculScore
This commit is contained in:
parent
cd7c27e187
commit
898098ef5d
149
scripts/calculScoreDate.php
Normal file
149
scripts/calculScoreDate.php
Normal file
@ -0,0 +1,149 @@
|
||||
<?php
|
||||
error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
|
||||
$dateStartIn = '2014-01-01';
|
||||
$dateStopIn = '2015-10-01';
|
||||
|
||||
/*$companies = array(
|
||||
'552144503',
|
||||
'341762573',
|
||||
);*/
|
||||
|
||||
$companies = array();
|
||||
$row = 1;
|
||||
if (($handle = fopen("liste-01.csv", "r")) !== false) {
|
||||
while (($data = fgetcsv($handle, 0, ",")) !== false) {
|
||||
if ($row == 1) {
|
||||
continue;
|
||||
}
|
||||
$row++;
|
||||
$companies[] = $data[0];
|
||||
}
|
||||
fclose($handle);
|
||||
}
|
||||
|
||||
// --- Define path to application directory
|
||||
defined('APPLICATION_PATH')
|
||||
|| define('APPLICATION_PATH', realpath(__DIR__ . '/../application'));
|
||||
|
||||
// --- Define application environment
|
||||
defined('APPLICATION_ENV')
|
||||
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
||||
|
||||
// --- Composer autoload
|
||||
require_once realpath(__DIR__ . '/../vendor/autoload.php');
|
||||
|
||||
// --- Create application, bootstrap, and run
|
||||
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
|
||||
|
||||
$c = new Zend_Config($application->getOptions());
|
||||
$db = Zend_Db::factory($c->profil->db->metier);
|
||||
Zend_Db_Table::setDefaultAdapter($db);
|
||||
|
||||
require_once APPLICATION_PATH.'/configs/config.php';
|
||||
require_once 'framework/fwk.php';
|
||||
require_once 'framework/common/chiffres.php';
|
||||
require_once 'framework/common/dates.php';
|
||||
require_once 'framework/mail/sendMail.php';
|
||||
require_once 'Metier/partenaires/classMLiens2.php';
|
||||
require_once 'Metier/partenaires/classMBanques.php';
|
||||
require_once 'Metier/insee/classMInsee.php';
|
||||
|
||||
|
||||
$fp = fopen('retour-'.date('YmdHis').'.csv', 'w');
|
||||
$delimiter = ',';
|
||||
$fileHeader = array(
|
||||
'siren',
|
||||
'dateCalc',
|
||||
'SituationJuridique',
|
||||
'Indiscore',
|
||||
'Indiscore20',
|
||||
'ScoreSolvabilite',
|
||||
'ScoreDirigeance',
|
||||
'ScoreConfor',
|
||||
'encours',
|
||||
);
|
||||
fputcsv($fp, $fileHeader, $delimiter, '"');
|
||||
|
||||
foreach ($companies as $item)
|
||||
{
|
||||
// --- Date de création de l'entreprise
|
||||
$dateCreaEnSet = null;
|
||||
$dateReal = new Zend_Date();
|
||||
// DCREN => insee.identite
|
||||
$sql = $db->select()->from('identite', array('DCREN'), 'insee')
|
||||
->where('siren=?', $item)->order('SIEGE DESC')->order('ACTIF DESC')->limit(1);
|
||||
$result = $db->fetchRow($sql, null, Zend_Db::FETCH_OBJ);
|
||||
if ($result !== null) {
|
||||
if ($dateReal->isDate($result->DCREN, 'yyyyMMdd')) {
|
||||
$dateReal->set($result->DCREN, 'yyyyMMdd') ;
|
||||
$dateCreaEnSet = 1;
|
||||
}
|
||||
}
|
||||
|
||||
// DateImma
|
||||
if ($dateCreaEn === null) {
|
||||
$sql = $db->select()->from('rncs_entrep', array('dateImma'), 'jo')
|
||||
->where('siren=?', $item)->limit(1);
|
||||
$result = $db->fetchRow($sql, null, Zend_Db::FETCH_OBJ);
|
||||
if ($result !== null) {
|
||||
if ($dateReal->isDate($result->dateImma, 'yyyy-MM-dd')) {
|
||||
$dateReal->set($result->dateImma, 'yyyyMMdd') ;
|
||||
$dateCreaEnSet = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($dateCreaEnSet === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// --- Date
|
||||
$dateStop = new Zend_Date($dateStopIn, 'yyyy-MM-dd');
|
||||
$dateStart = new Zend_Date($dateStartIn, 'yyyy-MM-dd');
|
||||
|
||||
echo $item.' - '.$dateStart->toString('yyyy-MM-dd').' '.$dateStop->toString('yyyy-MM-dd')."\n";
|
||||
$difference = $dateStop->sub($dateStart);
|
||||
$measure = new Zend_Measure_Time($difference->toValue(), Zend_Measure_Time::SECOND);
|
||||
$measure->convertTo(Zend_Measure_Time::MONTH);
|
||||
$nbMonth = $measure->getValue(0) + 1;
|
||||
|
||||
// --- Score
|
||||
$dateCalcul = $dateStart;
|
||||
for($i=0; $i<$nbMonth; $i++) {
|
||||
$line = array();
|
||||
$line['siren'] = $item;
|
||||
$line['dateCalc'] = $dateCalcul->toString('yyyy-MM-dd');
|
||||
echo "\t".$dateCalcul->toString('yyyy-MM-dd')."\n";
|
||||
if ($dateCalcul->compare($dateReal) == -1) {
|
||||
echo "Inconnue à cette date\n";
|
||||
} else {
|
||||
$score = new SdMetier_Scoring_Base();
|
||||
$score->setEvenLimit($dateCalcul->toString('yyyyMMdd'));
|
||||
$result = $score->calculIndiScore($item, '', false, 0);
|
||||
$line['DateCreaEn'] = $result['DateCreaEn'];
|
||||
$line['Capital'] = $result['Capital'];
|
||||
$line['SituationJuridique'] = $result['SituationJuridique'];
|
||||
$line['Indiscore'] = $result['Indiscore'];
|
||||
$line['Indiscore20'] = $result['Indiscore20'];
|
||||
$line['ScoreSolvabilite'] = $result['ScoreSolvabilite'];
|
||||
$line['ScoreDirigeance'] = $result['ScoreDirigeance'];
|
||||
$line['ScoreConfor'] = $result['ScoreConfor'];
|
||||
$line['encours'] = $result['encours'];
|
||||
}
|
||||
// Ecrire ligne CSV
|
||||
$row = array();
|
||||
foreach ($fileHeader as $col) {
|
||||
if (array_key_exists($col, $line)) {
|
||||
$row[] = $line[$col];
|
||||
} else {
|
||||
$row[] = '';
|
||||
}
|
||||
}
|
||||
fputcsv($fp, $row, $delimiter, '"');
|
||||
|
||||
// date +1
|
||||
$dateCalcul->addMonth(1);
|
||||
}
|
||||
}
|
||||
|
||||
fclose($fp);
|
Loading…
Reference in New Issue
Block a user