Commit ebe18d0a1e98469080a62edaeeab571f60cf5a30

Authored by Elena.Budnik
1 parent acf87705

new amda stat

php/classes/AmdaStats.php
1 1 <?php
2 2 /**
3 3 * @class AmdaStats
4   - * @version $Id: AmdaStats.php 2964 2015-06-26 07:53:48Z elena $
5   - *
  4 + * @version $Id: AmdaStats.php 2964 2015-06-26 07:53:48Z elena $
6 5 */
7 6  
8 7 class AmdaStats {
9   -
10   - public $statXml;
11   - public $tasks = array('mining', 'print', 'plot');
12   - public $tasksAdd = array('ttoper', 'samp', 'upload', 'create', 'images');
13   - public $usersToExclude = array( 'bouchemit', 'impex');
14   - public $success = true;
15   - public $paramInfo;
16   -
17   - public function __construct($user) {
18   -
19   - $this->statXml = new DomDocument('1.0','UTF-8');
20   - $this->statXml->preserveWhiteSpace = false;
21   - $this->statXml->formatOutput = true;
22   -
23   - if (!defined("StatsXml")){
24   - if (!$user){
25   - // general - to read
26   - define('StatsXml',DATAPATH.'Statistics/Stats.xml');
27   - // if (file_exists(StatsXml)) unlink(StatsXml);
28   - }
29   - else {
30   - // individual - to write
31   - define("StatsXml", USERPATH."/".$user."/Stats.xml");
32   - }
33   - }
34   -
35   - if (!file_exists(StatsXml)){
36   - if (!is_dir(DATAPATH.'Statistics')) {
37   - if (!mkdir(DATAPATH.'Statistics', 0775))
38   - return -1;
39   - if (!chgrp(DATAPATH.'Statistics', APACHE_USER))
40   - return -1;
41   - }
42   -
43   - $status = $this->generateXml();
44   - if (!$status) {
45   - error_log('Cannot create Stats.xml: Fatal Error '.$user,1,email);
46   - $this->success = false;
47   - }
48   - }
49   - else {
50   - $status = $this->statXml->load(StatsXml);
51   - if (!$status) {
52   - $status = $this->generateXml();
53   - $msg = $status ? 'Cannot load Stats.xml. New Stats.xml was created' :
54   - 'Cannot load Stats.xml. Cannot create Stats.xml: Fatal Error ';
55   - error_log($msg.$user,1,email);
56   - if (!$status) $this->success = false;
57   - }
58   - }
59   -
  8 +
  9 + public $statXml;
  10 + public $tasks = array('mining', 'print', 'plot');
  11 + public $tasksAdd = array('ttoper', 'samp', 'upload', 'create', 'images');
  12 + public $usersToExclude = array( 'bouchemit', 'impex');
  13 + public $success = true;
  14 + private $user = null;
  15 +
  16 + public function __construct($user) {
  17 +
  18 + $this->statXml = new DomDocument('1.0','UTF-8');
  19 + $this->statXml->preserveWhiteSpace = false;
  20 + $this->statXml->formatOutput = true;
  21 +
  22 + if (!defined("StatsXml")){
  23 + if (!$user){
  24 + // general - to read
  25 + define('StatsXml',DATAPATH.'Statistics/Stats.xml');
  26 + // if (file_exists(StatsXml)) unlink(StatsXml);
  27 + }
  28 + else {
  29 + // individual - to write
  30 + define("StatsXml", USERPATH."/".$user."/Stats.xml");
  31 + $this->user = $user;
  32 + }
  33 + }
  34 +
  35 + if (!file_exists(StatsXml)) {
  36 + if (!is_dir(DATAPATH.'Statistics')) {
  37 + if (!mkdir(DATAPATH.'Statistics', 0775)) $this->success = false; //return -1;
  38 + if (!chgrp(DATAPATH.'Statistics', APACHE_USER)) $this->success = false; // return -1;
  39 + }
  40 +
  41 + $status = $this->generateXml();
  42 + if (!$status) {
  43 + error_log('Cannot create Stats.xml: Fatal Error '.$user,1,email);
  44 + $this->success = false;
  45 + }
  46 + }
  47 + else {
  48 + $status = $this->statXml->load(StatsXml);
  49 + if (!$status) {
  50 + $status = $this->generateXml();
  51 + $msg = $status ? 'Cannot load Stats.xml. New Stats.xml was created' :
  52 + 'Cannot load Stats.xml. Cannot create Stats.xml: Fatal Error ';
  53 +
  54 + error_log($msg.$user,1,email);
  55 +
  56 + if (!$status)
  57 + $this->success = false;
  58 + }
  59 + }
60 60 }
61 61  
62 62 /*
63 63 * Merge individual User Stats.xml into one generique Stats.xml
64 64 */
65   - public function mergeXml() {
66   -
67   - $tags = array_merge($this->tasks, $this->tasksAdd);
68   -
69   - $doc2 = new DomDocument("1.0");
  65 + public function mergeXml() {
  66 +
  67 + $tags = array_merge($this->tasks, $this->tasksAdd);
  68 +
  69 + $doc2 = new DomDocument("1.0");
  70 +
  71 + $users=glob(USERPATH."*");
  72 + foreach ($users as $user) {
  73 + $name2 = $user."/Stats.xml";
  74 +
  75 + if (!file_Exists($name2)) continue;
  76 +
  77 + $doc2->load($name2);
  78 +
  79 + foreach ($tags as $tag) {
  80 + $tag1 = $this->statXml->getElementsByTagName($tag)->item(0);
  81 + $tag2 = $doc2->getElementsByTagName($tag)->item(0);
  82 + $items2 = $tag2->getElementsByTagName("item");
  83 + if ($items2->length > 0) {
  84 + foreach ($items2 as $item2) {
  85 + $item1 = $this->statXml->importNode($item2, true);
  86 + $tag1->appendChild($item1);
  87 + }
  88 + }
  89 + }
  90 + }
  91 +
  92 + // write task statistics as json
  93 + $this->getModulesStat(null,null,true);
  94 + // write data statistics as json
  95 + $this->getDataStat(0,null,null,true);
  96 +
  97 + return $this->statXml->save(StatsXml);
  98 + }
  99 +
  100 + private function generateXml() {
  101 +
  102 + $rootElement = $this->statXml->createElement('stats');
  103 +
  104 + $allTasks = array_merge($this->tasks, $this->tasksAdd);
  105 +
  106 + foreach ($allTasks as $task) {
  107 + $element = $this->statXml->createElement("$task");
  108 + $rootElement->appendChild($element);
  109 + }
  110 +
  111 + $this->statXml->appendChild($rootElement);
  112 +
  113 + return $this->statXml->save(StatsXml);
  114 + }
70 115  
71   - $users=glob(USERPATH."*");
72   - foreach ($users as $user) {
73   - $name2 = $user."/Stats.xml";
74   -
75   - if (!file_Exists($name2)) continue;
76   -
77   - $doc2->load($name2);
78   -
79   - foreach ($tags as $tag){
80   - $tag1 = $this->statXml->getElementsByTagName($tag)->item(0);
81   - $tag2 = $doc2->getElementsByTagName($tag)->item(0);
82   - $items2 = $tag2->getElementsByTagName("item");
83   - if ($items2->length > 0) {
84   - foreach ($items2 as $item2) {
85   - $item1 = $this->statXml->importNode($item2, true);
86   - $tag1->appendChild($item1);
87   - }
88   - }
89   - }
90   - }
91   -
92   - // write task statistics as json
93   - $this->getModulesStat(null,null,true);
94   - // write data statistics as json
95   - $this->getDataStat(0,null,null,true);
96   -
97   - return $this->statXml->save(StatsXml);
98   -
99   -}
100   -
101   - private function generateXml() {
102   -
103   - $rootElement = $this->statXml->createElement('stats');
104   -
105   - $allTasks = array_merge($this->tasks, $this->tasksAdd);
106   -
107   - foreach ($allTasks as $task) {
108   - $element = $this->statXml->createElement("$task");
109   - $rootElement->appendChild($element);
110   - }
111   -
112   - $this->statXml->appendChild($rootElement);
113   -
114   - return $this->statXml->save(StatsXml);
115   - }
116   -
117   - public function getInfo($var) {
118   -
119   - $info = $this->paramInfo->GetParamInfo($var);
120   - $id = $info['ddinfos']['dataset']['id'];
121   -
122   - if (!$id) {
123   - $id = $info['codeinfos']['vi'];
124   - // check if from Remote base
125   - if (!$id) {
126   - $info = $this->paramInfo->getRemoteParamInfo($var);
127   - if (!$info)
128   - return 'undefined';
129   - else
130   - return $info['base'].':'.$info['vi'];
131   - }
132   - else
133   - return $id;
134   - }
135   - else
136   - return $id;
137   -
138   - }
139   -
140   - public function addTask($task, $user, $vars){
141   -
142   - if (!in_array($user, $this->usersToExclude)) {
143   -
144   - $taskElement = $this->statXml->getElementsByTagName("$task")->item(0);
145   - if (is_object($taskElement)) {
146   - $newTask = $this->statXml->createElement('item');
147   - $newTask->setAttribute('date', date('Y-m-d'));
148   - $newTask->setAttribute('user', $user);
149   -
150   - if ($vars) {
151   - $this->paramInfo = new ParamsInfoMgr();
152   -
153   - $ID = array();
154   -
155   - foreach ($vars as $var) {
156   - if ((substr($var, 0, 7) == 'impex__') || (substr($var, 0, 13) == 'spase___IMPEX')){
157   - $ID[] = 'impex';
158   - }
159   - elseif (substr($var, 0, 4) == 'wsd_') {
160   - $ID[] = 'uploadedData';
161   - }
162   - // if derived parameter parse it
163   -// elseif (substr($var, 0, 3) == 'ws_') {
164   -//
165   -// if (!$parser) $parser = new Parser();
166   -// $realVar = $parser->replaceAll($var);
167   -// $varArr = $parser->getVars($realVar);
168   -// foreach ($varArr as $var) {
169   -// $ID[] = $this->getInfo($var);
170   -// }
171   -// }
172   - else {
173   - $ID[] = $this->getInfo($var);
174   - }
175   - }
176   -
177   - $ID = array_unique($ID);
178   -
179   - foreach ($ID as $id) {
180   - $datasetElement = $this->statXml->createElement('dataset', $id);
181   - $newTask->appendChild($datasetElement);
182   - }
183   - }
  116 + public function addTaskWithParams($user, $task, $vars) {
  117 +
  118 +// if (!$this->user) {
  119 +// error_log('User is null', 1, email);
  120 +// return;
  121 +// }
  122 +
  123 + if (!in_array($user, $this->usersToExclude)) {
  124 + $taskElement = $this->statXml->getElementsByTagName("$task")->item(0);
  125 + if (is_object($taskElement)) {
  126 + $newTask = $this->statXml->createElement('item');
  127 + $newTask->setAttribute('date', date('Y-m-d'));
  128 + $newTask->setAttribute('user', $user);
  129 +
  130 + if ($vars) {
  131 + $ID = array();
  132 +
  133 + foreach ($vars as $var) {
  134 + if ((substr($var, 0, 7) == 'impex__') || (substr($var, 0, 13) == 'spase___IMPEX')){
  135 + $ID[] = 'impex';
  136 + }
  137 + elseif (substr($var, 0, 4) == 'wsd_') {
  138 + $ID[] = 'uploadedData';
  139 + }
  140 + else
  141 + $ID[] = $var;
  142 + }
  143 +
  144 + $ID = array_unique($ID);
  145 +
  146 + foreach ($ID as $id) {
  147 + $datasetElement = $this->statXml->createElement('dataset', $id);
  148 + $newTask->appendChild($datasetElement);
  149 + }
  150 + }
  151 + }
  152 + $taskElement->appendChild($newTask);
  153 + $this->statXml->save(StatsXml);
  154 + }
  155 + else
  156 + error_log('Check Stats.xml - no task element '.$task, 1, email);
  157 + }
  158 +
  159 + public function addTask($task){
  160 +
  161 + if (!$this->user) {
  162 + error_log('User is null', 1, email);
  163 + return;
  164 + }
  165 +
  166 + if (!in_array($this->user, $this->usersToExclude)) {
  167 + $taskElement = $this->statXml->getElementsByTagName("$task")->item(0);
  168 + if (is_object($taskElement)) {
  169 + $newTask = $this->statXml->createElement('item');
  170 + $newTask->setAttribute('date', date('Y-m-d'));
  171 + $newTask->setAttribute('user', $this->user);
184 172  
185   - $taskElement->appendChild($newTask);
186   - $this->statXml->save(StatsXml);
187   - }
188   - else
189   - error_log('Check Stats.xml - no task element '.$task, 1, email);
190   - }
191   - }
  173 + $taskElement->appendChild($newTask);
  174 + $this->statXml->save(StatsXml);
  175 + }
  176 + else
  177 + error_log('Check Stats.xml - no task element '.$task, 1, email);
  178 + }
  179 + }
192 180  
193 181 /*
194 182 * Show Statistics
195 183 */
196   - public function getModulesStat($start, $stop, $update){
197   -
198   -
199   - if (!$update && file_exists(DATAPATH.'Statistics/tasks.json')) {
200   - return file_get_contents(DATAPATH.'Statistics/tasks.json');
201   - }
202   -
203   - $taskArray = array();
204   -
205   - foreach (array_merge($this->tasks,$this->tasksAdd) as $task) {
206   - $theTask = $this->statXml->getElementsByTagName($task)->item(0);
207   - $items = $theTask->getElementsByTagName('item');
208   - $hints = $items->length;
209   -
210   - $startStop = $this->getStartStop($items, $start, $stop);
211   - $taskArray[] = array('task' => $task, 'number' => $hints,
212   - 'start' => $startStop[0], 'stop' => $startStop[1]);
213   - }
214   -
215   - $objToReturn = json_encode(array('stats' => $taskArray));
216   -
217   - file_put_contents(DATAPATH.'Statistics/tasks.json', $objToReturn);
218   -
219   - return $objToReturn;
220   - }
221   -
222   -/*
223   -* Show Statistics
224   -*/
225   - public function getDataStat($index, $start, $stop, $update){
  184 + public function getModulesStat($start, $stop, $update){
226 185  
  186 + if (!$update && file_exists(DATAPATH.'Statistics/tasks.json')) {
  187 + return file_get_contents(DATAPATH.'Statistics/tasks.json');
  188 + }
  189 +
  190 + $taskArray = array();
227 191  
228   - if (!$update && file_exists(DATAPATH.'Statistics/data.json')) {
229   - $GENERALarray = json_decode(file_get_contents(DATAPATH.'Statistics/data.json'));
230   - }
231   - else {
232   - $VIarray = array();
233   - $TOTALarray = array();
234   - $STARTarray = array();
235   - $STOParray = array();
  192 + foreach (array_merge($this->tasks,$this->tasksAdd) as $task) {
  193 + $theTask = $this->statXml->getElementsByTagName($task)->item(0);
  194 + $items = $theTask->getElementsByTagName('item');
  195 + $hints = $items->length;
236 196  
237   - foreach ($this->tasks as $task) {
  197 + $startStop = $this->getStartStop($items, $start, $stop);
  198 + $taskArray[] = array('task' => $task, 'number' => $hints,
  199 + 'start' => $startStop[0], 'stop' => $startStop[1]);
  200 + }
238 201  
239   - $theTask = $this->statXml->getElementsByTagName($task)->item(0);
240   - $items = $theTask->getElementsByTagName('item');
241   - $TASKarray = array();
242   -
243   - foreach ($items as $item){
244   -
245   - $VIs = $item->getElementsByTagName('dataset');
246   - $time = strtotime($item->getAttribute('date'));
247   -
248   - foreach ($VIs as $VI) {
249   - $id = $VI->nodeValue;
250   - if ($id) {
251   - if ($TASKarray[$id]) {
252   - $TASKarray[$id]++;
253   - $TOTALarray[$id]++;
254   - if ($STARTarray[$id] > $time)
255   - $STARTarray[$id] = $time;
256   - if ($STOParray[$id] < $time)
257   - $STOParray[$id] = $time;
258   - }
259   - else {
260   - if (!$TOTALarray[$id]) {
261   - $STARTarray[$id] = $time;
262   - $STOParray[$id] = $time;
263   - $TOTALarray[$id] = 1;
264   - }
265   - else {
266   - if ($STARTarray[$id] > $time)
267   - $STARTarray[$id] = $time;
268   - if ($STOParray[$id] < $time)
269   - $STOParray[$id] = $time;
270   - $TOTALarray[$id]++;
271   - }
272   - $TASKarray[$id] = 1;
273   - }
274   - }
275   - }
276   - }
277   - $VIarray[$task] = $TASKarray;
278   - }
279   -
280   - $GENERALarray = array();
281   - arsort($TOTALarray);
282   -
283   - foreach ($TOTALarray as $key => $value) {
284   - $viStart = $STARTarray[$key];
285   - $viStop = $STOParray[$key];
286   - $plot = $VIarray['plot'][$key];
287   - $mining = $VIarray['mining'][$key];
288   - $print = $VIarray['print'][$key];
289   - if ($key != 'undefined')
290   - {
291   - $GENERALarray[] = array('id' => $key, 'number' => $value,
292   - 'plot' => $plot, 'mining' => $mining,
293   - 'print' => $print, 'start' => $viStart,
294   - 'stop' => $viStop);
295   - }
296   - }
297   - }
298   -
299   - $Nmax = count($GENERALarray);
300   -
301   - $length = $index + 20 > $Nmax ? $Nmax - $index + 1 : 20;
302   - $objToReturn = array('stats' => array_reverse(array_slice($GENERALarray, $index, $length)));
303   -
304   - file_put_contents(DATAPATH.'Statistics/data.json',json_encode($GENERALarray));
305   - // $objToReturn = array('stats' => $GENERALarray);
306   - return $objToReturn;
307   - }
308   -
309   - public function getStartStop($items, $start, $stop){
310   -
311   - if (!$start) $start = 0;
312   - if (!$stop) $stop = 100000000000;
313   - $date = array();
314   -
315   - foreach ($items as $item) {
316   - $newDate = strtotime($item->getAttribute('date'));
317   -
318   - if (($newDate > $start) && ($newDate < $stop))
319   - $date[] = $newDate;
320   - }
321   -
322   - return array(min($date), max($date));
323   - }
324   -
325   - public function mergeStats($inXml) {
  202 + $objToReturn = json_encode(array('stats' => $taskArray));
326 203  
  204 + file_put_contents(DATAPATH.'Statistics/tasks.json', $objToReturn);
327 205  
328   - if (!file_exists(StatsXml)) return 0;
  206 + return $objToReturn;
  207 + }
329 208  
330   - if (!file_exists($inXml)) return 0;
331   -
332   - $tags = array_merge($this->tasks,$this->tasksAdd);
333   -
334   - $doc1 = new DomDocument("1.0");
335   - $doc2 = new DomDocument("1.0");
336   -
337   - if (!$doc1->load(StatsXml)) return 0;
338   - if (!$doc2->load($inXml)) return 0;
339   -
340   - foreach ($tags as $tag){
  209 +/*
  210 +* Show Statistics
  211 +*/
  212 + public function getDataStat($index, $start, $stop, $update){
  213 +
  214 +
  215 + if (!$update && file_exists(DATAPATH.'Statistics/data.json')) {
  216 + $GENERALarray = json_decode(file_get_contents(DATAPATH.'Statistics/data.json'));
  217 + }
  218 + else {
  219 + $VIarray = array();
  220 + $TOTALarray = array();
  221 + $STARTarray = array();
  222 + $STOParray = array();
  223 +
  224 + foreach ($this->tasks as $task) {
  225 + $theTask = $this->statXml->getElementsByTagName($task)->item(0);
  226 + $items = $theTask->getElementsByTagName('item');
  227 + $TASKarray = array();
  228 +
  229 + foreach ($items as $item){
  230 + $VIs = $item->getElementsByTagName('dataset');
  231 + $time = strtotime($item->getAttribute('date'));
  232 +
  233 + foreach ($VIs as $VI) {
  234 + $id = $VI->nodeValue;
  235 + if ($id) {
  236 + if ($TASKarray[$id]) {
  237 + $TASKarray[$id]++;
  238 + $TOTALarray[$id]++;
  239 + if ($STARTarray[$id] > $time)
  240 + $STARTarray[$id] = $time;
  241 + if ($STOParray[$id] < $time)
  242 + $STOParray[$id] = $time;
  243 + }
  244 + else {
  245 + if (!$TOTALarray[$id]) {
  246 + $STARTarray[$id] = $time;
  247 + $STOParray[$id] = $time;
  248 + $TOTALarray[$id] = 1;
  249 + }
  250 + else {
  251 + if ($STARTarray[$id] > $time)
  252 + $STARTarray[$id] = $time;
  253 + if ($STOParray[$id] < $time)
  254 + $STOParray[$id] = $time;
  255 + $TOTALarray[$id]++;
  256 + }
  257 + $TASKarray[$id] = 1;
  258 + }
  259 + }
  260 + }
  261 + }
  262 + $VIarray[$task] = $TASKarray;
  263 + }
  264 +
  265 + $GENERALarray = array();
  266 + arsort($TOTALarray);
  267 +
  268 + foreach ($TOTALarray as $key => $value) {
  269 + $viStart = $STARTarray[$key];
  270 + $viStop = $STOParray[$key];
  271 + $plot = $VIarray['plot'][$key];
  272 + $mining = $VIarray['mining'][$key];
  273 + $print = $VIarray['print'][$key];
  274 + if ($key != 'undefined')
  275 + {
  276 + $GENERALarray[] = array('id' => $key, 'number' => $value,
  277 + 'plot' => $plot, 'mining' => $mining,
  278 + 'print' => $print, 'start' => $viStart,
  279 + 'stop' => $viStop);
  280 + }
  281 + }
  282 + }
  283 +
  284 + $Nmax = count($GENERALarray);
341 285  
342   - $tag1 = $doc1->getElementsByTagName($tag)->item(0);
343   - $tag2 = $doc2->getElementsByTagName($tag)->item(0);
344   - $items2 = $tag2->getElementsByTagName("item");
345   - if ($items2->length > 0) {
346   - foreach ($items2 as $item2) {
347   - $item1 = $doc1->importNode($item2, true);
348   - $tag1->appendChild($item1);
349   - }
350   - }
351   - }
352   -
353   - return $doc1->save(StatsXml);
354   -
355   - }
  286 + $length = $index + 20 > $Nmax ? $Nmax - $index + 1 : 20;
  287 + $objToReturn = array('stats' => array_reverse(array_slice($GENERALarray, $index, $length)));
  288 +
  289 + file_put_contents(DATAPATH.'Statistics/data.json',json_encode($GENERALarray));
  290 + // $objToReturn = array('stats' => $GENERALarray);
  291 + return $objToReturn;
  292 + }
  293 +
  294 + public function getStartStop($items, $start, $stop) {
  295 + if (!$start) $start = 0;
  296 + if (!$stop) $stop = 100000000000;
  297 +
  298 + $date = array();
  299 +
  300 + foreach ($items as $item) {
  301 + $newDate = strtotime($item->getAttribute('date'));
  302 +
  303 + if (($newDate > $start) && ($newDate < $stop))
  304 + $date[] = $newDate;
  305 + }
  306 +
  307 + return array(min($date), max($date));
  308 + }
  309 +
  310 + public function mergeStats($inXml) {
  311 +
  312 + if (!file_exists(StatsXml)) return 0;
  313 + if (!file_exists($inXml)) return 0;
  314 +
  315 + $tags = array_merge($this->tasks,$this->tasksAdd);
  316 +
  317 + $doc1 = new DomDocument("1.0");
  318 + $doc2 = new DomDocument("1.0");
  319 +
  320 + if (!$doc1->load(StatsXml)) return 0;
  321 + if (!$doc2->load($inXml)) return 0;
  322 +
  323 + foreach ($tags as $tag){
  324 + $tag1 = $doc1->getElementsByTagName($tag)->item(0);
  325 + $tag2 = $doc2->getElementsByTagName($tag)->item(0);
  326 + $items2 = $tag2->getElementsByTagName("item");
  327 + if ($items2->length > 0) {
  328 + foreach ($items2 as $item2) {
  329 + $item1 = $doc1->importNode($item2, true);
  330 + $tag1->appendChild($item1);
  331 + }
  332 + }
  333 + }
  334 +
  335 + return $doc1->save(StatsXml);
  336 + }
356 337 }
357 338 ?>
... ...
php/classes/InfoProvider.php deleted
... ... @@ -1,30 +0,0 @@
1   -<?php
2   -/**
3   - * @class InfoProvider
4   - * @version $Id: InfoProvider.php 2662 2014-11-26 09:45:33Z natacha $
5   - *
6   - */
7   -class InfoProvider {
8   -// units conversion:
9   -// km2Re = 1./6371.0; km2au = 1./1.5 *10^9; km2rma (mars) 1./3396.0; km2rv 1.0/6052.0; km2rmะต 1.0/2439.7
10   - public $realConversion = array( 'km2re' => '1.5696e-4', 'K2eV' => '8.622e-5', 'MK2eV' => '86.2069',
11   - 'km2au' => '6.68e-9', 'km2rma' => '2.945e-4', 'km2rv' => '1.652e-4',
12   - 'rma2km' => '3396.0', 'rv2km' => '6052.0', 'rga2km' => '2631.0',
13   - 're2km' => '6371.0', 'km2rmะต' => '4.099e-4','rme2km' => '2440.0',
14   - 'mbar2npa' => '1.0e11', 'a2na' => '1.0e9');
15   -
16   - public $Constants;
17   -
18   -
19   - function __construct() {
20   - $this->Constants = array();
21   - }
22   -
23   -//TODO constants => from constants.xml
24   -
25   - public function getConversion($key) {
26   - if ($this->realConversion[$key]) return $this->realConversion[$key];
27   - return -1;
28   - }
29   - }
30   -?>
31 0 \ No newline at end of file
php/classes/ParamsInfoMgr.php deleted
... ... @@ -1,980 +0,0 @@
1   -<?php
2   -/**
3   - * @class ParamsInfoMgr
4   - * @version $Id: ParamsInfoMgr.php 2780 2015-02-26 12:02:37Z elena $
5   - *
6   - */
7   -
8   - class ParamsInfoMgr {
9   - protected $derivedParamMgr, $mydataParamMgr, $mySimuParamMgr;
10   -
11   - protected $missionDom, $localDom, $internalDom;
12   -
13   - protected $ddLocalMissionXPath;
14   -
15   - function __construct() {
16   - $this->ddLocalMissionXPath = array();
17   - }
18   -
19   - /*
20   - * Get all info for a given REMOTE THEMIS parameter
21   - */
22   - public function getRemoteThemisParamInfo($param) {
23   -
24   - $info = array();
25   -
26   - if (sscanf($param,"%[^'('](%d:%d)",$par,$cstart,$cstop) == 3)
27   - {
28   - $comp_start = $cstart;
29   - $comp_stop = $cstop;
30   - }
31   - else if (sscanf($param,"%[^'('](%d)",$par,$cstart) == 2)
32   - {
33   - $comp_start = $cstart;
34   - $comp_stop = $cstart;
35   - }
36   - else
37   - $par = $param;
38   -
39   - $paramXML = new DomDocument("1.0");
40   - if (!$paramXML->load(RemoteData."THEMIS/base.xml")) return null;
41   -
42   -
43   - $paramID = $paramXML->getElementById($par);
44   - if($paramID == null ) return null;
45   -
46   - $parent = $paramID ->parentNode;
47   -
48   - $vi = $parent->getAttribute('xml:id');
49   -
50   - $info['base'] = '';
51   - $info['vi'] = $vi;
52   -
53   - return $info;
54   -
55   - }
56   -
57   - /*
58   - * Get all info for a given REMOTE parameter
59   - */
60   - public function getRemoteParamInfo($param) {
61   -
62   - if (substr($param,0,2) == 'th')
63   - return $this->getRemoteThemisParamInfo($param);
64   -
65   - $info = array();
66   -
67   - $ParamFile = RemoteData.'PARAMS/'.$param.'.xml';
68   - if (!file_exists($ParamFile)) return null;
69   -
70   - $paramXML = new DomDocument("1.0");
71   - if (!$paramXML->load($ParamFile)) return null;
72   -
73   - $fieldname = $paramXML->getElementsByTagName('paramID');
74   - if($fieldname->length == 0 ) return null;
75   -
76   - $base = $paramXML->getElementsByTagName('baseID');
77   - $vi = $paramXML->getElementsByTagName('viID');
78   -
79   - $info['base'] = $base->length == 0 ? 'undefined' : $base->item(0)->nodeValue;
80   - $info['vi'] = $vi->length == 0 ? 'undefined' : $vi->item(0)->nodeValue;
81   -
82   - $info['title'] = $fieldname->item(0)->nodeValue;
83   -
84   - return $info;
85   -
86   - }
87   -
88   - /*
89   - * Get all info for a given parameter
90   - */
91   - public function GetParamInfo($param)
92   - {
93   - // to correct 'restricted' parameters
94   - if (strpos($param, restricted) !== false) {
95   - $param = str_replace(restricted,"",$param);
96   - }
97   -
98   - //get components
99   - if (sscanf($param,"%[^'('](%d:%d)",$par,$cstart,$cstop) == 3)
100   - {
101   - $comp_start = $cstart;
102   - $comp_stop = $cstop;
103   - }
104   - else if (sscanf($param,"%[^'('](%d)",$par,$cstart) == 2)
105   - {
106   - $comp_start = $cstart;
107   - $comp_stop = $cstart;
108   - }
109   - else
110   - $par = $param;
111   -
112   - if (strncmp(strtolower($par), 'ws_', 3) == 0)
113   - return $this->GetDerivedParamInfo(substr($par,3),$comp_start,$comp_stop);
114   - else if (strncmp(strtolower($par), 'wsd_', 4) == 0)
115   - return $this->GetMyDataParamInfo(substr($par,4),$comp_start,$comp_stop);
116   - else if (strncmp(strtolower($par), 'spase_', 6) == 0)
117   - return $this->GetSimuDataParamInfo($par,$comp_start,$comp_stop);
118   -
119   - return $this->GetLocalParamInfo($par,$comp_start,$comp_stop);
120   - }
121   -
122   - /*
123   - * Get a full list of available missions (only missions with the status 'required') that come from Mission.xml file
124   - */
125   - public function GetMissionsList()
126   - {
127   - if (!$this->missionDom)
128   - {
129   - $this->missionDom = new DomDocument("1.0");
130   - if (!$this->missionDom->load(missionXml))
131   - return array('success' => false, 'message' => 'Cannot load missions file');
132   - }
133   -
134   - $missions = $this->missionDom->getElementsByTagName('MissionID');
135   -
136   - $missions_array = array('success' => true);
137   -
138   - foreach ($missions as $mission)
139   - {
140   -// if ($mission->getAttribute('status') != 'required')
141   -// continue;
142   - $id = $mission->nodeValue;
143   - $group = $mission->getAttribute('group');
144   - $missions_array[$id] = array("group" => $group);
145   - }
146   -
147   - return $missions_array;
148   - }
149   -
150   - /*
151   - * Extract sub mission info from a node (DD_*.xml file)
152   - */
153   - private function ExtractDDSubMissionInfoFromNode($node)
154   - {
155   - $name = $node->getAttribute('name');
156   - $desc = $node->getAttribute('desc');
157   - $help = $node->getAttribute('attention');
158   - $class = $node->getAttribute('class');
159   - if ($node->hasAttribute('xml:id')) {
160   - $id = $node->getAttribute('xml:id');
161   - }
162   - else {
163   - $tmp = explode("@",$name);
164   - $id = $tmp[0];
165   - }
166   -
167   - return array(
168   - "name" => $name,
169   - "desc" => $desc,
170   - "help" => $help,
171   - "class" => $class,
172   - "id" => $id
173   - );
174   - }
175   -
176   - /*
177   - * Extract instrument info from a node (DD_*.xml file)
178   - */
179   - private function ExtractDDInstrumentInfoFromNode($node)
180   - {
181   - $name = $node->getAttribute('name');
182   - $desc = $node->getAttribute('desc');
183   - $help = $node->getAttribute('attention');
184   - $id = $node->getAttribute('xml:id');
185   - $refURL = $node->getAttribute('refURL');
186   -
187   - $alternatenode = $node->getElementsByTagName('alternateName');
188   - $alt = array();
189   - foreach ($alternatenode as $a)
190   - array_push($alt,$a->nodeValue);
191   -
192   - $classnode = $node->getElementsByTagName('class');
193   - $class = array();
194   - foreach ($classnode as $c)
195   - array_push($class,$c->nodeValue);
196   -
197   - $pinode = $node->getElementsByTagName('pi');
198   - $pi = ($pinode->length > 0) ? $pinode->item(0)->nodeValue : '';
199   -
200   - return array(
201   - "name" => $name,
202   - "desc" => $desc,
203   - "help" => $help,
204   - "pi" => $pi,
205   - "id" => $id,
206   - "refURL" => $refURL,
207   - "alternamename" => $alt,
208   - "class" => $class
209   - );
210   - }
211   -
212   - /*
213   - * Extract parameter info from a node (DD_*.xml file)
214   - */
215   - private function ExtractDDDatasetInfoFromNode($node)
216   - {
217   - $id = $node->getAttribute('xml:id');
218   - $name = $node->getAttribute('name');
219   - $help = $node->getAttribute('attention');
220   - $sampnode = $node->getElementsByTagName('sampling');
221   - $min_samp = ($sampnode->length > 0) ? $sampnode->item(0)->nodeValue : '0';
222   - $sampnode = $node->getElementsByTagName('maxSampling');
223   - $max_samp = ($sampnode->length > 0) ? $sampnode->item(0)->nodeValue : $min_samp;
224   - $startnode = $node->getElementsByTagName('dataStart');
225   - $start = ($startnode->length > 0) ? $startnode->item(0)->nodeValue : '1970/01/01';
226   - $stopnode = $node->getElementsByTagName('dataStop');
227   - $stop = ($stopnode->length > 0) ? $stopnode->item(0)->nodeValue : '1970/01/01';
228   - $sourcenode = $node->getElementsByTagName('dataSource');
229   - $source = ($sourcenode->length > 0) ? $sourcenode->item(0)->nodeValue : '';
230   -
231   - $infonode = $node->getElementsByTagName('info');
232   - $infonode = ($infonode->length > 0) ? $infonode->item(0) : NULL;
233   -
234   - $title = '';
235   - $des = '';
236   - $creator = '';
237   - $calibration = '';
238   - $subject = array();
239   - $contributor = array();
240   - $target = array();
241   -
242   - if (isset($infonode))
243   - {
244   - $titlenode = $infonode->getElementsByTagName('title');
245   - $title = ($titlenode->length > 0) ? $titlenode->item(0)->nodeValue : '';
246   -
247   - $desnode = $infonode->getElementsByTagName('description');
248   - $des = ($desnode->length > 0) ? $desnode->item(0)->nodeValue : '';
249   -
250   - $creatornode = $infonode->getElementsByTagName('creator');
251   - $creator = ($creatornode->length > 0) ? $creatornode->item(0)->nodeValue : '';
252   -
253   - $calibrationnode = $infonode->getElementsByTagName('calibration');
254   - $calibration = ($calibrationnode->length > 0) ? $calibrationnode->item(0)->nodeValue : '';
255   -
256   - $subjectnode = $infonode->getElementsByTagName('subject');
257   - foreach ($subjectnode as $s)
258   - array_push($subject,$s->nodeValue);
259   -
260   - $contributornode = $infonode->getElementsByTagName('contributor');
261   - foreach ($contributornode as $c)
262   - array_push($contributor,$c->nodeValue);
263   -
264   - $targetnode = $infonode->getElementsByTagName('target');
265   - foreach ($targetnode as $t)
266   - array_push($target,$t->nodeValue);
267   - }
268   -
269   - return array(
270   - "id" => $id,
271   - "name" => $name,
272   - "help" => $help,
273   - "minsampling" => $min_samp,
274   - "maxsampling" => $max_samp,
275   - "starttime" => $start,
276   - "stoptime" => $stop,
277   - "source" => $source,
278   - "title" => $title,
279   - "description" => $des,
280   - "creator" => $creator,
281   - "calibration" => $calibration,
282   - "subject" => $subject,
283   - "contributor" => $contributor,
284   - "target" => $target
285   - );
286   - }
287   -
288   - /*
289   - * Extract parameter info from a node (DD_*.xml file)
290   - */
291   - private function ExtractDDParameterInfoFromNode($node, $comp_start = NULL, $comp_stop = NULL)
292   - {
293   - $units = $node->getAttribute('units');
294   - $display_type = $node->getAttribute('display_type');
295   -
296   - $components = $node->getElementsByTagName('component');
297   -
298   - //additionals info
299   - $infonode = $node->getElementsByTagName('info');
300   - $infonode = ($infonode->length > 0) ? $infonode->item(0) : NULL;
301   -
302   - $des = "";
303   - $ucd = "";
304   - $type = "";
305   -
306   - if (isset($infonode))
307   - {
308   - $desnode = $infonode->getElementsByTagName('description');
309   - $des = ($desnode->length > 0) ? $desnode->item(0)->nodeValue : '';
310   -
311   - $ucdnode = $infonode->getElementsByTagName('ucd');
312   - $ucd = ($ucdnode->length > 0) ? $ucdnode->item(0)->nodeValue : '';
313   -
314   - $typenode = $infonode->getElementsByTagName('type');
315   - $type = ($typenode->length > 0) ? $typenode->item(0)->nodeValue : '';
316   -
317   - }
318   -
319   - //size of the full parameter
320   - if ($node->getAttribute('size') != '')
321   - $fullsize = intval($node->getAttribute('size'));
322   - else
323   - {
324   - if ($components->length > 0)
325   - $fullsize = $components->length;
326   - else
327   - $fullsize = 1;
328   - }
329   -
330   - //get all components labels
331   - $comps_all_labels = array();
332   - if ($fullsize > 1)
333   - {
334   - if (($fullsize != $components->length)&& ($name !=''))
335   - {
336   - for ($i = 0; $i < $fullsize; $i++)
337   - $comps_all_labels[] = $name.'_'.$i;
338   - }
339   - else
340   - {
341   - $i = 0;
342   - foreach ($components as $comp)
343   - {
344   - $comps_all_labels[] = $comp->getAttribute('name');
345   - $i++;
346   - }
347   - }
348   - }
349   -
350   - //real size
351   - if (isset($comp_start))
352   - {
353   - if (isset($comp_stop) && ($comp_start != $comp_stop))
354   - $size = $comp_stop - $comp_start;
355   - else
356   - {
357   - $size = 1;
358   - $comp_stop = $comp_start;
359   - }
360   - }
361   - else
362   - {
363   - $comp_start = 0;
364   - $comp_stop = $fullsize-1;
365   - $size = $fullsize;
366   - }
367   -
368   - if ($size != $fullsize)
369   - {
370   - if ($size == 1)
371   - {
372   - $id = $node->getAttribute('xml:id')."_".$comp_start;
373   - $name = $comps_all_labels[$comp_start];
374   - }
375   - else
376   - {
377   - $id = $node->getAttribute('xml:id')."_".$comp_start."_".$comp_stop;
378   - $name = $node->getAttribute('name')."_".$comp_start."_".$comp_stop;
379   - $comps_label = "";
380   - for ($i = $comp_start; $i <= $comp_stop; $i++)
381   - {
382   - if ($i != $comp_start)
383   - $comps_label .= " ";
384   - $comps_label .= $comps_all_labels[$i];
385   - }
386   - }
387   - }
388   - else
389   - {
390   - $name = $node->getAttribute('name');
391   - $id = $node->getAttribute('xml:id');
392   - $comps_label = "";
393   - for ($i = 0; $i < $size; $i++)
394   - {
395   - if ($i != 0)
396   - $comps_label .= " ";
397   - $comps_label .= $comps_all_labels[$i];
398   - }
399   - }
400   -
401   - return array(
402   - "id" => $id,
403   - "name" => $name,
404   - "units" => $units,
405   - "size" => $size,
406   - "display_type" => $display_type,
407   - "comps_label" => $comps_label,
408   - "description" => $des,
409   - "ucd" => $ucd,
410   - "type" => $type
411   - );
412   - }
413   -
414   -
415   -
416   - /*
417   - * Get the DD_*.xml XPath from a mission id
418   - */
419   - public function GetDDMissionXPath($mission_id)
420   - {
421   - if ($this->ddLocalMissionXPath[$mission_id])
422   - return $this->ddLocalMissionXPath[$mission_id];
423   -
424   - $mission_file = LocalData.'DD_'.$mission_id.'.xml';
425   -
426   - if (!file_exists($mission_file))
427   - return null;
428   -
429   - $ddDom = new DomDocument("1.0");
430   - $ddDom->load($mission_file);
431   -
432   - $this->ddLocalMissionXPath[$mission_id] = new DOMXPath($ddDom);
433   -
434   - return $this->ddLocalMissionXPath[$mission_id];
435   - }
436   -
437   - /*
438   - * Get sub-missions info available in the DD_*.xml file from mission id
439   - * (a DD_*.xml file can contain more than one mission, for example THEMIS-A, THEMIS-B, etc..., this is what we called "sub-mission")
440   - */
441   - public function GetDDMissionInfo($mission_id)
442   - {
443   - $ddPath = $this->GetDDMissionXPath($mission_id);
444   -
445   - if (!$ddPath)
446   - return array('success' => false, 'message' => 'Error to parse DD mission file '.$mission_id);
447   -
448   - $subMiss = $ddPath->query("//mission");
449   -
450   - $sub_array = array();
451   -
452   - foreach($subMiss as $sub)
453   - {
454   - $infos = $this->ExtractDDSubMissionInfoFromNode($sub);
455   - $inst = $this->GetDDInstrumentsInfo($mission_id, $infos['name']);
456   -
457   - $sub_array[$infos['name']] = array(
458   - "desc" => $infos['desc'],
459   - "help" => $infos['help'],
460   - "class" => $infos['class'],
461   - "instruments" => $inst);
462   - }
463   -
464   - return $sub_array;
465   - }
466   -
467   - /*
468   - * Get instruments info available in the DD_*.xml file from mission id and sub mission name
469   - */
470   - public function GetDDInstrumentsInfo($mission_id, $sub_name)
471   - {
472   - $ddPath = $this->GetDDMissionXPath($mission_id);
473   -
474   - if (!$ddPath)
475   - return array('success' => false, 'message' => 'Error to parse DD mission file '.$mission_id);
476   -
477   - $instruments = $ddPath->query("//mission[@name='".$sub_name."']/instrument");
478   -
479   - $inst_array = array();
480   -
481   - foreach($instruments as $inst)
482   - {
483   - $infos = $this->ExtractDDInstrumentInfoFromNode($inst);
484   - $datasets = $this->GetDDDatasetsInfo($mission_id, $sub_name, $infos["name"]);
485   -
486   - $inst_array[$infos['name']] = array(
487   - "desc" => $infos['desc'],
488   - "help" => $infos['help'],
489   - "pi" => $infos['pi'],
490   - "id" => $infos['id'],
491   - "refURL" => $infos['refURL'],
492   - "alternamename" => $infos['alternamename'],
493   - "class" => $infos['class'],
494   - "datasets" => $datasets);
495   - }
496   -
497   - return $inst_array;
498   - }
499   -
500   - /*
501   - * Get datasets info available in the DD_*.xml file from mission id, sub mission name and instrument name
502   - */
503   - private function GetDDDatasetsInfo($mission_id, $sub_name, $inst_name)
504   - {
505   - $ddPath = $this->GetDDMissionXPath($mission_id);
506   -
507   - if (!$ddPath)
508   - return array('success' => false, 'message' => 'Error to parse DD mission file '.$mission_id);
509   -
510   - $datasets = $ddPath->query("//mission[@name='".$sub_name."']//instrument[@name='".$inst_name."']//dataset");
511   -
512   - $datas_array = array();
513   -
514   - foreach ($datasets as $data)
515   - {
516   - $infos = $this->ExtractDDDatasetInfoFromNode($data);
517   - $params = $this->GetDDParametersInfo($mission_id, $sub_name, $inst_name, $infos['id']);
518   -
519   - $datas_array[$infos['id']] = array(
520   - "name" => $infos['name'],
521   - "help" => $infos['help'],
522   - "minsampling" => $infos['minsampling'],
523   - "maxsampling" => $infos['maxsampling'],
524   - "starttime" => $infos['starttime'],
525   - "stoptime" => $infos['stoptime'],
526   - "source" => $infos['source'],
527   - "title" => $infos['title'],
528   - "description" => $infos['description'],
529   - "creator" => $infos['creator'],
530   - "calibration" => $infos['calibration'],
531   - "subject" => $infos['subject'],
532   - "contributor" => $infos['contributor'],
533   - "target" => $infos['target'],
534   - "parameters" => $params
535   - );
536   - }
537   -
538   - return $datas_array;
539   - }
540   -
541   - /*
542   - * Get parameters info available in the DD_*.xml file from mission id, sub mission name, instrument name and dataset id
543   - */
544   - public function GetDDParametersInfo($mission_id, $sub_name, $inst_name, $data_id)
545   - {
546   - $ddPath = $this->GetDDMissionXPath($mission_id);
547   -
548   - if (!$ddPath)
549   - return array('success' => false, 'message' => 'Error to parse DD mission file '.$mission_id);
550   -
551   - $parameters = $ddPath->query("//mission[@name='".$sub_name."']//instrument[@name='".$inst_name."']//dataset[@xml:id='".$data_id."']/parameter");
552   -
553   - $params_array = array();
554   -
555   - foreach ($parameters as $param)
556   - {
557   - $infos = $this->ExtractDDParameterInfoFromNode($param);
558   -
559   - $params_array[$infos['id']] = array(
560   - "name" => $infos["name"],
561   - "units" => $infos["units"],
562   - "size" => $infos["size"],
563   - "display_type" => $infos["display_type"],
564   - "comps_label" => $infos["comps_label"],
565   - "description" => $infos["description"],
566   - "ucd" => $infos["ucd"],
567   - "type" => $infos["type"]
568   - );
569   - }
570   -
571   - return $params_array;
572   - }
573   -
574   - /*
575   - * Get all DD_*.xml info from parameter id
576   - */
577   - public function GetDDInfoFromParameterID($param_id, $comp_start = NULL, $comp_stop = NULL)
578   - {
579   - $missions = $this->GetMissionsList();
580   -
581   - foreach ($missions as $mission_id => $mission_val)
582   - {
583   - $ddPath = $this->GetDDMissionXPath($mission_id);
584   -
585   - if (!$ddPath)
586   - continue;
587   -
588   - $parameters = $ddPath->query("//instrument//dataset/parameter[@xml:id='".$param_id."']");
589   -
590   - if ($parameters->length < 1)
591   - continue;
592   -
593   -
594   - $parameter_node = $parameters->item(0);
595   -
596   - //parameter info
597   - $param_infos = $this->ExtractDDParameterInfoFromNode($parameter_node, $comp_start, $comp_stop);
598   -
599   - //dataset info
600   - $dataset_node = $parameter_node->parentNode;
601   - $dataset_infos = $this->ExtractDDDatasetInfoFromNode($dataset_node);
602   -
603   - //instrument info
604   - $instrument_node = $dataset_node->parentNode->nodeName == 'instrument' ? $dataset_node->parentNode : $dataset_node->parentNode->parentNode;
605   - $instrument_infos = $this->ExtractDDInstrumentInfoFromNode($instrument_node);
606   -
607   - //sub mission info
608   - $tmp = $instrument_node->parentNode;
609   -
610   - if ($tmp->nodeName == "group" ) $submission_node = $tmp->parentNode;
611   - else $submission_node = $tmp;
612   - $submission_infos = $this->ExtractDDSubMissionInfoFromNode($submission_node);
613   -
614   - return array(
615   - 'success' => true,
616   - 'parameter' => $param_infos,
617   - 'dataset' => $dataset_infos,
618   - 'instrument' => $instrument_infos,
619   - 'submission' => $submission_infos,
620   - 'mission_id' => $mission_id
621   - );
622   - }
623   -
624   - return array('success' => false,
625   - 'message' => 'No such param '.$param_id);
626   - }
627   -
628   - /*
629   - * Get dataset info
630   - */
631   - public function GetDDInfoFromDatasetID($datasetId)
632   - {
633   - $missions = $this->GetMissionsList();
634   -
635   - foreach ($missions as $mission_id => $mission_val)
636   - {
637   - $ddPath = $this->GetDDMissionXPath($mission_id);
638   -
639   - if (!$ddPath)
640   - continue;
641   -
642   - $datasets = $ddPath->query("//instrument/dataset[@xml:id='".$datasetId."']");
643   -
644   - if ($datasets->length < 1)
645   - continue;
646   -
647   - $dataset_node = $datasets->item(0);
648   - $dataset_infos = $this->ExtractDDDatasetInfoFromNode($dataset_node);
649   -
650   - //instrument info
651   - $instrument_node = $dataset_node->parentNode;
652   - $instrument_infos = $this->ExtractDDInstrumentInfoFromNode($instrument_node);
653   -
654   - //sub mission info
655   - $submission_node = $instrument_node->parentNode;
656   - $submission_infos = $this->ExtractDDSubMissionInfoFromNode($submission_node);
657   -
658   - //parameters info
659   - $param_infos = $this->GetDDParametersInfo($mission_id, $submission_infos['name'], $instrument_infos['name'], $datasetId);
660   -
661   - return array(
662   - 'success' => true,
663   - 'parameter' => $param_infos,
664   - 'dataset' => $dataset_infos,
665   - 'instrument' => $instrument_infos,
666   - 'submission' => $submission_infos,
667   - 'mission_id' => $mission_id
668   - );
669   - }
670   -
671   - return array('success' => false,
672   - 'message' => 'No such dataset '.$datasetId);
673   - }
674   -
675   - public function ExtractLocalParamsInfoFromNode($theParam)
676   - {
677   - $name = $theParam->getAttribute("name");
678   - $vi = $theParam->getAttribute("vi");
679   - $size = $theParam->getElementsByTagName("SIZES")->item(0)->nodeValue;
680   - $tensor = $theParam->getElementsByTagName("TENSOR_ORDER_VALUE")->item(0)->nodeValue;
681   - $value_type = $theParam->getElementsByTagName("VALUE_TYPE")->item(0)->nodeValue;
682   - $fillNodes = $theParam->getElementsByTagName("FILLVAL");
683   - if ($fillNodes->length > 0)
684   - $fill_value = $fillNodes->item(0)->nodeValue;
685   - else
686   - $fill_value = "NaN";
687   - //if ($fill_value == "NaN") $fill_value = "!Values.F_NAN";
688   - $units = $theParam->getElementsByTagName("UNITS")->item(0)->nodeValue;
689   - $sampling = $theParam->getElementsByTagName("TIME_RESOLUTION")->item(0)->nodeValue;
690   - $maxSamplingNode = $theParam->getElementsByTagName("MAX_TIME_RESOLUTION");
691   - if ($maxSamplingNode->length > 0) $maxSampling = $maxSamplingNode->item(0)->nodeValue;
692   - else $maxSampling = $sampling;
693   - $frame = $theParam->getElementsByTagName("COORDINATE_SYSTEM")->item(0)->nodeValue;
694   - $legend = $theParam->getElementsByTagName("LABEL_I")->item(0)->nodeValue;
695   - $title = $theParam->getElementsByTagName("YTITLE")->item(0)->nodeValue;
696   - $plottype = $theParam->getElementsByTagName("DISPLAY_TYPE")->item(0)->nodeValue;
697   - // if ($plottype == "TICK_MARKS") //BRE - why put mission name in DISPLAY_TYPE tag? (for the moment, keep for compatibility)
698   - // $mission = $theParam->getElementsByTagName("DISPLAY_TYPE")->item(0)->getAttribute("name");
699   - // else
700   - // $mission = "n/a";
701   - $energychannel = $theParam->getAttribute("energy");
702   - if ($energychannel == '')
703   - $energychannel = 'Energy';
704   -
705   - $validMinNode = $theParam->getElementsByTagName("VALID_MIN");
706   - if ($validMinNode->length > 0) $validmin = $validMinNode->item(0)->nodeValue;
707   - else $validmin = 'unknown';
708   -
709   - $conversionNode = $theParam->getElementsByTagName("UNITS_CONVERSION");
710   - if ($conversionNode->length > 0) {
711   - $infoProvider = new InfoProvider();
712   - $conversion = $infoProvider->getConversion($conversionNode->item(0)->nodeValue);
713   - }
714   - else $conversion = '-1';
715   -
716   -
717   - $processNode = $theParam->getElementsByTagName("PROCESS");
718   - if ($processNode->length > 0) $process = $processNode->item(0)->nodeValue;
719   - else $process = '';
720   -
721   - //$ytitle = $units != NULL ? $title.",!C".$units : $title;
722   -
723   - return array(
724   - 'name' => $name,
725   - 'vi' => $vi,
726   - 'size' => $size,
727   - 'tensor' => $tensor,
728   - 'valuetype' => $value_type,
729   - 'fillvalue' => $fill_value,
730   - 'units' => $units,
731   - 'minsampling' => $sampling,
732   - 'maxsampling' => $maxSampling,
733   - 'frame' => $frame,
734   - 'legend' => $legend,
735   - 'title' => $title,
736   - 'plottype' => $plottype,
737   - // 'mission' => $mission, //BRE - why put mission name in DISPLAY_TYPE tag? (for the moment, keep for compatibility)
738   - 'conversion' => $conversion,
739   - 'validmin' => $validmin,
740   - 'process' => $process,
741   - 'energychannel' => $energychannel
742   - );
743   - }
744   -
745   - public function GetLocalParamInfo($param, $comp_start = NULL, $comp_stop = NULL)
746   - {
747   -
748   - if (!$this->localDom)
749   - {
750   - $this->localDom = new DomDocument("1.0");
751   - if (!$this->localDom->load(paramXml))
752   - return array('success' => false, 'id' => $param, 'message' => 'Cannot load local param file');
753   - }
754   -
755   - $theParam = $this->localDom->getElementById($param);
756   -
757   - $comp_array = array();
758   -
759   - if (isset($comp_start) && isset($comp_stop) && ($comp_start != $comp_stop))
760   - $par_id = $param."(".$comp_start.":".$comp_stop.")";
761   - else if (isset($comp_start))
762   - $par_id = $param."(".$comp_start.")";
763   - else
764   - $par_id = $param;
765   -
766   - if (!$theParam)
767   - $ddinfos = $this->GetDDInfoFromParameterID($par_id);
768   - else {
769   - $ddinfos = $this->GetDDInfoFromParameterID($param, $comp_start, $comp_stop);
770   - $isInternal = $theParam->hasAttribute('internal');
771   - }
772   -
773   - if (!$ddinfos['success'] && !$isInternal)
774   - return array('success' => false, 'id' => $param, 'message' => $ddinfos['message']);
775   -
776   - if (!$theParam)
777   - return array('success' => true,
778   - 'id' => $par_id,
779   - 'type' => 'local',
780   - 'withcode' => true,
781   - 'ddinfos' => $ddinfos);
782   -
783   -
784   - $codeinfos = $this->ExtractLocalParamsInfoFromNode($theParam);
785   -
786   - return array('success' => true,
787   - 'id' => $par_id,
788   - 'type' => 'local',
789   - 'withcode' => false,
790   - 'ddinfos' => $ddinfos,
791   - 'codeinfos' => $codeinfos);
792   - }
793   -
794   - protected function GetDerivedParamInfo($param, $comp_start = NULL, $comp_stop = NULL)
795   - {
796   - if (!$this->derivedParamMgr)
797   - $this->derivedParamMgr = new DerivedParamMgr('derivedParam');
798   -
799   - $obj = $this->derivedParamMgr->getObjectByName($param);
800   -
801   - if ($obj['error'])
802   - return array('success' => false, 'id' => $param, 'message' => $obj['error']);
803   -
804   - return array(
805   - 'success' => true,
806   - 'id' => $param,
807   - 'type' => 'derived',
808   - 'infos' => $obj
809   - );
810   - }
811   -
812   - protected function GetMyDataParamInfo($param, $comp_start = NULL, $comp_stop = NULL)
813   - {
814   - if (!$this->mydataParamMgr)
815   - $this->mydataParamMgr = new DerivedParamMgr();
816   -
817   - $obj = $this->mydataParamMgr->getObjectByName($param);
818   -
819   - if ($obj['error'])
820   - return array('success' => false, 'id' => $param, 'message' => $obj['error']);
821   -
822   - return array(
823   - 'success' => true,
824   - 'id' => $param,
825   - 'type' => 'mydata',
826   - 'infos' => $obj
827   - );
828   - }
829   -
830   - protected function GetSimuDataParamInfo($param, $comp_start = NULL, $comp_stop = NULL)
831   - {
832   - if (!$this->mySimuParamMgr)
833   - $this->mySimuParamMgr = new DerivedParamMgr('mySimuParam');
834   -
835   - $obj = $this->mySimuParamMgr->getObjectByName($param);
836   -
837   - if ($obj['error'])
838   - return array('success' => false, 'id' => $param, 'message' => $obj['error']);
839   -
840   - return array(
841   - 'success' => true,
842   - 'id' => $param,
843   - 'type' => 'mydata',
844   - 'infos' => $obj
845   - );
846   - }
847   - public function GetInternalParamInfo($param) {
848   - if (!$this->internalDom)
849   - {
850   - $this->internalDom = new DomDocument("1.0");
851   - if (!$this->internalDom->load(internalParams))
852   - return array('success' => false, 'id' => $param, 'message' => 'Cannot load local internal params file');
853   - }
854   -
855   - $theParam = $this->internalDom->getElementById($param);
856   -
857   - $parentDataset = $theParam->parentNode;
858   - $parentInstrument = $parentDataset->parentNode;
859   - $parentMission = $parentInstrument->parentNode;
860   - $missionName = isset($parentMission) ? $parentMission->getAttribute('name') : 'undefined';
861   -
862   - return array(
863   - 'success' => true,
864   - 'id' => $param,
865   - 'mission' => $missionName,
866   - 'instrument' => array('id' =>$parentInstrument->getAttribute('xml:id'),
867   - 'name' =>$parentInstrument->getAttribute('name'),
868   - 'desc' =>$parentInstrument->getAttribute('desc')),
869   - 'dataset' => array('id' =>$parentDataset->getAttribute('xml:id'),
870   - 'name' =>$parentDataset->getAttribute('name'),
871   - 'sampling' =>$parentDataset->getElementsByTagName('sampling')->item(0)->nodeValue,
872   - 'dataStart'=>$parentDataset->getElementsByTagName('dataStart')->item(0)->nodeValue,
873   - 'dataStop' =>$parentDataset->getElementsByTagName('dataStop')->item(0)->nodeValue)
874   - );
875   -
876   - }
877   -
878   - public function ParamInfosToString($infos)
879   - {
880   - $str = $infos['id'];
881   -
882   - if (!$infos['success'])
883   - return $str." - ".$infos['message'];
884   -
885   - switch($infos['type'])
886   - {
887   - case 'local' :
888   - $str .= (" - Type : Local Parameter @ CDPP/AMDA");
889   - if ($infos['ddinfos']['parameter']['name'] != '')
890   - $str .= (" - Name : ".$infos['ddinfos']['parameter']['name']);
891   - else
892   - $str .= (" - Name : ".$infos['codeinfos']['title']);
893   -
894   - if ($infos['ddinfos']['parameter']['units'] != '')
895   - $str .= (" - Units : ".$infos['ddinfos']['parameter']['units']);
896   - else
897   - $str .= (" - Units : ".$infos['codeinfos']['units']);
898   -
899   - if ($infos['ddinfos']['parameter']['size'] != '')
900   - $str .= (" - Size : ".$infos['ddinfos']['parameter']['size']);
901   - else
902   - $str .= (" - Size : ".$infos['codeinfos']['size']);
903   -
904   - if (!$infos['withcode'])
905   - if ($infos['codeinfos']['frame'] != '')
906   - $str .= (" - Frame : ".$infos['codeinfos']['frame']);
907   - if ($infos['ddinfos']['submission']['name'] != '')
908   - $str .= (" - Mission : ".$infos['ddinfos']['submission']['name']);
909   - else
910   - $str .= (" - Mission : ".$infos['codeinfos']['name']);
911   -
912   - $str .= (" - Instrument : ".$infos['ddinfos']['instrument']['name']);
913   - if ($infos['ddinfos']['dataset']['name'] != '')
914   - $str .= (" - Dataset : ".$infos['ddinfos']['dataset']['name']);
915   - else
916   - $str .= (" - Dataset : ".$infos['codeinfos']['plottype']);
917   -
918   - break;
919   - case 'derived' :
920   - $str .= (" - Type : Derived Parameter @ CDPP/AMDA");
921   - $str .= (" - Name : ".$infos['infos']['name']);
922   - $str .= (" - Units : ".$infos['infos']['units']);
923   - $str .= (" - Build chain : ".htmlentities($infos['infos']['buildchain']));
924   - $str .= (" - Time Step : ".$infos['infos']['timestep']);
925   - break;
926   - case 'mydata' :
927   - $str .= (" - Type : My Data Parameter @ CDPP/AMDA");
928   - $str .= (" - Name : ".$infos['infos']['name']);
929   - $str .= (" - Units : ".$infos['infos']['units']);
930   - $str .= (" - Size : ".$infos['infos']['size']);
931   - $str .= (" - From : ".$infos['infos']['file']);
932   - break;
933   - default :
934   - return $str." - Unknown parameter type (maybe not yet implemented?)";
935   - }
936   -
937   - return $str;
938   - }
939   -
940   -
941   - function forEachAllDDParameters($callback_func)
942   - {
943   - $missions = $this->GetMissionsList();
944   - foreach ($missions as $mis_key => $mis_val)
945   - {
946   - if ($mis_key == 'success')
947   - continue;
948   - $subs = $this->GetDDMissionInfo($mis_key);
949   - foreach ($subs as $sub_key => $sub_val)
950   - foreach($sub_val['instruments'] as $inst_key => $inst_val)
951   - foreach ($inst_val["datasets"] as $data_key => $data_val)
952   - foreach ($data_val["parameters"] as $param_key => $param_val)
953   - call_user_func($callback_func, array("mission" => array("id" => $mis_key, "infos" => $mis_val),
954   - "submission" => array("name" => $sub_key, "infos" => $sub_val),
955   - "instrument" => array("name" => $inst_key, "infos" => $inst_val),
956   - "dataset" => array("id" => $data_key, "infos" => $data_val),
957   - "parameter" => array("id" => $param_key, "infos" => $param_val)));
958   - }
959   - }
960   -
961   - function forEachAllDDDatasets($callback_func)
962   - {
963   - $missions = $this->GetMissionsList();
964   - foreach ($missions as $mis_key => $mis_val)
965   - {
966   - if ($mis_key == 'success')
967   - continue;
968   - $subs = $this->GetDDMissionInfo($mis_key);
969   - foreach ($subs as $sub_key => $sub_val)
970   - foreach($sub_val['instruments'] as $inst_key => $inst_val)
971   - foreach ($inst_val["datasets"] as $data_key => $data_val)
972   - call_user_func($callback_func, array("mission" => array("id" => $mis_key, "infos" => $mis_val),
973   - "submission" => array("name" => $sub_key, "infos" => $sub_val),
974   - "instrument" => array("name" => $inst_key, "infos" => $inst_val),
975   - "dataset" => array("id" => $data_key, "infos" => $data_val)));
976   - }
977   - }
978   - }
979   -
980   -?>