Commit 47efed944a4975b76c252cb02c2f96aa80039165
1 parent
3db4f103
Exists in
anr_tempete
Call LATMOS simulation code with snapshot ID
Showing
3 changed files
with
87 additions
and
18 deletions
Show diff stats
php/RemoteDataCenter/ImpexParamManager.php
... | ... | @@ -45,8 +45,14 @@ class ImpexParamManager |
45 | 45 | return $param_id; |
46 | 46 | |
47 | 47 | $fullParamId = $param_id; |
48 | - foreach ($templateArgs as $key => $value) | |
49 | - $fullParamId .= "_".$value; | |
48 | + foreach ($templateArgs as $key => $value) { | |
49 | + if ($key == 'snapshots') { | |
50 | + $fullParamId .= "_".md5(serialize($value)); | |
51 | + } | |
52 | + else { | |
53 | + $fullParamId .= "_".$value; | |
54 | + } | |
55 | + } | |
50 | 56 | |
51 | 57 | return $fullParamId; |
52 | 58 | } |
... | ... | @@ -64,7 +70,7 @@ class ImpexParamManager |
64 | 70 | } |
65 | 71 | |
66 | 72 | public function createImpexParameter($param, $intervals, $templateArgs = NULL) |
67 | - { | |
73 | + { | |
68 | 74 | $this->initParam($param, $templateArgs); |
69 | 75 | $this->parameterKey = $this->impexParamInfo->getParameterKey($param); |
70 | 76 | |
... | ... | @@ -102,21 +108,46 @@ class ImpexParamManager |
102 | 108 | |
103 | 109 | if (is_array($templateArgs)) |
104 | 110 | $templateArgs = (object) $templateArgs; |
105 | - | |
111 | + | |
106 | 112 | if ($templateArgs->url_XYZ) |
107 | 113 | { |
108 | - $url_XYZ = $this->getOrbit($startTime, $stopTime, $templateArgs->url_XYZ); | |
109 | - $params = $this->makeRequest($templateArgs, $url_XYZ); | |
114 | + if (isset($templateArgs->snapshots)) { | |
115 | + // ANR TEMPETE | |
116 | + if (empty($templateArgs->snapshots)) { | |
117 | + throw new Exception("Please select at least one snapshot for $param"); | |
118 | + } | |
119 | + // Retrieve snapshots info | |
120 | + $paramMgr = new RemoteParamManager(); | |
121 | + $paramMgr->init(); | |
122 | + $snapshots_info = $paramMgr->getAvailableSnapshots($param); | |
123 | + // split request in relation with snapshots selection | |
124 | + $snap_date = array(); | |
125 | + foreach ($templateArgs->snapshots as $snapshot) { | |
126 | + foreach ($snapshots_info as $snap_info) { | |
127 | + if ($snapshot == $snap_info['id']) { | |
128 | + $snap_date[$snapshot] = strtotime($snap_info['startDate']); | |
129 | + } | |
130 | + } | |
131 | + } | |
132 | + $request_start = strtotime($startTime); | |
133 | + $request_stop = strtotime($stopTime); | |
134 | + $url_XYZ = $this->getOrbit($startTime, $stopTime, $templateArgs->url_XYZ); | |
135 | + $params = $this->makeRequest($templateArgs->snapshots[0], $templateArgs, $url_XYZ); | |
136 | + } | |
137 | + else { | |
138 | + $url_XYZ = $this->getOrbit($startTime, $stopTime, $templateArgs->url_XYZ); | |
139 | + $params = $this->makeRequest($this->resourceID, $templateArgs, $url_XYZ); | |
140 | + } | |
110 | 141 | } |
111 | 142 | else |
112 | 143 | { |
113 | - $params = $this->makeRequest($templateArgs); | |
144 | + $params = $this->makeRequest($this->resourceID, $templateArgs); | |
114 | 145 | } |
115 | 146 | |
116 | 147 | $remoteFile = $this->center->getData($params, $this->isSpectra); |
117 | 148 | |
118 | 149 | $localFile = $this->center->getFileName($this->resourceID, $templateArgs,$start); |
119 | - | |
150 | + | |
120 | 151 | if (!copy($remoteFile, IHMConfigClass::getLocalBasePath().$localFile)) { |
121 | 152 | if ($this->orbitTempFolder) |
122 | 153 | CommonClass::rrmdir($this->orbitTempFolder); |
... | ... | @@ -234,11 +265,11 @@ class ImpexParamManager |
234 | 265 | if ($templateArgs->url_XYZ) |
235 | 266 | { |
236 | 267 | $url_XYZ = $this->getOrbit($startTime, $stopTime, $templateArgs->url_XYZ); |
237 | - $params = $this->makeRequest($templateArgs, $url_XYZ); | |
268 | + $params = $this->makeRequest($this->resourceID, $templateArgs, $url_XYZ); | |
238 | 269 | } |
239 | 270 | else |
240 | 271 | { |
241 | - $params = $this->makeRequest($templateArgs); | |
272 | + $params = $this->makeRequest($this->resourceID, $templateArgs); | |
242 | 273 | } |
243 | 274 | |
244 | 275 | |
... | ... | @@ -423,7 +454,7 @@ class ImpexParamManager |
423 | 454 | } |
424 | 455 | } |
425 | 456 | |
426 | - public function makeRequest($templateArgs = null, $url_XYZ = null) | |
457 | + public function makeRequest($resourceID, $templateArgs = null, $url_XYZ = null) | |
427 | 458 | { |
428 | 459 | $params = array(); |
429 | 460 | |
... | ... | @@ -438,7 +469,7 @@ class ImpexParamManager |
438 | 469 | |
439 | 470 | foreach ($templateArgs as $key => $value) |
440 | 471 | { |
441 | - if ($key != 'url_XYZ') | |
472 | + if ($key != 'url_XYZ' && $key != 'snapshots') | |
442 | 473 | $extraParams[$key] = $value; |
443 | 474 | } |
444 | 475 | |
... | ... | @@ -464,10 +495,10 @@ class ImpexParamManager |
464 | 495 | } |
465 | 496 | else |
466 | 497 | { |
467 | - $params['accessUrl'] = $this->impexParamInfo->getAccessUrl($this->resourceID); | |
498 | + $params['accessUrl'] = $this->impexParamInfo->getAccessUrl($resourceID); | |
468 | 499 | } |
469 | 500 | |
470 | - $params['ResourceID'] = $this->resourceID; | |
501 | + $params['ResourceID'] = $resourceID; | |
471 | 502 | |
472 | 503 | return $params; |
473 | 504 | } | ... | ... |
php/RemoteDataCenter/RemoteParamManager.php
... | ... | @@ -423,5 +423,31 @@ class RemoteParamManager |
423 | 423 | return $datasetId.'.xml'; |
424 | 424 | |
425 | 425 | } |
426 | + | |
427 | + public function getAvailableSnapshots($paramId) { | |
428 | + $xpath = new DOMXpath($this->xmlDom); | |
429 | + $parameterNodes = $xpath->query('//dataCenter/simulationModel/simulationRegion/runID/dataset/parameter[@xml:id="'.$paramId.'"]'); | |
430 | + if ($parameterNodes->length < 1) { | |
431 | + return array(); | |
432 | + } | |
433 | + $parameterNode = $parameterNodes->item(0); | |
434 | + | |
435 | + $snapshotNodes = $xpath->query('//dataCenter/simulationModel/simulationRegion/runID/dataset[@xml:id="'.$parameterNode->parentNode->getAttribute('xml:id').'"]/snapshots/snapshot'); | |
436 | + if ($snapshotNodes->length < 1) { | |
437 | + return array(); | |
438 | + } | |
439 | + | |
440 | + $snapshots = array(); | |
441 | + foreach ($snapshotNodes as $snapshotNode) { | |
442 | + $snapshots[] = array( | |
443 | + 'id' => $snapshotNode->getAttribute('xml:id'), | |
444 | + 'releaseDate' => $snapshotNode->getAttribute('releaseDate'), | |
445 | + 'startDate' => $snapshotNode->getAttribute('startDate'), | |
446 | + 'stopDate' => $snapshotNode->getAttribute('stopDate'), | |
447 | + 'dataSrcUrl' => $snapshotNode->getAttribute('dataSrcUrl'), | |
448 | + ); | |
449 | + } | |
450 | + return $snapshots; | |
451 | + } | |
426 | 452 | } |
427 | 453 | ?> | ... | ... |
php/RemoteDataCenter/SimulationDataCenterClass.php
... | ... | @@ -389,8 +389,14 @@ class SimulationDataCenterClass extends RemoteDataCenterClass |
389 | 389 | public function getFileName($resourceID, $templateArgs, $start) |
390 | 390 | { |
391 | 391 | $fileName = strtr($resourceID, $this->impex_pairs); |
392 | - foreach ($templateArgs as $key => $value) | |
393 | - $fileName .= "_".$value; | |
392 | + foreach ($templateArgs as $key => $value) { | |
393 | + if ($key == 'snapshots') { | |
394 | + $fileName .= "_".md5(serialize($value)); | |
395 | + } | |
396 | + else { | |
397 | + $fileName .= "_".$value; | |
398 | + } | |
399 | + } | |
394 | 400 | |
395 | 401 | |
396 | 402 | $fileName .= "_".$start.'.xml'; |
... | ... | @@ -401,8 +407,14 @@ class SimulationDataCenterClass extends RemoteDataCenterClass |
401 | 407 | public function getMask($resourceID, $templateArgs) |
402 | 408 | { |
403 | 409 | $fileMask = strtr($resourceID, $this->impex_pairs); |
404 | - foreach ($templateArgs as $key => $value) | |
405 | - $fileMask .= "_".$value; | |
410 | + foreach ($templateArgs as $key => $value) { | |
411 | + if ($key == 'snapshots') { | |
412 | + $fileMask .= "_".md5(serialize($value)); | |
413 | + } | |
414 | + else { | |
415 | + $fileMask .= "_".$value; | |
416 | + } | |
417 | + } | |
406 | 418 | |
407 | 419 | $fileMask .= '*.xml'; |
408 | 420 | ... | ... |