From 47efed944a4975b76c252cb02c2f96aa80039165 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Fri, 1 Jul 2022 05:54:52 +0000 Subject: [PATCH] Call LATMOS simulation code with snapshot ID --- php/RemoteDataCenter/ImpexParamManager.php | 59 +++++++++++++++++++++++++++++++++++++++++++++-------------- php/RemoteDataCenter/RemoteParamManager.php | 26 ++++++++++++++++++++++++++ php/RemoteDataCenter/SimulationDataCenterClass.php | 20 ++++++++++++++++---- 3 files changed, 87 insertions(+), 18 deletions(-) diff --git a/php/RemoteDataCenter/ImpexParamManager.php b/php/RemoteDataCenter/ImpexParamManager.php index a058b14..74d49cb 100644 --- a/php/RemoteDataCenter/ImpexParamManager.php +++ b/php/RemoteDataCenter/ImpexParamManager.php @@ -45,8 +45,14 @@ class ImpexParamManager return $param_id; $fullParamId = $param_id; - foreach ($templateArgs as $key => $value) - $fullParamId .= "_".$value; + foreach ($templateArgs as $key => $value) { + if ($key == 'snapshots') { + $fullParamId .= "_".md5(serialize($value)); + } + else { + $fullParamId .= "_".$value; + } + } return $fullParamId; } @@ -64,7 +70,7 @@ class ImpexParamManager } public function createImpexParameter($param, $intervals, $templateArgs = NULL) - { + { $this->initParam($param, $templateArgs); $this->parameterKey = $this->impexParamInfo->getParameterKey($param); @@ -102,21 +108,46 @@ class ImpexParamManager if (is_array($templateArgs)) $templateArgs = (object) $templateArgs; - + if ($templateArgs->url_XYZ) { - $url_XYZ = $this->getOrbit($startTime, $stopTime, $templateArgs->url_XYZ); - $params = $this->makeRequest($templateArgs, $url_XYZ); + if (isset($templateArgs->snapshots)) { + // ANR TEMPETE + if (empty($templateArgs->snapshots)) { + throw new Exception("Please select at least one snapshot for $param"); + } + // Retrieve snapshots info + $paramMgr = new RemoteParamManager(); + $paramMgr->init(); + $snapshots_info = $paramMgr->getAvailableSnapshots($param); + // split request in relation with snapshots selection + $snap_date = array(); + foreach ($templateArgs->snapshots as $snapshot) { + foreach ($snapshots_info as $snap_info) { + if ($snapshot == $snap_info['id']) { + $snap_date[$snapshot] = strtotime($snap_info['startDate']); + } + } + } + $request_start = strtotime($startTime); + $request_stop = strtotime($stopTime); + $url_XYZ = $this->getOrbit($startTime, $stopTime, $templateArgs->url_XYZ); + $params = $this->makeRequest($templateArgs->snapshots[0], $templateArgs, $url_XYZ); + } + else { + $url_XYZ = $this->getOrbit($startTime, $stopTime, $templateArgs->url_XYZ); + $params = $this->makeRequest($this->resourceID, $templateArgs, $url_XYZ); + } } else { - $params = $this->makeRequest($templateArgs); + $params = $this->makeRequest($this->resourceID, $templateArgs); } $remoteFile = $this->center->getData($params, $this->isSpectra); $localFile = $this->center->getFileName($this->resourceID, $templateArgs,$start); - + if (!copy($remoteFile, IHMConfigClass::getLocalBasePath().$localFile)) { if ($this->orbitTempFolder) CommonClass::rrmdir($this->orbitTempFolder); @@ -234,11 +265,11 @@ class ImpexParamManager if ($templateArgs->url_XYZ) { $url_XYZ = $this->getOrbit($startTime, $stopTime, $templateArgs->url_XYZ); - $params = $this->makeRequest($templateArgs, $url_XYZ); + $params = $this->makeRequest($this->resourceID, $templateArgs, $url_XYZ); } else { - $params = $this->makeRequest($templateArgs); + $params = $this->makeRequest($this->resourceID, $templateArgs); } @@ -423,7 +454,7 @@ class ImpexParamManager } } - public function makeRequest($templateArgs = null, $url_XYZ = null) + public function makeRequest($resourceID, $templateArgs = null, $url_XYZ = null) { $params = array(); @@ -438,7 +469,7 @@ class ImpexParamManager foreach ($templateArgs as $key => $value) { - if ($key != 'url_XYZ') + if ($key != 'url_XYZ' && $key != 'snapshots') $extraParams[$key] = $value; } @@ -464,10 +495,10 @@ class ImpexParamManager } else { - $params['accessUrl'] = $this->impexParamInfo->getAccessUrl($this->resourceID); + $params['accessUrl'] = $this->impexParamInfo->getAccessUrl($resourceID); } - $params['ResourceID'] = $this->resourceID; + $params['ResourceID'] = $resourceID; return $params; } diff --git a/php/RemoteDataCenter/RemoteParamManager.php b/php/RemoteDataCenter/RemoteParamManager.php index 3852258..f347d0b 100644 --- a/php/RemoteDataCenter/RemoteParamManager.php +++ b/php/RemoteDataCenter/RemoteParamManager.php @@ -423,5 +423,31 @@ class RemoteParamManager return $datasetId.'.xml'; } + + public function getAvailableSnapshots($paramId) { + $xpath = new DOMXpath($this->xmlDom); + $parameterNodes = $xpath->query('//dataCenter/simulationModel/simulationRegion/runID/dataset/parameter[@xml:id="'.$paramId.'"]'); + if ($parameterNodes->length < 1) { + return array(); + } + $parameterNode = $parameterNodes->item(0); + + $snapshotNodes = $xpath->query('//dataCenter/simulationModel/simulationRegion/runID/dataset[@xml:id="'.$parameterNode->parentNode->getAttribute('xml:id').'"]/snapshots/snapshot'); + if ($snapshotNodes->length < 1) { + return array(); + } + + $snapshots = array(); + foreach ($snapshotNodes as $snapshotNode) { + $snapshots[] = array( + 'id' => $snapshotNode->getAttribute('xml:id'), + 'releaseDate' => $snapshotNode->getAttribute('releaseDate'), + 'startDate' => $snapshotNode->getAttribute('startDate'), + 'stopDate' => $snapshotNode->getAttribute('stopDate'), + 'dataSrcUrl' => $snapshotNode->getAttribute('dataSrcUrl'), + ); + } + return $snapshots; + } } ?> diff --git a/php/RemoteDataCenter/SimulationDataCenterClass.php b/php/RemoteDataCenter/SimulationDataCenterClass.php index e8fe3fe..5768ea9 100644 --- a/php/RemoteDataCenter/SimulationDataCenterClass.php +++ b/php/RemoteDataCenter/SimulationDataCenterClass.php @@ -389,8 +389,14 @@ class SimulationDataCenterClass extends RemoteDataCenterClass public function getFileName($resourceID, $templateArgs, $start) { $fileName = strtr($resourceID, $this->impex_pairs); - foreach ($templateArgs as $key => $value) - $fileName .= "_".$value; + foreach ($templateArgs as $key => $value) { + if ($key == 'snapshots') { + $fileName .= "_".md5(serialize($value)); + } + else { + $fileName .= "_".$value; + } + } $fileName .= "_".$start.'.xml'; @@ -401,8 +407,14 @@ class SimulationDataCenterClass extends RemoteDataCenterClass public function getMask($resourceID, $templateArgs) { $fileMask = strtr($resourceID, $this->impex_pairs); - foreach ($templateArgs as $key => $value) - $fileMask .= "_".$value; + foreach ($templateArgs as $key => $value) { + if ($key == 'snapshots') { + $fileMask .= "_".md5(serialize($value)); + } + else { + $fileMask .= "_".$value; + } + } $fileMask .= '*.xml'; -- libgit2 0.21.2