Subversion Repositories eFlore/Applications.cel

Compare Revisions

No changes between revisions

Ignore whitespace Rev 3788 → Rev 3789

/branches/v3.00-serfouette/scripts/modules/pull_plantnet/config.defaut.ini
5,7 → 5,7
; Url pour avoir les correspondandes des ids des obs chez les partenaires
urlPlantnetMatchingPartner = '/v1/edi/partners/observations/partnerids?token={token}'
; Url de base du service de suivi des obs plantnet
urlPlantnetLatestChanges = '/v1/edi/partners/projects/{project}/observations/{lifecycle}/latest?token={token}&startDate={startDate}';
urlPlantnetLatestChanges = '/v1/edi/partners/observations/{lifecycle}/latest?token={token}&startDate={startDate}';
; Url pour obtenir une obs PN
urlPlantnetObsById = '/v1/edi/partners/projects/{project}/observations/{id}?token={token}'
; token (prod ou test)
/branches/v3.00-serfouette/scripts/modules/pull_plantnet/PullPlantnet.php
22,12 → 22,8
// Cache d'informations utilisateurs provenant de l'annuaire TB
protected $userInfos = [];
 
// Cache des obs id PN traitées pendant cette run
protected $processedObsId = [];
 
// Paramètre de suivi et de pagination de l'API des obs PN
protected $currentPage = '';
protected $currentProject = '';
protected $lastTimestamp = '';
protected $hasMore = false;
 
112,32 → 108,25
 
/**
* Considering all modified pn obs since startDate
* One pn project after an other
* Inserting obs in tb db (if new and matching user email)
*/
private function updateLatest(string $startDate = '1917:03:15 00:00:00', string $lifecycle = 'modified') {
$startDate = strtotime($startDate) * 1000; // we need a microtimestamp
 
$pnProjects = $this->getProjects(); // refresh projects list
foreach ($pnProjects as $project) {
do {
$observations_PN = $this->getProjectLatest($project, $startDate, $lifecycle);
$this->updateObs($observations_PN);
} while ($this->hasMore);
}
do {
$observations_PN = $this->getLatest($startDate, $lifecycle);
$this->updateObs($observations_PN);
} while ($this->hasMore);
}
 
private function getProjectLatest(array $project, int $startDate, string $lifecycle): array {
$this->currentProject = $project;
private function getLatest(int $startDate, string $lifecycle): array {
$this->refreshBddConnexion();
 
if (!$this->currentPage) {
echo 'Projet ' . $project['name'] . "\n";
 
// hop, on appelle le service de PN
$url_service = str_replace(
['{project}', '{token}', '{startDate}', '{lifecycle}'],
[$project['id'], Config::get('tokenPlantnet'), $startDate, $lifecycle],
['{token}', '{startDate}', '{lifecycle}'],
[Config::get('tokenPlantnet'), $startDate, $lifecycle],
Config::get('urlPlantnetBase').Config::get('urlPlantnetLatestChanges')
);
 
177,8 → 166,8
// $url_service = Config::get('urlPlantnetBase').$responseJson['next'];
// Build next page url with last read timestamp, to avoid pagination latency
$url_service = str_replace(
['{project}', '{token}', '{startDate}', '{lifecycle}'],
[$project['id'], Config::get('tokenPlantnet'), $this->lastTimestamp, $lifecycle],
['{token}', '{startDate}', '{lifecycle}'],
[Config::get('tokenPlantnet'), $this->lastTimestamp, $lifecycle],
Config::get('urlPlantnetBase').Config::get('urlPlantnetLatestChanges')
);
$this->currentPage = $url_service;
191,7 → 180,7
}
 
private function getProjects(): array {
// get PN projects list
// get PN projects list (useless since we have a single source)
$url = str_replace('{token}', Config::get('tokenPlantnet'), Config::get('urlPlantnetBase').Config::get('urlPlantnetProjects'));
 
$this->debug("URL service liste projets : $url");
222,15 → 211,6
$url_cel_widget_saisie = Config::get('urlCelWidgetSaisie');
 
foreach ($observations_PN as $obs) {
// est-ce qu'on a déjà traité cette obs ? (oui une même obs peut être dans plusieurs projects)
if (array_key_exists($obs['id'], $this->processedObsId)) {
$this->log("Obs {$obs['id']} déjà traitée pendant cette run");
continue;
} else {
$this->processedObsId[$obs['id']] = true;
$this->log("Obs {$obs['id']} ajoutée à la liste des obs traitées pendant cette run");
}
 
// on ne teste pas la suppression de l'obs ici, faut le faire après avoir vérifié si on l'a déjà synchro
if (!isset($obs['currentName'])) {
$this->log("Obs {$obs['id']} sans nom de taxon, on zap");
387,12 → 367,12
// 'obsId1[num_nom_ret]' => '',
// 'obsId1[num_nom_sel]' => '',
// 'obsId1[num_taxon]' => '',
'obsId1[referentiel]' => $this->findProbableTaxoRepos($this->currentProject['id']), // @TODO faire une fois et mettre en cache
'obsId1[referentiel]' => $this->findProbableTaxoRepos($obs['project']), // @TODO faire une fois et mettre en cache
// 'obsId1[station]' => '',
'obsId1[obs_id]' => $obs['id'],
'projet' => 'PlantNet',
'tag-img' => implode(', ', $tags_images ?? []),
'tag-obs' => 'plantnet, plantnet-mobile, pn:referentiel-' . $this->currentProject['id'],
'tag-obs' => 'plantnet, plantnet-mobile, pn:referentiel-' . $obs['project'],
'utilisateur[courriel]' => $email,
'utilisateur[id_utilisateur]' => $infos_utilisateur['id'],
'utilisateur[nom]' => $infos_utilisateur['nom'],
654,7 → 634,6
 
private function updateOnePN($pnObsId, $pnProjectId) {
if (!is_int($pnObsId) || !is_string($pnProjectId)) {
die(var_dump($pnObsId, $pnProjectId));
throw new Exception("\nBad params types, give me an integer and a string plz\n");
}
// get PN project list
671,11 → 650,6
echo " - $projectId ($projectName)\n";
}
throw new Exception("Project $pnProjectId does not exist\n");
} else {
$this->currentProject = [
'id' => $pnProjectId,
'name' => $list[$pnProjectId],
];
}
 
// get PN obs
/branches/v3.00-serfouette/scripts
Property changes:
Modified: svn:mergeinfo
Merged /trunk/scripts:r3788
/branches/v3.00-serfouette
Property changes:
Modified: svn:mergeinfo
Merged /trunk:r3788