From e225e6c336d1c460e64ea758f858502764c7b9e0 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Tue, 27 May 2014 12:56:14 +0000 Subject: [PATCH] Update --- library/Metier/partenaires/classMMap.php | 170 ++++++++++++++++------- scripts/cron.php | 9 +- scripts/jobs/enrichissement.php | 2 +- 3 files changed, 126 insertions(+), 55 deletions(-) diff --git a/library/Metier/partenaires/classMMap.php b/library/Metier/partenaires/classMMap.php index 85e472f6..8bf6e962 100644 --- a/library/Metier/partenaires/classMMap.php +++ b/library/Metier/partenaires/classMMap.php @@ -515,7 +515,8 @@ class MMap { public $adresseValidee=''; public $enCache=false; - private $apiKeyG='ABQIAAAAuKBtUyFonYJBl1fqfc78tRQvADPcxwXf3Q2QIE-M32vuSkrxiBRLUHDB_YSLeTscTDeWRKM_wILaaw'; +// private $apiKeyG='ABQIAAAAuKBtUyFonYJBl1fqfc78tRQvADPcxwXf3Q2QIE-M32vuSkrxiBRLUHDB_YSLeTscTDeWRKM_wILaaw'; + private $apiKeyG='AIzaSyBfyIMaVwm1nn8AupBf-asC816R71LZl8g'; // private $apiKey='ABQIAAAAuKBtUyFonYJBl1fqfc78tRT4Qe_2x2fax4Crd4sBzQI-tDkl3BRm2l2feTV5Lnx0Ah-aTIlwHtglpA'; private $apiKeyY='klII0gzV34Ho2TCsN3XiXeh4No033AifxMeDXfFXj8TDCXO3WAtOLj9c74VsV45HcII-'; private $apiKeyC='ae5216123e414fcd84b8ca9a0f43a68c'; @@ -566,7 +567,7 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999 case 2: $this->precision=4; break; // Town level geocoding case 3: $this->precision=6; break; // Way level geocoding case 4: $this->precision=8; break; // Road element level geocoding - default: die('Precisions Inconnue : "'.$result->geocode_level->code.'"='.$result->geocode_level->label.EOL.$page['body']); break; + default: /*die('Precisions Inconnue : "'.$result->geocode_level->code.'"='.$result->geocode_level->label.EOL.$page['body']);*/ break; } $this->adresseValidee=@preg_replace('/ +/', ' ', strtoupper(str_replace(''', "'", trim(htmlspecialchars_decode($result->road_element->number.' '.$result->way->name,ENT_QUOTES))))); @@ -615,8 +616,8 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999 $this->precision=0; $fileName=LOG_PATH.'/geoCodeur'.$this->geocodeur.'.log'; - $tmp=@explode(',',file_get_contents($filename)); - $nbQuery=$tmp[0]*1; + $tmp=@explode('|',file_get_contents($fileName)); + $nbQuery=@$tmp[1]*1; if ($pays=='') $pays='France'; /*if (preg_match('/^([0-9]{1,4} )(.*)$/', $adresse, $matches)) { @@ -632,8 +633,8 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999 $this->codeRetour=$page['code']; $this->header=$page['header']; - $nbQuery=($nbQuery*1)+1; - file_put_contents($fileName, $nbQuery.','.$this->codeRetour.",$url,".date('Y-m-d H:i:s').EOL); + $nbQuery++; + file_put_contents($fileName, $this->geocodeur.'|'.$nbQuery.'|'.$this->codeRetour."|$url|".date('Y-m-d H:i:s').'|'.$this->body.EOL); $res=@json_decode(utf8_decode($page['body'])); if ($this->codeRetour==200 && $res->status->success==1) { @@ -643,6 +644,9 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999 case 'housenumber': $this->precision=8; break; case 'street': $this->precision=6; break; case 'zip': $this->precision=5; break; + case 'city': $this->precision=4; break; + case 'district': $this->precision=3; break; + case 'sight': $this->precision=0; break; default: //print_r($res); //die('addressType inconnue : '.$geoCodage->addressType.EOL); @@ -663,7 +667,8 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999 echo 'lon='.$this->longitudeDec.EOL; echo 'precis='.$this->precision.EOL; die($url);*/ - return true; + if ($this->precision>0) + return true; } //print_r($page); //print_r($res); @@ -677,18 +682,18 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999 $this->precision=0; $fileName=LOG_PATH.'/geoCodeur'.$this->geocodeur.'.log'; - $tmp=@explode(',',file_get_contents($filename)); - $nbQuery=$tmp[0]*1; + $tmp=@explode('|',file_get_contents($fileName)); + $nbQuery=@$tmp[1]*1; - $_url='http://query.yahooapis.com/v1/public/yql?q=select+*+from+geo.placefinder+where+text%3D%22'.rawurlencode($address).'%22&format=xml'; + $url='http://query.yahooapis.com/v1/public/yql?q=select+*+from+geo.placefinder+where+text%3D%22'.rawurlencode($address).'%22&format=xml'; $_result = false; - $page=getUrl($_url, '', '', '', false, '', '', 3); + $page=getUrl($url, '', '', '', false, '', '', 3); $this->body=$page['body']; $this->codeRetour=$page['code']; $this->header=$page['header']; - $nbQuery=($nbQuery*1)+1; - file_put_contents($fileName, $nbQuery.','.$this->codeRetour.",$url,".date('Y-m-d H:i:s').EOL); + $nbQuery++; + file_put_contents($fileName, $this->geocodeur.'|'.$nbQuery.'|'.$this->codeRetour."|$url|".date('Y-m-d H:i:s').'|'.$this->body.EOL); if ($this->codeRetour==200) { @@ -700,6 +705,14 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999 FranceFR690042006813111 + + 87 + POINT_ADDRESS + 48.2817694.0904148.2817314.09047400 + 38B, Rue Maurice Romagon10800 Saint-Julien-les-VillasFrance38BRue Maurice Romagon + 10800Saint-Julien-les-VillasAubeChampagne-ArdenneFranceFR1010800D49A3CF6AD6DEB1C1272297511 + + */ //echo "Yahoo :'$address'".EOL.$this->body.EOL; @@ -707,20 +720,38 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999 $this->codeRetourY='ZERO_RESULTS'; //echo $this->codeRetourY.EOL; return false; - } elseif (preg_match('!(.*)(.*)(.*)!U', $this->body, $_match)) { - $quality=$_match[1]; - $this->codeRetourY='OK'; - if ($quality>87) $this->precision=9; // POI or Coordinate - elseif ($quality>82) $this->precision=8; // Address - elseif ($quality>75) $this->precision=7; // Intersection - elseif ($quality>70) $this->precision=6; // Street match - elseif ($quality>40) $this->precision=5; // Zip Code - elseif ($quality>30) $this->precision=4; // Town - elseif ($quality>20) $this->precision=3; // Sous/Région - elseif ($quality>10) $this->precision=2; // Region/state - elseif ($quality> 8) $this->precision=1; // Country - else { $this->precision=0; // Not an address - $this->codeRetourY='ZERO_RESULTS'; + } elseif (preg_match('!(.*)(?:.*)(.*)(.*)!U', $this->body, $_match)) { + if (preg_match('!(.*)(.*)(.*)(.*)!U', $this->body, $_match2)) { + $quality=$_match2[1]; + $qualityTxt=$_match2[2]; + $this->codeRetourY='OK'; + if ($quality>87 || $qualityTxt=='POINT_ADDRESS') $this->precision=9; // POI or Coordinate + elseif ($quality>82 || $qualityTxt=='INTERPOLATED') $this->precision=8; // Address (N° compris dans une Tranche d'adresse) + elseif ($quality>75) $this->precision=-7; // Intersection + elseif ($quality>70) $this->precision=-6; // Street match + elseif ($quality>40) $this->precision=-5; // Zip Code + elseif ($quality>30) $this->precision=-4; // Town + elseif ($quality>20) $this->precision=-3; // Sous/Région + elseif ($quality>10) $this->precision=-2; // Region/state + elseif ($quality> 8) $this->precision=-1; // Country + else { $this->precision=0; // Not an address + $this->codeRetourY='ZERO_RESULTS'; + } + } else { + $quality=$_match[1]; + $this->codeRetourY='OK'; + if ($quality>87) $this->precision=9; // POI or Coordinate + elseif ($quality>82) $this->precision=8; // Address + elseif ($quality>75) $this->precision=7; // Intersection + elseif ($quality>70) $this->precision=6; // Street match + elseif ($quality>40) $this->precision=5; // Zip Code + elseif ($quality>30) $this->precision=4; // Town + elseif ($quality>20) $this->precision=3; // Sous/Région + elseif ($quality>10) $this->precision=2; // Region/state + elseif ($quality> 8) $this->precision=1; // Country + else { $this->precision=0; // Not an address + $this->codeRetourY='ZERO_RESULTS'; + } } $this->latitudeDec=$_match[2]; $this->longitudeDec=$_match[3]; @@ -755,19 +786,22 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999 $this->precision=0; $fileName=LOG_PATH.'/geoCodeur'.$this->geocodeur.'.log'; - $tmp=@explode(',',file_get_contents($filename)); - $nbQuery=$tmp[0]*1; + $tmp=@explode('|',file_get_contents($fileName)); + $nbQuery=@$tmp[1]*1; - $url='http://maps.googleapis.com/maps/api/geocode/xml?address='.urlencode($adresse.', '.$cp.' '. $ville.', '.$pays).'&sensor=false'; + //$url='http://maps.googleapis.com/maps/api/geocode/xml?address='.urlencode($adresse.', '.$cp.' '. $ville.', '.$pays).'&sensor=false'; + $url='https://maps.googleapis.com/maps/api/geocode/xml?address='.urlencode($adresse.', '.$cp.' '. $ville.', '.$pays).'&sensor=false&key='.$this->apiKeyG; - $page=getUrl($url, '', '', $this->referer, false, 'maps.google.com', $proxy,3); + $page=getUrl($url, '', '', $this->referer, false, 'maps.googleapis.com', $proxy,3); + //print_r($page); + //die($url); //getUrl($url, $strCookies='', $postData='', $referer='', $debug=false, $host='', $proxy='', $timeout=0) { $this->body=$page['body']; $this->codeRetour=$page['code']; $this->header=$page['header']; - $nbQuery=($nbQuery*1)+1; - file_put_contents($fileName, $nbQuery.','.$this->codeRetour.",$url,".date('Y-m-d H:i:s').EOL); + $nbQuery++; + file_put_contents($fileName, $this->geocodeur.'|'.$nbQuery.'|'.$this->codeRetour."|$url|".date('Y-m-d H:i:s').'|'.$this->body.EOL); if ($this->codeRetour==200) { // REVERSE GEOCODING @@ -784,6 +818,32 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999 7 Intersection level accuracy. (Since 2.59) 8 Address level accuracy. (Since 2.59) */ +/* + + OK + + street_address + 0 Impasse Saint-Germier, 31270 Frouzins, France + + 0 + 0 + street_number + + + Impasse Saint-Germier + Imp. Saint-Germier + route + + + 43.5160071 + 1.3252185 + + RANGE_INTERPOLATED + + true + + + */ $this->codeRetourG=@getTextInHtml($this->body, '', '', ''); $location_type=@getTextInHtml($this->body, '', '', ''); switch($location_type) { @@ -805,17 +865,16 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999 break; } - $this->adresseValidee=strtoupper(str_replace(''', "'", htmlspecialchars_decode(utf8_decode(@getTextInHtml($this->body, '', '')),ENT_QUOTES))); - $strTmp=@getTextInHtml($this->body, '', '', ''); - $tabTmp=explode(',', $strTmp); - $this->latitudeDec=@$tabTmp[1]; - $this->longitudeDec=$tabTmp[0]; + $this->adresseValidee=strtoupper(str_replace(''', "'", htmlspecialchars_decode(utf8_decode(@getTextInHtml($this->body, '', '')),ENT_QUOTES))); + if (preg_match('!(?:.*)(?:.*)(.*)(?:.*)(.*)(?:.*)!Uis', $this->body, $matches2)) { + $this->latitudeDec=@$matches2[1]; + $this->longitudeDec=@$matches2[2]; $this->latitudeDeg=dec2dms($this->latitudeDec); $this->longitudeDeg=dec2dms($this->longitudeDec); + } /* 200 G_GEO_SUCCESS No errors occurred; the address was successfully parsed and its geocode has been returneds->geocodeur='Google'; - . 400 G_GEO_BAD_REQUEST A directions request could not be successfully parsed. 500 G_GEO_SERVER_ERROR A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known. 601 G_GEO_MISSING_QUERY The HTTP q parameter was either missing or had no value. For geocoding requests, this means that an empty address was @@ -840,8 +899,23 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999 UNKNOWN_ERROR indicates that the request could not be processed due to a server error. The request may succeed if you try again. */ - if ($this->codeRetourG=='OK') + /* + + + OVER_QUERY_LIMIT + You have exceeded your daily request quota for this API. + + */ + + if ($this->codeRetourG=='OK') { + //echo $this->body.EOL; + //echo 'Adr='.$this->adresseValidee.EOL; + //echo 'Lat='.$this->latitudeDec.EOL; + //echo 'Lon='.$this->longitudeDec.EOL; + //echo 'Pre='.$this->precision.EOL; + //die(); return true; + } elseif ($this->codeRetourG=='ZERO_RESULTS' || // http://maps.googleapis.com/maps/api/geocode/xml?address=0044+RUE+JACQUES+-+LOUIS+HENON%2C+69004+LYON+4EME%2C+France&sensor=false $this->codeRetourG=='INVALID_REQUEST' || // http://maps.googleapis.com/maps/api/geocode/xml?address=0028+B+RUE+MGR+DE+BEAUMONT%2C+97400+SAINT+DENIS%2C+La+R%E9union&sensor=false $this->codeRetourG=='OVER_QUERY_LIMIT') { @@ -907,7 +981,7 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999 $ligne='En base : '.print_r($zonage, true); } elseif ($this->accesDist) { $this->enCache=false; - $retM=$retY=false; + $retG=$retY=$retC=$retM=false; if (substr($codeRivoli,0,3)*1==971) $pays='Guadeloupe'; elseif (substr($codeRivoli,0,3)*1==972) $pays='Martinique'; elseif (substr($codeRivoli,0,3)*1==973) $pays='Guyane'; @@ -921,8 +995,8 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999 elseif (substr($codeRivoli,0,3)*1==987) $pays='Polynésie française'; // 98711 à 98758,98799 Polynésie française (sans changement) elseif (substr($codeRivoli,0,3)*1==988) $pays='Nouvelle Calédonie'; // 98801 à 98832 Nouvelle Calédonie (sans changement) elseif (substr($codeRivoli,0,3)*1==989) $pays='Wallis-et-Futuna'; // 98911 à 98913 Wallis et Futuna (anciens codes non compatibles : 98611 à 98613) - elseif (substr($codeRivoli,0,2)*1>96 && substr($codeRivoli,0,2)*1<99) - die("Code Rivoli non géré : '$codeRivoli'".EOL); + /*elseif (substr($codeRivoli,0,2)*1>96 && substr($codeRivoli,0,2)*1<99) + die("Code Rivoli non géré : '$codeRivoli'".EOL);*/ $retG=$this->geoCodeAdrCpVilleG($adresse, $cp, $ville, $pays); if ($this->codeRetourG=='OVER_QUERY_LIMIT' || $this->precision==0) { @@ -968,11 +1042,11 @@ API keybing = 56D6CBA671C986D3EA11B1B48F97507BE9B46999 /** Insertion de l'adresse que si elle est possible **/ //echo ('Avant Insert '.$this->latitudeDec.EOL.$this->longitudeDec.EOL); - if ($this->latitudeDec<>0 && $this->longitudeDec<>0) { - print_r($tabInsert); - echo ($this->latitudeDec.EOL.$this->longitudeDec.EOL); + if ($this->latitudeDec<>0 && $this->longitudeDec<>0 && $this->precision>0) { + // print_r($tabInsert); + //echo ($this->latitudeDec.EOL.$this->longitudeDec.EOL); $iDb->insert('zonageXY', $tabInsert); - if (mysql_errno()>0) echo mysql_error().die(EOL); + /*if (mysql_errno()>0) echo mysql_error().die(EOL);*/ } else { $this->precision=$this->latitudeDec=$this->longitudeDec=0; $this->adresseValidee=''; @@ -1074,7 +1148,7 @@ The text version of the service also accepts a list of lat/lng for the parameter [3] => 78.31.45.206 */ - $url="http://ws.geonames.org/srtm3?lat=$tabLatLon&lng=$lon"; + $url="http://ws.geonames.org/srtm3?lat=$tabLatLon&lng=$lon&username=scores_et_decisions&password=bj10sx"; $page=getUrl($url, '', '', '', false, '', '', 3); $alt=trim($page['body']); if (preg_match('/the (.*) limit of (.*) credits(.*) has been exceeded\. Please throttle your requests or use the commercial service/Uis', $alt, $matches)) { diff --git a/scripts/cron.php b/scripts/cron.php index 4d2cddde..0cf77c86 100644 --- a/scripts/cron.php +++ b/scripts/cron.php @@ -53,11 +53,7 @@ $sql = $commandesM->select() ->where("dateStart != '0000-00-00 00:00:00'") ->where("dateStop = '0000-00-00 00:00:00'"); $result = $commandesM->fetchAll($sql); -if ( count($result)>0 ) { - - - -} else { +if ( count($result)==0 ) { //Si pas de traitement en cours alors on lance $sql = $commandesM->select() @@ -69,7 +65,8 @@ if ( count($result)>0 ) { if (count($result)>0) { $info = $result->current(); echo "Lancement enrichissement $info->id\n"; - exec('php '.realpath(dirname(__FILE__))."/jobs/enrichissement.php --id ".$info->id." &"); + $log = $application->profil->path->data.'/log/'.$info->id.'.log'; + exec('php '.__DIR__."/jobs/enrichissement.php --id ".$info->id." 2>&1 >> ".$log." &"); } } \ No newline at end of file diff --git a/scripts/jobs/enrichissement.php b/scripts/jobs/enrichissement.php index 6b512efc..a9509117 100644 --- a/scripts/jobs/enrichissement.php +++ b/scripts/jobs/enrichissement.php @@ -1463,7 +1463,7 @@ function GPSData($siren, $nic, $values = false) $result = $iDb->select( 'etablissements e', - "e.adr_num, e.adr_btq, e.adr_typeVoie, e.adr_libVoie, e.adr_comp, e.adr_cp, e.adr_ville", + "LPAD(e.adr_num,4,0) AS adr_num, e.adr_btq, e.adr_typeVoie, e.adr_libVoie, e.adr_comp, LPAD(e.adr_cp,5,0) AS adr_cp, e.adr_ville", "siren=$siren AND nic=$nic", false, MYSQL_ASSOC); if (count($result)>0) { $MInsee = new MInsee($iDb);