Commit 96fa912db33d9481600fa16877252e6f9cf30717
1 parent
e925e409
Exists in
master
and in
46 other branches
ihm level instead of values
Showing
1 changed file
with
827 additions
and
841 deletions
Show diff stats
src/InputOutput/IHMImpl/Tools/IHMParamManagerClass.php
... | ... | @@ -5,846 +5,832 @@ |
5 | 5 | * @brief Parameter manager |
6 | 6 | * @details |
7 | 7 | */ |
8 | -class IHMParamManagerClass | |
9 | -{ | |
10 | - protected $userParameterMgr = null; | |
11 | - protected $templateParamsManager = null; | |
12 | - protected $paramImpexMgr = null; | |
13 | - protected $ttCatMgr = null; | |
14 | - | |
15 | - protected $cacheExpressionParser = null; | |
16 | - | |
17 | - /* | |
18 | - * @brief Constructor | |
19 | - */ | |
20 | - function __construct() | |
21 | - { | |
22 | - $this->templateParamsManager = new IHMParamTemplateClass(); | |
23 | - $this->cacheExpressionParser = array(); | |
24 | - } | |
25 | - | |
26 | - public function addGeneratedParam($paramId, $expression, $sampling_mode, $sampling_step, $ref_param, $paramsData) | |
27 | - { | |
28 | - $expressionInfo = $this->parseExpression($expression, $paramsData->getWorkingPath()); | |
29 | - if (!$expressionInfo['success']) { | |
30 | - throw new Exception($expressionInfo['message']); | |
31 | - } | |
32 | - | |
33 | - //create a process param for the derived parameter | |
34 | - $this->addProcessParam($paramId, $expressionInfo["expression"], $expression, | |
35 | - $expressionInfo['params'], $sampling_mode, $sampling_step, $ref_param, | |
36 | - 0, time(), "", "", $paramsData); | |
37 | - } | |
38 | - | |
39 | - /* | |
40 | - * @brief Add an existing parameter | |
41 | - */ | |
42 | - public function addExistingParam($param, $paramsData, $templateArgs = NULL, $tableLink = NULL) | |
43 | - { | |
44 | - if ($this->isDerivedParam($param)) | |
45 | - return $this->addDerivedParam($param,$paramsData); | |
46 | - else if ($this->isUploadedParam($param)) | |
47 | - return $this->addUploadedParam($param,$paramsData); | |
48 | - else if ($this->isImpexParam($param)) | |
49 | - return $this->addImpexParam($param,$paramsData,$templateArgs); | |
50 | - else | |
51 | - return $this->addLocalParam($param,$paramsData,$templateArgs, $tableLink); | |
52 | - return ""; | |
53 | - } | |
54 | - | |
55 | - /* | |
56 | - * @brief Add a process parameter | |
57 | - */ | |
58 | - public function addProcessParam($paramId,$expression,$expression_info,$params, $sampling_mode, $sampling_step, $ref_param, $gap,$dateModif,$units,$ytitle,$paramsData) | |
59 | - { | |
60 | - $paramsData->addProcessParamToCreate($paramId, $expression, $expression_info, $params, $sampling_mode, $sampling_step, $ref_param, $gap,$dateModif, $units, $ytitle); | |
61 | - | |
62 | - foreach ($params as $param) { | |
63 | - $template_args = NULL; | |
64 | - | |
65 | - if (array_key_exists("template_args", $param)) | |
66 | - $template_args = $param["template_args"]; | |
67 | - | |
68 | - $this->addExistingParam($param["paramid"],$paramsData,$template_args); | |
69 | - } | |
70 | - if (!empty($ref_param)) { | |
71 | - $this->addExistingParam($ref_param, $paramsData,$template_args); | |
72 | - } | |
73 | - | |
74 | - return true; | |
75 | - } | |
76 | - | |
77 | - /* | |
78 | - * @brief Add a TT or catalog parameter | |
79 | - */ | |
80 | - public function addTTCatParam($paramId, $paramsData) | |
81 | - { | |
82 | - if (!isset($this->ttCatMgr)) { | |
83 | - $this->ttCatMgr = new IHMTTCatLoaderClass(); | |
84 | - } | |
85 | - $info = $this->ttCatMgr->getTTCatInfoFromId($paramId); | |
86 | - | |
87 | - if (!$info["success"]) { | |
88 | - throw new Exception($info["message"]); | |
89 | - } | |
90 | - | |
91 | - $status = array(); | |
92 | - $units = ""; | |
93 | - $ytitle = ""; | |
94 | - $flag = ""; | |
95 | - | |
96 | - if ($info["info"]["isCatalog"]) { | |
97 | - $parameters = $this->ttCatMgr->getCatalogParameters($paramId); | |
98 | - if (!$parameters["success"] || empty($parameters["parameters"])) { | |
99 | - throw new Exception("Error to extract first parameter of ".$paramId); | |
100 | - } | |
101 | - //For the moment, use the first parameter | |
102 | - $parameter = $parameters["parameters"][0]; | |
103 | - $units = $parameter["units"]; | |
104 | - $ytitle = !empty($parameter["name"]) ? $parameter["name"] : $parameter["id"]; | |
105 | - $flag = $parameter["id"]; | |
106 | - $description = $parameter["description"]; | |
107 | - $desc_parts = array(); | |
108 | - foreach (explode("-",$description) as $def) { | |
109 | - $def = trim($def); | |
110 | - $p = strpos($def, ":"); | |
111 | - if ($p === FALSE) { | |
112 | - continue; | |
113 | - } | |
114 | - $val = substr($def, 0, $p); | |
115 | - $val = trim($val); | |
116 | - $name = substr($def, $p+1); | |
117 | - $name = trim($name); | |
118 | - $color = ""; | |
119 | - $p = strpos($name, "["); | |
120 | - if ($p !== FALSE) { | |
121 | - $color = substr($name, $p); | |
122 | - $color = trim($color); | |
123 | - $name = substr($name, 0, $p); | |
124 | - $name = trim($name); | |
125 | - } | |
126 | - $status[] = array( | |
127 | - "min" => floatval($val), | |
128 | - "max" => floatval($val), | |
129 | - "name" => $name, | |
130 | - "color" => $color, | |
131 | - ); | |
132 | - } | |
133 | - } | |
134 | - else { | |
135 | - $status = array( | |
136 | - array( | |
137 | - "min" => 1, | |
138 | - "max" => 1, | |
139 | - "name" => "Inside", | |
140 | - "color" => "[255,0,0]", | |
141 | - ) | |
142 | - ); | |
143 | - $ytitle = $info["info"]["name"]; | |
144 | - } | |
145 | - | |
146 | - $paramsData->addTTCatParamToCreate($paramId, $info["info"]["path"], $info["info"]["isShared"], filemtime($info["info"]["path"]), $units, $ytitle, $status, $flag); | |
147 | - return array("id" => $paramId, "indexes" => array(), "calib_infos" => array()); | |
148 | - } | |
149 | - | |
150 | - /* | |
151 | - * @brief Detect if it's a derived parameter | |
152 | - */ | |
153 | - private function isDerivedParam($param) | |
154 | - { | |
155 | - return preg_match("#^ws_#",$param); | |
156 | - } | |
157 | - | |
158 | - /* | |
159 | - * @brief Detect if it's a uploaded parameter | |
160 | - */ | |
161 | - public function isUploadedParam($param) | |
162 | - { | |
163 | - return preg_match("#^wsd_#",$param); | |
164 | - } | |
165 | - | |
166 | - /* | |
167 | - * @brief Detect if it's IMPEX parameter | |
168 | - */ | |
169 | - private function isImpexParam($param) | |
170 | - { | |
171 | - return preg_match("#^".IHMImpexParamClass::$paramPrefix."#",$param); | |
172 | - } | |
173 | - | |
174 | - /* | |
175 | - * @brief Add a local parameter | |
176 | - */ | |
177 | - private function addLocalParam($param, $paramsData, $templateArgs, $tableLink) | |
178 | - { | |
179 | - //local parameter | |
180 | - $indexes = array(); | |
181 | - $calib_infos = array(); | |
182 | - //check for components | |
183 | - $pattern = "/(?P<param>.*)\((?P<components>.*)\)/"; | |
184 | - preg_match_all($pattern, $param, $matches); | |
185 | - if ((count($matches["param"]) > 0) && (count($matches["components"]) > 0)) | |
186 | - { | |
187 | - $paramId = $matches["param"][0]; | |
188 | - $indexes = explode(",",$matches["components"][0]); | |
189 | - } | |
190 | - else | |
191 | - $paramId = $param; | |
192 | - | |
193 | - //check templated parameter | |
194 | - $real_param_id = $paramId; | |
195 | - $paramPath = ""; | |
196 | - if ($this->templateParamsManager->isTemplatedParam($paramId)) { | |
197 | - $paramPath = $this->templateParamsManager->generateTemplatedParamFile($paramId, $templateArgs, $tableLink); | |
198 | - $real_param_id = $this->templateParamsManager->getTemplatedParamId($paramId, $templateArgs); | |
199 | - if (empty($paramPath) || !file_exists($paramPath)) | |
200 | - throw new Exception('Cannot generate parameter template file '.$paramId); | |
201 | - } | |
202 | - else { | |
203 | - $paramPath = IHMConfigClass::getLocalParamDBPath().$paramId.".xml"; | |
204 | - if (!file_exists($paramPath)) | |
205 | - throw new Exception('Cannot find parameter local file '.$paramId); | |
206 | - } | |
207 | - | |
208 | - $paramsData->addParamToCopy($real_param_id,$paramPath); | |
209 | - | |
210 | - $this->addLinkedLocalParams($paramId, $paramsData, $templateArgs); | |
211 | - | |
212 | - return array("id" => $real_param_id, "indexes" => $indexes, "calib_infos" => $calib_infos, "path" => $paramPath); | |
213 | - } | |
214 | - | |
215 | - /* | |
216 | - * @brief Add linked parameter | |
217 | - */ | |
218 | - private function addLinkedLocalParams($paramId,$paramsData,$templateArgs = NULL) | |
219 | - { | |
220 | - $doc = new DOMDocument("1.0", "UTF-8"); | |
221 | - $doc->preserveWhiteSpace = false; | |
222 | - $doc->formatOutput = true; | |
223 | - | |
224 | - $real_param_id = $paramId; | |
225 | - if ($this->templateParamsManager->isTemplatedParam($paramId)) { | |
226 | - $paramPath = $this->templateParamsManager->getTemplatePath($paramId); | |
227 | - if (empty($paramPath) || !@$doc->load($paramPath)) | |
228 | - throw new Exception('Cannot find parameter template file '.$paramId); | |
229 | - } | |
230 | - else { | |
231 | - $paramPath = IHMConfigClass::getLocalParamDBPath().$paramId.".xml"; | |
232 | - if (empty($paramPath) || !@$doc->load($paramPath)) | |
233 | - throw new Exception('Cannot find parameter local file '.$paramId); | |
234 | - } | |
235 | - | |
236 | - //<get> | |
237 | - $getNodes = $doc->getElementsByTagName('get'); | |
238 | - | |
239 | - if ($getNodes->length <= 0) | |
240 | - throw new Exception('Parameter local file '.$paramId.' dont have a getter node'); | |
241 | - | |
242 | - $getNode = $getNodes->item(0); | |
243 | - | |
244 | - //<amdaParam name="imf"/> | |
245 | - $amdaParamNodes = $doc->getElementsByTagName('amdaParam'); | |
246 | - | |
247 | - foreach($amdaParamNodes as $amdaParamNode) | |
248 | - { | |
249 | - $linkedParamId = $amdaParamNode->getAttribute('name'); | |
250 | - if (empty($linkedParamId)) | |
251 | - continue; | |
252 | - $template_id = $this->templateParamsManager->getTemplateId($linkedParamId); | |
253 | - $tempArgs = isset($templateArgs) ? $templateArgs : array(); | |
254 | - if ($template_id !== FALSE) { | |
255 | - $linkedParamId = $template_id; | |
256 | - } | |
257 | - else { | |
258 | - $linkedParamId = $this->templateParamsManager->replaceArgs($linkedParamId, $templateArgs); | |
259 | - $parsedParam = $this->templateParamsManager->parseTemplatedParam($linkedParamId); | |
260 | - if ($parsedParam !== FALSE) { | |
261 | - $linkedParamId = $parsedParam['paramid']; | |
262 | - foreach ($parsedParam['template_args'] as $key => $val) { | |
263 | - $tempArgs[$key] = $val; | |
264 | - } | |
265 | - } | |
266 | - } | |
267 | - | |
268 | - if ($this->templateParamsManager->isTemplatedParam($linkedParamId)) { | |
269 | - $linkedParamPath = $this->templateParamsManager->generateTemplatedParamFile($linkedParamId, $tempArgs); | |
270 | - $real_linked_param_id = $this->templateParamsManager->getTemplatedParamId($linkedParamId, $tempArgs); | |
271 | - } | |
272 | - else { | |
273 | - $real_linked_param_id = $linkedParamId; | |
274 | - $linkedParamPath = IHMConfigClass::getLocalParamDBPath().$real_linked_param_id.".xml"; | |
275 | - } | |
276 | - $paramsData->addParamToCopy($real_linked_param_id,$linkedParamPath); | |
277 | - $this->addLinkedLocalParams($linkedParamId, $paramsData); | |
278 | - } | |
279 | - } | |
280 | - | |
281 | - /* | |
282 | - * @brief Add derived parameter | |
283 | - */ | |
284 | - private function addDerivedParam($param,$paramsData) | |
285 | - { | |
286 | - $time = time(); | |
287 | - if (!isset($this->userParameterMgr)) | |
288 | - $this->userParameterMgr = new IHMUserParamManagerClass(); | |
289 | - | |
290 | - //get derived parameter info | |
291 | - $res = $this->userParameterMgr->getDerivedParameterFromName($param); | |
292 | - | |
293 | - if (!$res["success"]) | |
294 | - throw new Exception('Error to load derived parameter file : '.$res["message"]); | |
295 | - | |
296 | - if (isset($res["param"]["info"]["parsedExpression"])) { | |
297 | - //Re use existing parsed expression info | |
298 | - $expressionInfo = $res["param"]["info"]["parsedExpression"]; | |
299 | - } | |
300 | - else { | |
301 | - //parse expression | |
302 | - $expressionInfo = $this->parseExpression($res["param"]["expression"], $paramsData->getWorkingPath()); | |
303 | - | |
304 | - if (!$expressionInfo['success']) { | |
305 | - throw new Exception($expressionInfo['message']); | |
306 | - } | |
307 | - | |
308 | - $paramsList = array(); | |
309 | - foreach ($expressionInfo['params'] as $p) { | |
310 | - $paramsList[] = $p["paramid"]; | |
311 | - } | |
312 | - $this->userParameterMgr->saveDerivedParameterParsedExpression($res["param"]["id"], $expressionInfo["expression"], md5($res["param"]["expression"]), $paramsList); | |
313 | - } | |
314 | - | |
315 | - $paramId = $param; | |
316 | - | |
317 | - //create a process param for the derived parameter | |
318 | - $this->addProcessParam($paramId, $expressionInfo["expression"], $res["param"]["expression"], | |
319 | - $expressionInfo['params'], $res["param"]["info"]["sampling_mode"], $res["param"]["info"]["timestep"], $res["param"]["info"]["reference_param"], | |
320 | - 0,$res["param"]["dateModif"],!empty($res["param"]["info"]["units"]) ? $res["param"]["info"]["units"] : "", | |
321 | - !empty($res["param"]["info"]["yTitle"]) ? $res["param"]["info"]["yTitle"] : "", $paramsData); | |
322 | - | |
323 | - return array("id" => $paramId, "indexes" => array(), "calib_infos" => array()); | |
324 | - } | |
325 | - | |
326 | - /* | |
327 | - * @brief Add IMPEX parameter : create dynamically xml parameter descriptor in user WS | |
328 | - */ | |
329 | - private function addImpexParam($param,$paramsData,$templateArgs = NULL) | |
330 | - { | |
331 | - if (!isset($this->paramImpexMgr)) | |
332 | - $this->paramImpexMgr = new ImpexParamManager(); | |
333 | - | |
334 | - $parameterID = $this->paramImpexMgr->getImpexFullParamId($param, $templateArgs); | |
335 | - | |
336 | - $requestNodes = $paramsData->getRequestNodes(); | |
337 | - | |
338 | - // it is PARAMSGEN | |
339 | - if (!$requestNodes) { | |
340 | - return array("id" => $parameterID); | |
341 | - } | |
342 | - | |
343 | - $timesNode = $requestNodes[0]->getTimesNode(); | |
344 | - $intervals = $timesNode->getIntervals(); | |
345 | - $originFile = IHMConfigClass::getUserWSPath().$parameterID.".xml"; | |
346 | - | |
347 | - if (!file_exists($originFile)) { | |
348 | - // create IMPEX parameter info and data | |
349 | - $res = $this->paramImpexMgr->createImpexParameter($param, $intervals, $templateArgs); | |
350 | - | |
351 | - if (!$res["success"]) | |
352 | - throw new Exception('Error to create IMPEX parameter : '.$res["message"]); | |
353 | - | |
354 | - $newParamNode = $paramsData->addLocalParamToCreate($res["param"]["id"], | |
355 | - $res["param"]["info"]["viId"], $res["param"]["info"]["realVar"], | |
356 | - $res["param"]["info"]["minSampling"], $res["param"]["info"]["maxSampling"], | |
357 | - $res["param"]["info"]["type"],$res["param"]["info"]["size"], | |
358 | - NULL,$res["param"]["dateModif"],true); | |
359 | - | |
360 | - $newParamNode->getInfo()->setName($res["param"]["info"]['name']); | |
361 | - $newParamNode->getInfo()->setShortName($res["param"]["info"]['name']); | |
362 | - $newParamNode->getInfo()->setUnits($res["param"]["info"]['units']); | |
363 | - | |
364 | - $tableDef = $res["param"]["info"]["tableDef"]; | |
365 | - if (isset($tableDef) && array_key_exists('tableDefType', $tableDef) && ($tableDef['tableDefType'] != 'NONE')) | |
366 | - { | |
367 | - switch ($tableDef['channelsDefType']) | |
368 | - { | |
369 | - case 'BOUND' : | |
370 | - $boundTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::BOUNDS, $res["param"]["info"]["yTitle"]); | |
371 | - $boundTable->setUnits($res["param"]["info"]["yUnits"]); | |
372 | - switch ($tableDef['tableDefType']) | |
373 | - { | |
374 | - case 'SELECT' : | |
375 | - $boundTable->setBoundsName($tableDef['data']['bound']); | |
376 | - $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['bound']); | |
377 | - break; | |
378 | - default : | |
379 | - throw new Exception("Unknown tableDefType ".$tableDef['tableDefType']); | |
380 | - } | |
381 | - break; | |
382 | - case 'CENTER' : | |
383 | - $centerTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTER, $res["param"]["info"]["yTitle"]); | |
384 | - $centerTable->setUnits($res["param"]["info"]["yUnits"]); | |
385 | - $centerTable->setSize($tableDef['data']['width']); | |
386 | - switch ($tableDef['tableDefType']) | |
387 | - { | |
388 | - case 'SELECT' : | |
389 | - $centerTable->setCenterName($tableDef['data']['center']); | |
390 | - $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['center']); | |
391 | - break; | |
392 | - default : | |
393 | - throw new Exception("Unknown tableDefType ".$tableDef['tableDefType']); | |
394 | - } | |
395 | - break; | |
396 | - default : | |
397 | - throw new Exception("Unknown tableDefType ".$tableDef['channelsDefType']); | |
398 | - } | |
399 | - } | |
400 | - | |
401 | - return array("id" => $res["param"]["id"], "plotType" => $res["param"]["info"]["plotType"]); | |
402 | - } | |
403 | - else { | |
404 | - // add IMPEX parameter data | |
405 | - $this->paramImpexMgr->addImpexData($param, $intervals, $templateArgs); | |
406 | - $paramsData->addParamToCopy($parameterID, $originFile); | |
407 | - | |
408 | - return array("id" => $parameterID); | |
409 | - } | |
410 | - } | |
411 | - | |
412 | - /* | |
413 | - * @brief Add uploaded parameter | |
414 | - */ | |
415 | - private function addUploadedParam($param,$paramsData) | |
416 | - { | |
417 | - if (!isset($this->userParameterMgr)) | |
418 | - $this->userParameterMgr = new IHMUserParamManagerClass(); | |
419 | - | |
420 | - //get uploaded parameter info | |
421 | - $res = $this->userParameterMgr->getUploadedParameterFromName($param); | |
422 | - | |
423 | - if (!$res["success"]) | |
424 | - throw new Exception('Error to load uploaded parameter file : '.$res["message"]); | |
425 | - | |
426 | - $paramId = $param; | |
427 | - | |
428 | - $newParamNode = $paramsData->addLocalParamToCreate($paramId, | |
429 | - $res["param"]["info"]["viId"], $res["param"]["info"]["realVar"], | |
430 | - $res["param"]["info"]["minSampling"], $res["param"]["info"]["maxSampling"], | |
431 | - $res["param"]["info"]["type"],$res["param"]["info"]["size"], | |
432 | - $res["param"]["info"]["fillValue"],$res["param"]["dateModif"]); | |
433 | - | |
434 | - if (!empty($res["param"]["info"]["yTitle"])) { | |
435 | - $newParamNode->getInfo()->setName($res["param"]["info"]['yTitle']); | |
436 | - $newParamNode->getInfo()->setShortName($res["param"]["info"]['yTitle']); | |
437 | - } | |
438 | - if (!empty($res["param"]["info"]['units'])) { | |
439 | - $newParamNode->getInfo()->setUnits($res["param"]["info"]['units']); | |
440 | - } | |
441 | - | |
442 | - | |
443 | - $tableDef = $res["param"]["info"]["tableDef"]; | |
444 | - if (isset($tableDef) && array_key_exists('tableDefType', $tableDef) && ($tableDef['tableDefType'] != 'NONE')) | |
445 | - { | |
446 | - $tableName = empty($tableDef['tableName']) ? 'Table' : $tableDef['tableName']; | |
447 | - $tableUnits = empty($tableDef['tableUnits']) ? '' : $tableDef['tableUnits']; | |
448 | - switch ($tableDef['channelsDefType']) | |
449 | - { | |
450 | - case 'MINMAX' : | |
451 | - $minMaxTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::MINMAX, $tableName); | |
452 | - $minMaxTable->setUnits($tableUnits); | |
453 | - switch ($tableDef['tableDefType']) | |
454 | - { | |
455 | - case 'SELECT' : | |
456 | - $minMaxTable->setMinName($tableDef['data']['min']); | |
457 | - $minMaxTable->setMaxName($tableDef['data']['max']); | |
458 | - $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['min']); | |
459 | - $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['max']); | |
460 | - break; | |
461 | - case 'MANUAL' : | |
462 | - $minMaxTable->setMinName('min'); | |
463 | - $minMaxTable->setMaxName('max'); | |
464 | - $clbMinNode = $newParamNode->addClbManual('min'); | |
465 | - $clbMinValues = explode(',', $tableDef['data']['min']); | |
466 | - foreach ($clbMinValues as $value) | |
467 | - $clbMinNode->addClbValue($value); | |
468 | - $clbMaxNode = $newParamNode->addClbManual('max'); | |
469 | - $clbMaxValues = explode(',', $tableDef['data']['max']); | |
470 | - foreach ($clbMaxValues as $value) | |
471 | - $clbMaxNode->addClbValue($value); | |
472 | - break; | |
473 | - } | |
474 | - break; | |
475 | - case 'BOUND' : | |
476 | - $boundTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::BOUNDS, $tableName); | |
477 | - $boundTable->setUnits($tableUnits); | |
478 | - switch ($tableDef['tableDefType']) | |
479 | - { | |
480 | - case 'SELECT' : | |
481 | - $boundTable->setBoundsName($tableDef['data']['bound']); | |
482 | - $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['bound']); | |
483 | - break; | |
484 | - case 'MANUAL' : | |
485 | - $boundTable->setBoundsName('bound'); | |
486 | - $clbBoundNode = $newParamNode->addClbManual('bound'); | |
487 | - $clbBoundValues = explode(',', $tableDef['data']['bound']); | |
488 | - foreach ($clbBoundValues as $value) | |
489 | - $clbBoundNode->addClbValue($value); | |
490 | - break; | |
491 | - } | |
492 | - break; | |
493 | - case 'CENTER' : | |
494 | - $centerTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTER, $tableName); | |
495 | - $centerTable->setUnits($tableUnits); | |
496 | - $centerTable->setSize($tableDef['data']['width']); | |
497 | - switch ($tableDef['tableDefType']) | |
498 | - { | |
499 | - case 'SELECT' : | |
500 | - $centerTable->setCenterName($tableDef['data']['center']); | |
501 | - $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['center']); | |
502 | - break; | |
503 | - case 'MANUAL' : | |
504 | - $centerTable->setCenterName('center'); | |
505 | - $clbCenterNode = $newParamNode->addClbManual('center'); | |
506 | - $clbCenterValues = explode(',', $tableDef['data']['center']); | |
507 | - foreach ($clbCenterValues as $value) | |
508 | - $clbCenterNode->addClbValue($value); | |
509 | - break; | |
510 | - } | |
511 | - break; | |
512 | - case 'CENTERWIDTH' : | |
513 | - $centerWidthTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTERWIDTH, $tableName); | |
514 | - $centerWidthTable->setUnits($tableUnits); | |
515 | - switch ($tableDef['tableDefType']) | |
516 | - { | |
517 | - case 'SELECT' : | |
518 | - $centerWidthTable->setCenterName($tableDef['data']['center']); | |
519 | - $centerWidthTable->setWidthName($tableDef['data']['width']); | |
520 | - $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['center']); | |
521 | - $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['width']); | |
522 | - break; | |
523 | - case 'MANUAL' : | |
524 | - $centerWidthTable->setCenterName('center'); | |
525 | - $centerWidthTable->setWidthName('width'); | |
526 | - $clbCenterNode = $newParamNode->addClbManual('center'); | |
527 | - $clbWidthNode = $newParamNode->addClbManual('width'); | |
528 | - $clbCenterValues = explode(',', $tableDef['data']['center']); | |
529 | - foreach ($clbCenterValues as $value) | |
530 | - $clbCenterNode->addClbValue($value); | |
531 | - $clbWidthValues = explode(',', $tableDef['data']['width']); | |
532 | - foreach ($clbWidthValues as $value) | |
533 | - $clbWidthNode->addClbValue($value); | |
534 | - break; | |
535 | - } | |
536 | - break; | |
537 | - } | |
538 | - } | |
539 | - | |
540 | - return array("id" => $paramId, "plotType" => $res["param"]["info"]["plotType"]); | |
541 | - } | |
542 | - | |
543 | - public function applyFilter($paramsData, $paramData, &$paramInfo) { | |
544 | - $filter = (isset($paramData->{'filter_spikes'}) && ($paramData->{'filter_spikes'}))? true:false; | |
545 | - if(!$filter){ | |
546 | - return; | |
547 | - } | |
548 | - $my_type= $paramData->{'type'}; | |
549 | - | |
550 | - switch ($paramData->{'type'}) { | |
551 | - case 0: | |
552 | - break; | |
553 | - case 1: | |
554 | - // vector | |
555 | - $dim1_index = ($dim1_is_range || !isset($paramData->{'dim1-index'}) || ($paramData->{'dim1-index'} == '')) ? '*' : $paramData->{'dim1-index'}; | |
556 | - $dim2_index = ($dim2_is_range || !isset($paramData->{'dim2-index'}) || ($paramData->{'dim2-index'} == '')) ? '*' : $paramData->{'dim2-index'}; | |
557 | - $factor = !empty($paramData->{'filter_spikes_factor'}) ? $paramData->{'filter_spikes_factor'} : 5; | |
558 | - $nPoints = !empty($paramData->{'filter_spikes_nPoints'}) ? $paramData->{'filter_spikes_nPoints'} : 100; | |
559 | - if($dim1_index != '*'){ | |
560 | - $template_args = array( | |
561 | - 'paramid' => $paramInfo['id'], | |
562 | - 'factor' => $factor, | |
563 | - 'nPoints' => $nPoints, | |
564 | - 'index' => $dim1_index | |
565 | - ); | |
566 | - $paramInfo = $this->addExistingParam('filter_spikes_component', $paramsData, $template_args); | |
567 | - }else{ | |
568 | - $template_args = array( | |
569 | - 'paramid' => $paramInfo['id'], | |
570 | - 'factor' => $factor, | |
571 | - 'nPoints' => $nPoints, | |
572 | - ); | |
573 | - $paramInfo = $this->addExistingParam('filter_spikes', $paramsData, $template_args); | |
574 | - } | |
575 | - break; | |
576 | - case 2: | |
577 | - return array('success' => FALSE, 'message' => '2D Table filtering not implรฉmented yet'); | |
578 | - | |
579 | - } | |
8 | +class IHMParamManagerClass { | |
9 | + | |
10 | + protected $userParameterMgr = null; | |
11 | + protected $templateParamsManager = null; | |
12 | + protected $paramImpexMgr = null; | |
13 | + protected $ttCatMgr = null; | |
14 | + protected $cacheExpressionParser = null; | |
15 | + | |
16 | + /* | |
17 | + * @brief Constructor | |
18 | + */ | |
19 | + | |
20 | + function __construct() { | |
21 | + $this->templateParamsManager = new IHMParamTemplateClass(); | |
22 | + $this->cacheExpressionParser = array(); | |
23 | + } | |
24 | + | |
25 | + public function addGeneratedParam($paramId, $expression, $sampling_mode, $sampling_step, $ref_param, $paramsData) { | |
26 | + $expressionInfo = $this->parseExpression($expression, $paramsData->getWorkingPath()); | |
27 | + if (!$expressionInfo['success']) { | |
28 | + throw new Exception($expressionInfo['message']); | |
29 | + } | |
30 | + | |
31 | + //create a process param for the derived parameter | |
32 | + $this->addProcessParam($paramId, $expressionInfo["expression"], $expression, $expressionInfo['params'], $sampling_mode, $sampling_step, $ref_param, 0, time(), "", "", $paramsData); | |
33 | + } | |
34 | + | |
35 | + /* | |
36 | + * @brief Add an existing parameter | |
37 | + */ | |
38 | + | |
39 | + public function addExistingParam($param, $paramsData, $templateArgs = NULL, $tableLink = NULL) { | |
40 | + if ($this->isDerivedParam($param)) | |
41 | + return $this->addDerivedParam($param, $paramsData); | |
42 | + else if ($this->isUploadedParam($param)) | |
43 | + return $this->addUploadedParam($param, $paramsData); | |
44 | + else if ($this->isImpexParam($param)) | |
45 | + return $this->addImpexParam($param, $paramsData, $templateArgs); | |
46 | + else | |
47 | + return $this->addLocalParam($param, $paramsData, $templateArgs, $tableLink); | |
48 | + return ""; | |
49 | + } | |
50 | + | |
51 | + /* | |
52 | + * @brief Add a process parameter | |
53 | + */ | |
54 | + | |
55 | + public function addProcessParam($paramId, $expression, $expression_info, $params, $sampling_mode, $sampling_step, $ref_param, $gap, $dateModif, $units, $ytitle, $paramsData) { | |
56 | + $paramsData->addProcessParamToCreate($paramId, $expression, $expression_info, $params, $sampling_mode, $sampling_step, $ref_param, $gap, $dateModif, $units, $ytitle); | |
57 | + | |
58 | + foreach ($params as $param) { | |
59 | + $template_args = NULL; | |
60 | + | |
61 | + if (array_key_exists("template_args", $param)) | |
62 | + $template_args = $param["template_args"]; | |
63 | + | |
64 | + $this->addExistingParam($param["paramid"], $paramsData, $template_args); | |
65 | + } | |
66 | + if (!empty($ref_param)) { | |
67 | + $this->addExistingParam($ref_param, $paramsData, $template_args); | |
68 | + } | |
69 | + | |
70 | + return true; | |
71 | + } | |
72 | + | |
73 | + /* | |
74 | + * @brief Add a TT or catalog parameter | |
75 | + */ | |
76 | + | |
77 | + public function addTTCatParam($paramId, $paramsData) { | |
78 | + if (!isset($this->ttCatMgr)) { | |
79 | + $this->ttCatMgr = new IHMTTCatLoaderClass(); | |
80 | + } | |
81 | + $info = $this->ttCatMgr->getTTCatInfoFromId($paramId); | |
82 | + | |
83 | + if (!$info["success"]) { | |
84 | + throw new Exception($info["message"]); | |
85 | + } | |
86 | + | |
87 | + $status = array(); | |
88 | + $units = ""; | |
89 | + $ytitle = ""; | |
90 | + $flag = ""; | |
91 | + | |
92 | + if ($info["info"]["isCatalog"]) { | |
93 | + $parameters = $this->ttCatMgr->getCatalogParameters($paramId); | |
94 | + if (!$parameters["success"] || empty($parameters["parameters"])) { | |
95 | + throw new Exception("Error to extract first parameter of " . $paramId); | |
96 | + } | |
97 | + //For the moment, use the first parameter | |
98 | + $parameter = $parameters["parameters"][0]; | |
99 | + $units = $parameter["units"]; | |
100 | + $ytitle = !empty($parameter["name"]) ? $parameter["name"] : $parameter["id"]; | |
101 | + $flag = $parameter["id"]; | |
102 | + $description = $parameter["description"]; | |
103 | + $desc_parts = array(); | |
104 | + foreach (explode("-", $description) as $def) { | |
105 | + $def = trim($def); | |
106 | + $p = strpos($def, ":"); | |
107 | + if ($p === FALSE) { | |
108 | + continue; | |
109 | + } | |
110 | + $val = substr($def, 0, $p); | |
111 | + $val = trim($val); | |
112 | + $name = substr($def, $p + 1); | |
113 | + $name = trim($name); | |
114 | + $color = ""; | |
115 | + $p = strpos($name, "["); | |
116 | + if ($p !== FALSE) { | |
117 | + $color = substr($name, $p); | |
118 | + $color = trim($color); | |
119 | + $name = substr($name, 0, $p); | |
120 | + $name = trim($name); | |
121 | + } | |
122 | + $status[] = array( | |
123 | + "min" => floatval($val), | |
124 | + "max" => floatval($val), | |
125 | + "name" => $name, | |
126 | + "color" => $color, | |
127 | + ); | |
128 | + } | |
129 | + } else { | |
130 | + $status = array( | |
131 | + array( | |
132 | + "min" => 1, | |
133 | + "max" => 1, | |
134 | + "name" => "Inside", | |
135 | + "color" => "[255,0,0]", | |
136 | + ) | |
137 | + ); | |
138 | + $ytitle = $info["info"]["name"]; | |
139 | + } | |
140 | + | |
141 | + $paramsData->addTTCatParamToCreate($paramId, $info["info"]["path"], $info["info"]["isShared"], filemtime($info["info"]["path"]), $units, $ytitle, $status, $flag); | |
142 | + return array("id" => $paramId, "indexes" => array(), "calib_infos" => array()); | |
143 | + } | |
144 | + | |
145 | + /* | |
146 | + * @brief Detect if it's a derived parameter | |
147 | + */ | |
148 | + | |
149 | + private function isDerivedParam($param) { | |
150 | + return preg_match("#^ws_#", $param); | |
151 | + } | |
152 | + | |
153 | + /* | |
154 | + * @brief Detect if it's a uploaded parameter | |
155 | + */ | |
156 | + | |
157 | + public function isUploadedParam($param) { | |
158 | + return preg_match("#^wsd_#", $param); | |
159 | + } | |
160 | + | |
161 | + /* | |
162 | + * @brief Detect if it's IMPEX parameter | |
163 | + */ | |
164 | + | |
165 | + private function isImpexParam($param) { | |
166 | + return preg_match("#^" . IHMImpexParamClass::$paramPrefix . "#", $param); | |
167 | + } | |
168 | + | |
169 | + /* | |
170 | + * @brief Add a local parameter | |
171 | + */ | |
172 | + | |
173 | + private function addLocalParam($param, $paramsData, $templateArgs, $tableLink) { | |
174 | + //local parameter | |
175 | + $indexes = array(); | |
176 | + $calib_infos = array(); | |
177 | + //check for components | |
178 | + $pattern = "/(?P<param>.*)\((?P<components>.*)\)/"; | |
179 | + preg_match_all($pattern, $param, $matches); | |
180 | + if ((count($matches["param"]) > 0) && (count($matches["components"]) > 0)) { | |
181 | + $paramId = $matches["param"][0]; | |
182 | + $indexes = explode(",", $matches["components"][0]); | |
183 | + } else | |
184 | + $paramId = $param; | |
185 | + | |
186 | + //check templated parameter | |
187 | + $real_param_id = $paramId; | |
188 | + $paramPath = ""; | |
189 | + if ($this->templateParamsManager->isTemplatedParam($paramId)) { | |
190 | + $paramPath = $this->templateParamsManager->generateTemplatedParamFile($paramId, $templateArgs, $tableLink); | |
191 | + $real_param_id = $this->templateParamsManager->getTemplatedParamId($paramId, $templateArgs); | |
192 | + if (empty($paramPath) || !file_exists($paramPath)) | |
193 | + throw new Exception('Cannot generate parameter template file ' . $paramId); | |
194 | + } | |
195 | + else { | |
196 | + $paramPath = IHMConfigClass::getLocalParamDBPath() . $paramId . ".xml"; | |
197 | + if (!file_exists($paramPath)) | |
198 | + throw new Exception('Cannot find parameter local file ' . $paramId); | |
199 | + } | |
200 | + | |
201 | + $paramsData->addParamToCopy($real_param_id, $paramPath); | |
202 | + | |
203 | + $this->addLinkedLocalParams($paramId, $paramsData, $templateArgs); | |
204 | + | |
205 | + return array("id" => $real_param_id, "indexes" => $indexes, "calib_infos" => $calib_infos, "path" => $paramPath); | |
206 | + } | |
207 | + | |
208 | + /* | |
209 | + * @brief Add linked parameter | |
210 | + */ | |
211 | + | |
212 | + private function addLinkedLocalParams($paramId, $paramsData, $templateArgs = NULL) { | |
213 | + $doc = new DOMDocument("1.0", "UTF-8"); | |
214 | + $doc->preserveWhiteSpace = false; | |
215 | + $doc->formatOutput = true; | |
216 | + | |
217 | + $real_param_id = $paramId; | |
218 | + if ($this->templateParamsManager->isTemplatedParam($paramId)) { | |
219 | + $paramPath = $this->templateParamsManager->getTemplatePath($paramId); | |
220 | + if (empty($paramPath) || !@$doc->load($paramPath)) | |
221 | + throw new Exception('Cannot find parameter template file ' . $paramId); | |
222 | + } | |
223 | + else { | |
224 | + $paramPath = IHMConfigClass::getLocalParamDBPath() . $paramId . ".xml"; | |
225 | + if (empty($paramPath) || !@$doc->load($paramPath)) | |
226 | + throw new Exception('Cannot find parameter local file ' . $paramId); | |
227 | + } | |
228 | + | |
229 | + //<get> | |
230 | + $getNodes = $doc->getElementsByTagName('get'); | |
231 | + | |
232 | + if ($getNodes->length <= 0) | |
233 | + throw new Exception('Parameter local file ' . $paramId . ' dont have a getter node'); | |
234 | + | |
235 | + $getNode = $getNodes->item(0); | |
236 | + | |
237 | + //<amdaParam name="imf"/> | |
238 | + $amdaParamNodes = $doc->getElementsByTagName('amdaParam'); | |
239 | + | |
240 | + foreach ($amdaParamNodes as $amdaParamNode) { | |
241 | + $linkedParamId = $amdaParamNode->getAttribute('name'); | |
242 | + if (empty($linkedParamId)) | |
243 | + continue; | |
244 | + $template_id = $this->templateParamsManager->getTemplateId($linkedParamId); | |
245 | + $tempArgs = isset($templateArgs) ? $templateArgs : array(); | |
246 | + if ($template_id !== FALSE) { | |
247 | + $linkedParamId = $template_id; | |
248 | + } else { | |
249 | + $linkedParamId = $this->templateParamsManager->replaceArgs($linkedParamId, $templateArgs); | |
250 | + $parsedParam = $this->templateParamsManager->parseTemplatedParam($linkedParamId); | |
251 | + if ($parsedParam !== FALSE) { | |
252 | + $linkedParamId = $parsedParam['paramid']; | |
253 | + foreach ($parsedParam['template_args'] as $key => $val) { | |
254 | + $tempArgs[$key] = $val; | |
580 | 255 | } |
581 | - | |
582 | - | |
583 | - public function applyRangesAndIndexes($paramsData, $paramData, $force_total_2d, &$paramInfo) { | |
584 | - $dim1_min = 0; | |
585 | - $dim1_max = 0; | |
586 | - $dim2_min = 0; | |
587 | - $dim2_max = 0; | |
588 | - | |
589 | - $dim1_is_range = (isset($paramData->{'dim1-sum-type'}) && ($paramData->{'dim1-sum-type'} > 0)); | |
590 | - $dim1_index = ($dim1_is_range || !isset($paramData->{'dim1-index'}) || ($paramData->{'dim1-index'} == '')) ? '*' : $paramData->{'dim1-index'}; | |
591 | - if ($dim1_is_range) { | |
592 | - switch ($paramData->{'dim1-sum-type'}) { | |
593 | - case 1: | |
594 | - //Sum between a range of value | |
595 | - $dim1_min = !empty($paramData->{'dim1-min-value'}) ? $paramData->{'dim1-min-value'} : 0; | |
596 | - $dim1_max = !empty($paramData->{'dim1-max-value'}) ? $paramData->{'dim1-max-value'} : 0; | |
597 | - break; | |
598 | - case 2: | |
599 | - //Sum between indexes | |
600 | - $dim1_min = !empty($paramData->{'dim1-min-index'}) ? $paramData->{'dim1-min-index'} : 0; | |
601 | - $dim1_max = !empty($paramData->{'dim1-max-index'}) ? $paramData->{'dim1-max-index'} : 0; | |
602 | - break; | |
603 | - } | |
604 | - } | |
605 | - | |
606 | - $dim2_is_range = (isset($paramData->{'dim2-sum-type'}) && ($paramData->{'dim2-sum-type'} > 0)); | |
607 | - $dim2_index = ($dim2_is_range || !isset($paramData->{'dim2-index'}) || ($paramData->{'dim2-index'} == '')) ? '*' : $paramData->{'dim2-index'}; | |
608 | - if ($dim2_is_range) { | |
609 | - switch ($paramData->{'dim2-sum-type'}) { | |
610 | - case 1: | |
611 | - //Sum between a range of value | |
612 | - $dim2_min = !empty($paramData->{'dim2-min-value'}) ? $paramData->{'dim2-min-value'} : 0; | |
613 | - $dim2_max = !empty($paramData->{'dim2-max-value'}) ? $paramData->{'dim2-max-value'} : 0; | |
614 | - break; | |
615 | - case 2: | |
616 | - //Sum between indexes | |
617 | - $dim2_min = !empty($paramData->{'dim2-min-index'}) ? $paramData->{'dim2-min-index'} : 0; | |
618 | - $dim2_max = !empty($paramData->{'dim2-max-index'}) ? $paramData->{'dim2-max-index'} : 0; | |
619 | - break; | |
620 | - } | |
621 | - } | |
622 | - | |
623 | - switch ($paramData->{'type'}) { | |
624 | - case 0: | |
625 | - //scalar - nothing to do | |
626 | - break; | |
627 | - case 1: | |
628 | - //Tab1D | |
629 | - if ($dim1_is_range) { | |
630 | - $template_args = array( | |
631 | - 'paramid' => $paramInfo['id'], | |
632 | - 'min' => $dim1_min, | |
633 | - 'max' => $dim1_max, | |
634 | - 'relateddim' => 0, | |
635 | - ); | |
636 | - if ($paramData->{'dim1-sum-type'} == 2) | |
637 | - $paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args); | |
638 | - else | |
639 | - $paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args); | |
640 | - } | |
641 | - else if ($dim2_is_range) { | |
642 | - $template_args = array( | |
643 | - 'paramid' => $paramInfo['id'], | |
644 | - 'min' => $dim2_min, | |
645 | - 'max' => $dim2_max, | |
646 | - 'relateddim' => 1, | |
647 | - ); | |
648 | - if ($paramData->{'dim2-sum-type'} == 2) | |
649 | - $paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args); | |
650 | - else | |
651 | - $paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args); | |
652 | - } | |
653 | - else if ($dim1_index != '*') { | |
654 | - $paramInfo['indexes'][] = $dim1_index; | |
655 | - } | |
656 | - else if ($dim2_index != '*') { | |
657 | - $paramInfo['indexes'][] = $dim2_index; | |
658 | - } | |
659 | - break; | |
660 | - case 2: | |
661 | - //Tab2D | |
662 | - if ($dim1_is_range && $dim2_is_range) { | |
663 | - if ($paramData->{'dim1-sum-type'} != $paramData->{'dim2-sum-type'}) { | |
664 | - throw new Exception("Not supported - Dimensions ranges for ".$paramInfo['id']." must have the same type for each dimensions"); | |
665 | - } | |
666 | - $template_args = array( | |
667 | - 'paramid' => $paramInfo['id'], | |
668 | - 'min1' => $dim1_min, | |
669 | - 'max1' => $dim1_max, | |
670 | - 'relateddim1' => 0, | |
671 | - 'min2' => $dim2_min, | |
672 | - 'max2' => $dim2_max, | |
673 | - ); | |
674 | - if ($paramData->{'dim1-sum-type'} == 2) | |
675 | - $paramInfo = $this->addExistingParam('sum_into_table_indexes_2d', $paramsData, $template_args); | |
676 | - else | |
677 | - $paramInfo = $this->addExistingParam('sum_into_table_range_2d', $paramsData, $template_args); | |
678 | - } | |
679 | - else if ($dim1_is_range) { | |
680 | - $template_args = array( | |
681 | - 'paramid' => $paramInfo['id'], | |
682 | - 'min' => $dim1_min, | |
683 | - 'max' => $dim1_max, | |
684 | - 'relateddim' => 0, | |
685 | - ); | |
686 | - $tableLink = array( | |
687 | - 'paramid' => $paramInfo['id'], | |
688 | - 'relateddim' => 1, | |
689 | - ); | |
690 | - if ($paramData->{'dim1-sum-type'} == 2) | |
691 | - $paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args, $tableLink); | |
692 | - else | |
693 | - $paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args, $tableLink); | |
694 | - if ($dim2_index != '*') { | |
695 | - $paramInfo['indexes'][] = $dim2_index; | |
696 | - } | |
697 | - } | |
698 | - else if ($dim2_is_range) { | |
699 | - $template_args = array( | |
700 | - 'paramid' => $paramInfo['id'], | |
701 | - 'min' => $dim2_min, | |
702 | - 'max' => $dim2_max, | |
703 | - 'relateddim' => 1, | |
704 | - ); | |
705 | - $tableLink = array( | |
706 | - 'paramid' => $paramInfo['id'], | |
707 | - 'relateddim' => 0, | |
708 | - ); | |
709 | - if ($paramData->{'dim2-sum-type'} == 2) | |
710 | - $paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args, $tableLink); | |
711 | - else | |
712 | - $paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args, $tableLink); | |
713 | - if ($dim1_index != '*') { | |
714 | - $paramInfo['indexes'][] = $dim1_index; | |
715 | - } | |
716 | - } | |
717 | - else if (($dim1_index != '*') && ($dim2_index != '*')) { | |
718 | - $paramInfo['indexes'][] = "[".$dim1_index.",".$dim2_index."]"; | |
719 | - } | |
720 | - else if ($dim1_index != '*') { | |
721 | - $paramInfo['indexes'][] = "[".$dim1_index.",*]"; | |
722 | - } | |
723 | - else if ($dim2_index != '*') { | |
724 | - $paramInfo['indexes'][] = "[*,".$dim2_index."]"; | |
725 | - } | |
726 | - else if ($force_total_2d) { | |
727 | - //total over 2 dims | |
728 | - $template_args = array( | |
729 | - 'paramid' => $paramInfo['id'], | |
730 | - ); | |
731 | - $paramInfo = $this->addExistingParam('total_2D', $paramsData, $template_args); | |
732 | - } | |
733 | - break; | |
734 | - } | |
735 | - } | |
736 | - | |
737 | - public function parseExpression($expression, $workingDir) { | |
738 | - $outputFileName = "parser_".md5($expression).".xml"; | |
739 | - if (array_key_exists($outputFileName, $this->cacheExpressionParser)) { | |
740 | - return $this->cacheExpressionParser[$outputFileName]; | |
741 | - } | |
742 | - $parserData = new ParserRequestDataClass(); | |
743 | - $parserData->setManagerFilePath(IHMConfigClass::getProcessManagerFilePath()); | |
744 | - $parserData->addExpression($expression); | |
745 | - $parserData->setWorkingPath($workingDir); | |
746 | - $parserData->setLocalParamsPath(IHMConfigClass::getLocalParamDBPath()); | |
747 | - $parserData->setConstantsFilePath(IHMConfigClass::getConstantsFilePath()); | |
748 | - $parserData->setFunctionsFilePath(IHMConfigClass::getFunctionsFilePath()); | |
749 | - $parserData->setParamTemplatesFilePath(IHMConfigClass::getParamTemplateListFilePath()); | |
750 | - $parserData->setFunctionsArgsListFilePath(IHMConfigClass::getFunctionsArgsListFilePath()); | |
751 | - $parserData->setOutputFileName($outputFileName); | |
752 | - $resultFilePath = $workingDir."/".$outputFileName; | |
753 | - | |
754 | - $parserRequest = new ParserRequestClass(); | |
755 | - $parserRequest->setData($parserData); | |
756 | - | |
757 | - if (!$parserRequest->init() || !$parserRequest->run()) { | |
758 | - if (file_exists($resultFilePath)) { | |
759 | - unlink($resultFilePath); | |
760 | - } | |
761 | - return array('success' => FALSE, 'message' => 'Error to init or run expression parser'); | |
762 | - } | |
763 | - | |
764 | - //Load result file | |
765 | - $doc = new DOMDocument(); | |
766 | - $doc->load($resultFilePath); | |
767 | - if (!$doc->load($resultFilePath)) { | |
768 | - if (file_exists($resultFilePath)) { | |
769 | - unlink($resultFilePath); | |
770 | - } | |
771 | - return array('success' => FALSE, 'message' => 'Error to load parser result file'); | |
772 | - } | |
773 | - | |
774 | - $expressionNodes = $doc->getElementsByTagName('expression'); | |
775 | - if ($expressionNodes->length == 0) { | |
776 | - unlink($resultFilePath); | |
777 | - return array('success' => FALSE, 'message' => 'Cannot get expression nodes in parser result file'); | |
778 | - } | |
779 | - | |
780 | - $crtExpressionNode = NULL; | |
781 | - foreach ($expressionNodes as $expressionNode) { | |
782 | - $ihmExpressionNodes = $expressionNode->getElementsByTagName('ihm'); | |
783 | - if ($ihmExpressionNodes->length == 0) { | |
784 | - continue; | |
785 | - } | |
786 | - if ($ihmExpressionNodes->item(0)->nodeValue == $expression) { | |
787 | - $crtExpressionNode = $expressionNode; | |
788 | - break; | |
789 | - } | |
790 | - } | |
791 | - | |
792 | - if (!isset($crtExpressionNode)) { | |
793 | - unlink($resultFilePath); | |
794 | - return array('success' => FALSE, 'message' => 'Cannot retrieve expression in parser result file'); | |
795 | - } | |
796 | - | |
797 | - if ($crtExpressionNode->getAttribute('success') != "true") { | |
798 | - unlink($resultFilePath); | |
799 | - return array('success' => FALSE, 'message' => 'Synthax error in expression '.$expression); | |
800 | - } | |
801 | - | |
802 | - $kernelExpressionNodes = $crtExpressionNode->getElementsByTagName('kernel'); | |
803 | - if ($kernelExpressionNodes->length == 0) { | |
804 | - unlink($resultFilePath); | |
805 | - return array('success' => FALSE, 'message' => 'Cannot retrieve kernel expression in parser result file'); | |
806 | - } | |
807 | - | |
808 | - $kernelExpression = $kernelExpressionNodes->item(0)->nodeValue; | |
809 | - | |
810 | - if (empty($kernelExpression)) { | |
811 | - unlink($resultFilePath); | |
812 | - return array('success' => FALSE, 'message' => 'Parser return an empty expression'); | |
813 | - } | |
814 | - | |
815 | - $params = array(); | |
816 | - $paramsNodes = $crtExpressionNode->getElementsByTagName('params'); | |
817 | - if ($paramsNodes->length != 0) { | |
818 | - $paramNodes = $paramsNodes->item(0)->getElementsByTagName('param'); | |
819 | - if ($paramNodes->length != 0) { | |
820 | - foreach ($paramNodes as $paramNode) { | |
821 | - if (!empty($paramNode->nodeValue)) { | |
822 | - $params[] = array( | |
823 | - 'paramid' => $paramNode->nodeValue | |
824 | - ); | |
825 | - } | |
826 | - } | |
827 | - } | |
828 | - } | |
829 | - | |
830 | - unlink($resultFilePath); | |
831 | - | |
832 | - if (empty($params)) { | |
833 | - return array('success' => FALSE, 'message' => 'Expression should contain at least one parameter'); | |
834 | - } | |
835 | - | |
836 | - foreach ($params as &$param) { | |
837 | - $templated_param = $this->templateParamsManager->parseTemplatedParam($param['paramid']); | |
838 | - if ($templated_param !== FALSE) { | |
839 | - $param = $templated_param; | |
840 | - } | |
841 | - } | |
842 | - | |
843 | - $this->cacheExpressionParser[$outputFileName] = array('success' => TRUE, 'expression' => $kernelExpression, 'params' => $params); | |
844 | - return $this->cacheExpressionParser[$outputFileName]; | |
845 | - } | |
846 | - | |
847 | - public function getTemplateParamsManager() { | |
848 | - return $this->templateParamsManager; | |
849 | - } | |
256 | + } | |
257 | + } | |
258 | + | |
259 | + if ($this->templateParamsManager->isTemplatedParam($linkedParamId)) { | |
260 | + $linkedParamPath = $this->templateParamsManager->generateTemplatedParamFile($linkedParamId, $tempArgs); | |
261 | + $real_linked_param_id = $this->templateParamsManager->getTemplatedParamId($linkedParamId, $tempArgs); | |
262 | + } else { | |
263 | + $real_linked_param_id = $linkedParamId; | |
264 | + $linkedParamPath = IHMConfigClass::getLocalParamDBPath() . $real_linked_param_id . ".xml"; | |
265 | + } | |
266 | + $paramsData->addParamToCopy($real_linked_param_id, $linkedParamPath); | |
267 | + $this->addLinkedLocalParams($linkedParamId, $paramsData); | |
268 | + } | |
269 | + } | |
270 | + | |
271 | + /* | |
272 | + * @brief Add derived parameter | |
273 | + */ | |
274 | + | |
275 | + private function addDerivedParam($param, $paramsData) { | |
276 | + $time = time(); | |
277 | + if (!isset($this->userParameterMgr)) | |
278 | + $this->userParameterMgr = new IHMUserParamManagerClass(); | |
279 | + | |
280 | + //get derived parameter info | |
281 | + $res = $this->userParameterMgr->getDerivedParameterFromName($param); | |
282 | + | |
283 | + if (!$res["success"]) | |
284 | + throw new Exception('Error to load derived parameter file : ' . $res["message"]); | |
285 | + | |
286 | + if (isset($res["param"]["info"]["parsedExpression"])) { | |
287 | + //Re use existing parsed expression info | |
288 | + $expressionInfo = $res["param"]["info"]["parsedExpression"]; | |
289 | + } else { | |
290 | + //parse expression | |
291 | + $expressionInfo = $this->parseExpression($res["param"]["expression"], $paramsData->getWorkingPath()); | |
292 | + | |
293 | + if (!$expressionInfo['success']) { | |
294 | + throw new Exception($expressionInfo['message']); | |
295 | + } | |
296 | + | |
297 | + $paramsList = array(); | |
298 | + foreach ($expressionInfo['params'] as $p) { | |
299 | + $paramsList[] = $p["paramid"]; | |
300 | + } | |
301 | + $this->userParameterMgr->saveDerivedParameterParsedExpression($res["param"]["id"], $expressionInfo["expression"], md5($res["param"]["expression"]), $paramsList); | |
302 | + } | |
303 | + | |
304 | + $paramId = $param; | |
305 | + | |
306 | + //create a process param for the derived parameter | |
307 | + $this->addProcessParam($paramId, $expressionInfo["expression"], $res["param"]["expression"], $expressionInfo['params'], $res["param"]["info"]["sampling_mode"], $res["param"]["info"]["timestep"], $res["param"]["info"]["reference_param"], 0, $res["param"]["dateModif"], !empty($res["param"]["info"]["units"]) ? $res["param"]["info"]["units"] : "", !empty($res["param"]["info"]["yTitle"]) ? $res["param"]["info"]["yTitle"] : "", $paramsData); | |
308 | + | |
309 | + return array("id" => $paramId, "indexes" => array(), "calib_infos" => array()); | |
310 | + } | |
311 | + | |
312 | + /* | |
313 | + * @brief Add IMPEX parameter : create dynamically xml parameter descriptor in user WS | |
314 | + */ | |
315 | + | |
316 | + private function addImpexParam($param, $paramsData, $templateArgs = NULL) { | |
317 | + if (!isset($this->paramImpexMgr)) | |
318 | + $this->paramImpexMgr = new ImpexParamManager(); | |
319 | + | |
320 | + $parameterID = $this->paramImpexMgr->getImpexFullParamId($param, $templateArgs); | |
321 | + | |
322 | + $requestNodes = $paramsData->getRequestNodes(); | |
323 | + | |
324 | + // it is PARAMSGEN | |
325 | + if (!$requestNodes) { | |
326 | + return array("id" => $parameterID); | |
327 | + } | |
328 | + | |
329 | + $timesNode = $requestNodes[0]->getTimesNode(); | |
330 | + $intervals = $timesNode->getIntervals(); | |
331 | + $originFile = IHMConfigClass::getUserWSPath() . $parameterID . ".xml"; | |
332 | + | |
333 | + if (!file_exists($originFile)) { | |
334 | + // create IMPEX parameter info and data | |
335 | + $res = $this->paramImpexMgr->createImpexParameter($param, $intervals, $templateArgs); | |
336 | + | |
337 | + if (!$res["success"]) | |
338 | + throw new Exception('Error to create IMPEX parameter : ' . $res["message"]); | |
339 | + | |
340 | + $newParamNode = $paramsData->addLocalParamToCreate($res["param"]["id"], $res["param"]["info"]["viId"], $res["param"]["info"]["realVar"], $res["param"]["info"]["minSampling"], $res["param"]["info"]["maxSampling"], $res["param"]["info"]["type"], $res["param"]["info"]["size"], NULL, $res["param"]["dateModif"], true); | |
341 | + | |
342 | + $newParamNode->getInfo()->setName($res["param"]["info"]['name']); | |
343 | + $newParamNode->getInfo()->setShortName($res["param"]["info"]['name']); | |
344 | + $newParamNode->getInfo()->setUnits($res["param"]["info"]['units']); | |
345 | + | |
346 | + $tableDef = $res["param"]["info"]["tableDef"]; | |
347 | + if (isset($tableDef) && array_key_exists('tableDefType', $tableDef) && ($tableDef['tableDefType'] != 'NONE')) { | |
348 | + switch ($tableDef['channelsDefType']) { | |
349 | + case 'BOUND' : | |
350 | + $boundTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::BOUNDS, $res["param"]["info"]["yTitle"]); | |
351 | + $boundTable->setUnits($res["param"]["info"]["yUnits"]); | |
352 | + switch ($tableDef['tableDefType']) { | |
353 | + case 'SELECT' : | |
354 | + $boundTable->setBoundsName($tableDef['data']['bound']); | |
355 | + $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['bound']); | |
356 | + break; | |
357 | + default : | |
358 | + throw new Exception("Unknown tableDefType " . $tableDef['tableDefType']); | |
359 | + } | |
360 | + break; | |
361 | + case 'CENTER' : | |
362 | + $centerTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTER, $res["param"]["info"]["yTitle"]); | |
363 | + $centerTable->setUnits($res["param"]["info"]["yUnits"]); | |
364 | + $centerTable->setSize($tableDef['data']['width']); | |
365 | + switch ($tableDef['tableDefType']) { | |
366 | + case 'SELECT' : | |
367 | + $centerTable->setCenterName($tableDef['data']['center']); | |
368 | + $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['center']); | |
369 | + break; | |
370 | + default : | |
371 | + throw new Exception("Unknown tableDefType " . $tableDef['tableDefType']); | |
372 | + } | |
373 | + break; | |
374 | + default : | |
375 | + throw new Exception("Unknown tableDefType " . $tableDef['channelsDefType']); | |
376 | + } | |
377 | + } | |
378 | + | |
379 | + return array("id" => $res["param"]["id"], "plotType" => $res["param"]["info"]["plotType"]); | |
380 | + } else { | |
381 | + // add IMPEX parameter data | |
382 | + $this->paramImpexMgr->addImpexData($param, $intervals, $templateArgs); | |
383 | + $paramsData->addParamToCopy($parameterID, $originFile); | |
384 | + | |
385 | + return array("id" => $parameterID); | |
386 | + } | |
387 | + } | |
388 | + | |
389 | + /* | |
390 | + * @brief Add uploaded parameter | |
391 | + */ | |
392 | + | |
393 | + private function addUploadedParam($param, $paramsData) { | |
394 | + if (!isset($this->userParameterMgr)) | |
395 | + $this->userParameterMgr = new IHMUserParamManagerClass(); | |
396 | + | |
397 | + //get uploaded parameter info | |
398 | + $res = $this->userParameterMgr->getUploadedParameterFromName($param); | |
399 | + | |
400 | + if (!$res["success"]) | |
401 | + throw new Exception('Error to load uploaded parameter file : ' . $res["message"]); | |
402 | + | |
403 | + $paramId = $param; | |
404 | + | |
405 | + $newParamNode = $paramsData->addLocalParamToCreate($paramId, $res["param"]["info"]["viId"], $res["param"]["info"]["realVar"], $res["param"]["info"]["minSampling"], $res["param"]["info"]["maxSampling"], $res["param"]["info"]["type"], $res["param"]["info"]["size"], $res["param"]["info"]["fillValue"], $res["param"]["dateModif"]); | |
406 | + | |
407 | + if (!empty($res["param"]["info"]["yTitle"])) { | |
408 | + $newParamNode->getInfo()->setName($res["param"]["info"]['yTitle']); | |
409 | + $newParamNode->getInfo()->setShortName($res["param"]["info"]['yTitle']); | |
410 | + } | |
411 | + if (!empty($res["param"]["info"]['units'])) { | |
412 | + $newParamNode->getInfo()->setUnits($res["param"]["info"]['units']); | |
413 | + } | |
414 | + | |
415 | + | |
416 | + $tableDef = $res["param"]["info"]["tableDef"]; | |
417 | + if (isset($tableDef) && array_key_exists('tableDefType', $tableDef) && ($tableDef['tableDefType'] != 'NONE')) { | |
418 | + $tableName = empty($tableDef['tableName']) ? 'Table' : $tableDef['tableName']; | |
419 | + $tableUnits = empty($tableDef['tableUnits']) ? '' : $tableDef['tableUnits']; | |
420 | + switch ($tableDef['channelsDefType']) { | |
421 | + case 'MINMAX' : | |
422 | + $minMaxTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::MINMAX, $tableName); | |
423 | + $minMaxTable->setUnits($tableUnits); | |
424 | + switch ($tableDef['tableDefType']) { | |
425 | + case 'SELECT' : | |
426 | + $minMaxTable->setMinName($tableDef['data']['min']); | |
427 | + $minMaxTable->setMaxName($tableDef['data']['max']); | |
428 | + $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['min']); | |
429 | + $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['max']); | |
430 | + break; | |
431 | + case 'MANUAL' : | |
432 | + $minMaxTable->setMinName('min'); | |
433 | + $minMaxTable->setMaxName('max'); | |
434 | + $clbMinNode = $newParamNode->addClbManual('min'); | |
435 | + $clbMinValues = explode(',', $tableDef['data']['min']); | |
436 | + foreach ($clbMinValues as $value) | |
437 | + $clbMinNode->addClbValue($value); | |
438 | + $clbMaxNode = $newParamNode->addClbManual('max'); | |
439 | + $clbMaxValues = explode(',', $tableDef['data']['max']); | |
440 | + foreach ($clbMaxValues as $value) | |
441 | + $clbMaxNode->addClbValue($value); | |
442 | + break; | |
443 | + } | |
444 | + break; | |
445 | + case 'BOUND' : | |
446 | + $boundTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::BOUNDS, $tableName); | |
447 | + $boundTable->setUnits($tableUnits); | |
448 | + switch ($tableDef['tableDefType']) { | |
449 | + case 'SELECT' : | |
450 | + $boundTable->setBoundsName($tableDef['data']['bound']); | |
451 | + $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['bound']); | |
452 | + break; | |
453 | + case 'MANUAL' : | |
454 | + $boundTable->setBoundsName('bound'); | |
455 | + $clbBoundNode = $newParamNode->addClbManual('bound'); | |
456 | + $clbBoundValues = explode(',', $tableDef['data']['bound']); | |
457 | + foreach ($clbBoundValues as $value) | |
458 | + $clbBoundNode->addClbValue($value); | |
459 | + break; | |
460 | + } | |
461 | + break; | |
462 | + case 'CENTER' : | |
463 | + $centerTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTER, $tableName); | |
464 | + $centerTable->setUnits($tableUnits); | |
465 | + $centerTable->setSize($tableDef['data']['width']); | |
466 | + switch ($tableDef['tableDefType']) { | |
467 | + case 'SELECT' : | |
468 | + $centerTable->setCenterName($tableDef['data']['center']); | |
469 | + $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['center']); | |
470 | + break; | |
471 | + case 'MANUAL' : | |
472 | + $centerTable->setCenterName('center'); | |
473 | + $clbCenterNode = $newParamNode->addClbManual('center'); | |
474 | + $clbCenterValues = explode(',', $tableDef['data']['center']); | |
475 | + foreach ($clbCenterValues as $value) | |
476 | + $clbCenterNode->addClbValue($value); | |
477 | + break; | |
478 | + } | |
479 | + break; | |
480 | + case 'CENTERWIDTH' : | |
481 | + $centerWidthTable = $newParamNode->getInfo()->addTable(InfoParamTableTypeEnum::CENTERWIDTH, $tableName); | |
482 | + $centerWidthTable->setUnits($tableUnits); | |
483 | + switch ($tableDef['tableDefType']) { | |
484 | + case 'SELECT' : | |
485 | + $centerWidthTable->setCenterName($tableDef['data']['center']); | |
486 | + $centerWidthTable->setWidthName($tableDef['data']['width']); | |
487 | + $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['center']); | |
488 | + $newParamNode->getParamGet()->getLocalParam($res["param"]["info"]["realVar"])->addCalibInfo($tableDef['data']['width']); | |
489 | + break; | |
490 | + case 'MANUAL' : | |
491 | + $centerWidthTable->setCenterName('center'); | |
492 | + $centerWidthTable->setWidthName('width'); | |
493 | + $clbCenterNode = $newParamNode->addClbManual('center'); | |
494 | + $clbWidthNode = $newParamNode->addClbManual('width'); | |
495 | + $clbCenterValues = explode(',', $tableDef['data']['center']); | |
496 | + foreach ($clbCenterValues as $value) | |
497 | + $clbCenterNode->addClbValue($value); | |
498 | + $clbWidthValues = explode(',', $tableDef['data']['width']); | |
499 | + foreach ($clbWidthValues as $value) | |
500 | + $clbWidthNode->addClbValue($value); | |
501 | + break; | |
502 | + } | |
503 | + break; | |
504 | + } | |
505 | + } | |
506 | + | |
507 | + return array("id" => $paramId, "plotType" => $res["param"]["info"]["plotType"]); | |
508 | + } | |
509 | + | |
510 | + public function applyFilter($paramsData, $paramData, &$paramInfo) { | |
511 | + $filter = (isset($paramData->{'param-drawing-object'}->{'filtering-activated'}) && ($paramData->{'param-drawing-object'}->{'filtering-activated'})) ? true : false; | |
512 | + if (!$filter) { | |
513 | + return; | |
514 | + } | |
515 | + $my_type = $paramData->{'type'}; | |
516 | + | |
517 | + switch ($paramData->{'type'}) { | |
518 | + case 0: | |
519 | + case 1: | |
520 | + // vector | |
521 | + $dim1_index = ($dim1_is_range || !isset($paramData->{'dim1-index'}) || ($paramData->{'dim1-index'} == '')) ? '*' : $paramData->{'dim1-index'}; | |
522 | + $dim2_index = ($dim2_is_range || !isset($paramData->{'dim2-index'}) || ($paramData->{'dim2-index'} == '')) ? '*' : $paramData->{'dim2-index'}; | |
523 | + if (isset($paramData->{'param-drawing-object'}->{'filtering-level'})) { | |
524 | + switch ($paramData->{'param-drawing-object'}->{'filtering-level'}) { | |
525 | + case 1: | |
526 | + $factor = 6; | |
527 | + $nPoints = 100; | |
528 | + $level="low"; | |
529 | + break; | |
530 | + case 2: | |
531 | + $factor = 5; | |
532 | + $nPoints = 100; | |
533 | + $level="medium"; | |
534 | + break; | |
535 | + case 3: | |
536 | + $factor = 4; | |
537 | + $nPoints = 100; | |
538 | + $level="strong"; | |
539 | + break; | |
540 | + default: | |
541 | + $factor = 6; | |
542 | + $nPoints = 100; | |
543 | + $level="low"; | |
544 | + } | |
545 | + } else { | |
546 | + $factor = 5; | |
547 | + $nPoints = 100; | |
548 | + } | |
549 | + | |
550 | + if ($dim1_index != '*') { | |
551 | + $template_args = array( | |
552 | + 'paramid' => $paramInfo['id'], | |
553 | + 'factor' => $factor, | |
554 | + 'nPoints' => $nPoints, | |
555 | + 'index' => $dim1_index, | |
556 | + 'level' => $level | |
557 | + ); | |
558 | + $paramInfo = $this->addExistingParam('filter_spikes_component', $paramsData, $template_args); | |
559 | + } else { | |
560 | + $template_args = array( | |
561 | + 'paramid' => $paramInfo['id'], | |
562 | + 'factor' => $factor, | |
563 | + 'nPoints' => $nPoints, | |
564 | + 'level' => $level | |
565 | + ); | |
566 | + $paramInfo = $this->addExistingParam('filter_spikes', $paramsData, $template_args); | |
567 | + } | |
568 | + break; | |
569 | + case 2: | |
570 | + return array('success' => FALSE, 'message' => '2D Table filtering not implรฉmented yet'); | |
571 | + } | |
572 | + } | |
573 | + | |
574 | + public function applyRangesAndIndexes($paramsData, $paramData, $force_total_2d, &$paramInfo) { | |
575 | + $dim1_min = 0; | |
576 | + $dim1_max = 0; | |
577 | + $dim2_min = 0; | |
578 | + $dim2_max = 0; | |
579 | + | |
580 | + $dim1_is_range = (isset($paramData->{'dim1-sum-type'}) && ($paramData->{'dim1-sum-type'} > 0)); | |
581 | + $dim1_index = ($dim1_is_range || !isset($paramData->{'dim1-index'}) || ($paramData->{'dim1-index'} == '')) ? '*' : $paramData->{'dim1-index'}; | |
582 | + if ($dim1_is_range) { | |
583 | + switch ($paramData->{'dim1-sum-type'}) { | |
584 | + case 1: | |
585 | + //Sum between a range of value | |
586 | + $dim1_min = !empty($paramData->{'dim1-min-value'}) ? $paramData->{'dim1-min-value'} : 0; | |
587 | + $dim1_max = !empty($paramData->{'dim1-max-value'}) ? $paramData->{'dim1-max-value'} : 0; | |
588 | + break; | |
589 | + case 2: | |
590 | + //Sum between indexes | |
591 | + $dim1_min = !empty($paramData->{'dim1-min-index'}) ? $paramData->{'dim1-min-index'} : 0; | |
592 | + $dim1_max = !empty($paramData->{'dim1-max-index'}) ? $paramData->{'dim1-max-index'} : 0; | |
593 | + break; | |
594 | + } | |
595 | + } | |
596 | + | |
597 | + $dim2_is_range = (isset($paramData->{'dim2-sum-type'}) && ($paramData->{'dim2-sum-type'} > 0)); | |
598 | + $dim2_index = ($dim2_is_range || !isset($paramData->{'dim2-index'}) || ($paramData->{'dim2-index'} == '')) ? '*' : $paramData->{'dim2-index'}; | |
599 | + if ($dim2_is_range) { | |
600 | + switch ($paramData->{'dim2-sum-type'}) { | |
601 | + case 1: | |
602 | + //Sum between a range of value | |
603 | + $dim2_min = !empty($paramData->{'dim2-min-value'}) ? $paramData->{'dim2-min-value'} : 0; | |
604 | + $dim2_max = !empty($paramData->{'dim2-max-value'}) ? $paramData->{'dim2-max-value'} : 0; | |
605 | + break; | |
606 | + case 2: | |
607 | + //Sum between indexes | |
608 | + $dim2_min = !empty($paramData->{'dim2-min-index'}) ? $paramData->{'dim2-min-index'} : 0; | |
609 | + $dim2_max = !empty($paramData->{'dim2-max-index'}) ? $paramData->{'dim2-max-index'} : 0; | |
610 | + break; | |
611 | + } | |
612 | + } | |
613 | + | |
614 | + switch ($paramData->{'type'}) { | |
615 | + case 0: | |
616 | + //scalar - nothing to do | |
617 | + break; | |
618 | + case 1: | |
619 | + //Tab1D | |
620 | + if ($dim1_is_range) { | |
621 | + $template_args = array( | |
622 | + 'paramid' => $paramInfo['id'], | |
623 | + 'min' => $dim1_min, | |
624 | + 'max' => $dim1_max, | |
625 | + 'relateddim' => 0, | |
626 | + ); | |
627 | + if ($paramData->{'dim1-sum-type'} == 2) | |
628 | + $paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args); | |
629 | + else | |
630 | + $paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args); | |
631 | + } | |
632 | + else if ($dim2_is_range) { | |
633 | + $template_args = array( | |
634 | + 'paramid' => $paramInfo['id'], | |
635 | + 'min' => $dim2_min, | |
636 | + 'max' => $dim2_max, | |
637 | + 'relateddim' => 1, | |
638 | + ); | |
639 | + if ($paramData->{'dim2-sum-type'} == 2) | |
640 | + $paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args); | |
641 | + else | |
642 | + $paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args); | |
643 | + } | |
644 | + else if ($dim1_index != '*') { | |
645 | + $paramInfo['indexes'][] = $dim1_index; | |
646 | + } else if ($dim2_index != '*') { | |
647 | + $paramInfo['indexes'][] = $dim2_index; | |
648 | + } | |
649 | + break; | |
650 | + case 2: | |
651 | + //Tab2D | |
652 | + if ($dim1_is_range && $dim2_is_range) { | |
653 | + if ($paramData->{'dim1-sum-type'} != $paramData->{'dim2-sum-type'}) { | |
654 | + throw new Exception("Not supported - Dimensions ranges for " . $paramInfo['id'] . " must have the same type for each dimensions"); | |
655 | + } | |
656 | + $template_args = array( | |
657 | + 'paramid' => $paramInfo['id'], | |
658 | + 'min1' => $dim1_min, | |
659 | + 'max1' => $dim1_max, | |
660 | + 'relateddim1' => 0, | |
661 | + 'min2' => $dim2_min, | |
662 | + 'max2' => $dim2_max, | |
663 | + ); | |
664 | + if ($paramData->{'dim1-sum-type'} == 2) | |
665 | + $paramInfo = $this->addExistingParam('sum_into_table_indexes_2d', $paramsData, $template_args); | |
666 | + else | |
667 | + $paramInfo = $this->addExistingParam('sum_into_table_range_2d', $paramsData, $template_args); | |
668 | + } | |
669 | + else if ($dim1_is_range) { | |
670 | + $template_args = array( | |
671 | + 'paramid' => $paramInfo['id'], | |
672 | + 'min' => $dim1_min, | |
673 | + 'max' => $dim1_max, | |
674 | + 'relateddim' => 0, | |
675 | + ); | |
676 | + $tableLink = array( | |
677 | + 'paramid' => $paramInfo['id'], | |
678 | + 'relateddim' => 1, | |
679 | + ); | |
680 | + if ($paramData->{'dim1-sum-type'} == 2) | |
681 | + $paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args, $tableLink); | |
682 | + else | |
683 | + $paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args, $tableLink); | |
684 | + if ($dim2_index != '*') { | |
685 | + $paramInfo['indexes'][] = $dim2_index; | |
686 | + } | |
687 | + } else if ($dim2_is_range) { | |
688 | + $template_args = array( | |
689 | + 'paramid' => $paramInfo['id'], | |
690 | + 'min' => $dim2_min, | |
691 | + 'max' => $dim2_max, | |
692 | + 'relateddim' => 1, | |
693 | + ); | |
694 | + $tableLink = array( | |
695 | + 'paramid' => $paramInfo['id'], | |
696 | + 'relateddim' => 0, | |
697 | + ); | |
698 | + if ($paramData->{'dim2-sum-type'} == 2) | |
699 | + $paramInfo = $this->addExistingParam('sum_into_table_indexes', $paramsData, $template_args, $tableLink); | |
700 | + else | |
701 | + $paramInfo = $this->addExistingParam('sum_into_table_range', $paramsData, $template_args, $tableLink); | |
702 | + if ($dim1_index != '*') { | |
703 | + $paramInfo['indexes'][] = $dim1_index; | |
704 | + } | |
705 | + } else if (($dim1_index != '*') && ($dim2_index != '*')) { | |
706 | + $paramInfo['indexes'][] = "[" . $dim1_index . "," . $dim2_index . "]"; | |
707 | + } else if ($dim1_index != '*') { | |
708 | + $paramInfo['indexes'][] = "[" . $dim1_index . ",*]"; | |
709 | + } else if ($dim2_index != '*') { | |
710 | + $paramInfo['indexes'][] = "[*," . $dim2_index . "]"; | |
711 | + } else if ($force_total_2d) { | |
712 | + //total over 2 dims | |
713 | + $template_args = array( | |
714 | + 'paramid' => $paramInfo['id'], | |
715 | + ); | |
716 | + $paramInfo = $this->addExistingParam('total_2D', $paramsData, $template_args); | |
717 | + } | |
718 | + break; | |
719 | + } | |
720 | + } | |
721 | + | |
722 | + public function parseExpression($expression, $workingDir) { | |
723 | + $outputFileName = "parser_" . md5($expression) . ".xml"; | |
724 | + if (array_key_exists($outputFileName, $this->cacheExpressionParser)) { | |
725 | + return $this->cacheExpressionParser[$outputFileName]; | |
726 | + } | |
727 | + $parserData = new ParserRequestDataClass(); | |
728 | + $parserData->setManagerFilePath(IHMConfigClass::getProcessManagerFilePath()); | |
729 | + $parserData->addExpression($expression); | |
730 | + $parserData->setWorkingPath($workingDir); | |
731 | + $parserData->setLocalParamsPath(IHMConfigClass::getLocalParamDBPath()); | |
732 | + $parserData->setConstantsFilePath(IHMConfigClass::getConstantsFilePath()); | |
733 | + $parserData->setFunctionsFilePath(IHMConfigClass::getFunctionsFilePath()); | |
734 | + $parserData->setParamTemplatesFilePath(IHMConfigClass::getParamTemplateListFilePath()); | |
735 | + $parserData->setFunctionsArgsListFilePath(IHMConfigClass::getFunctionsArgsListFilePath()); | |
736 | + $parserData->setOutputFileName($outputFileName); | |
737 | + $resultFilePath = $workingDir . "/" . $outputFileName; | |
738 | + | |
739 | + $parserRequest = new ParserRequestClass(); | |
740 | + $parserRequest->setData($parserData); | |
741 | + | |
742 | + if (!$parserRequest->init() || !$parserRequest->run()) { | |
743 | + if (file_exists($resultFilePath)) { | |
744 | + unlink($resultFilePath); | |
745 | + } | |
746 | + return array('success' => FALSE, 'message' => 'Error to init or run expression parser'); | |
747 | + } | |
748 | + | |
749 | + //Load result file | |
750 | + $doc = new DOMDocument(); | |
751 | + $doc->load($resultFilePath); | |
752 | + if (!$doc->load($resultFilePath)) { | |
753 | + if (file_exists($resultFilePath)) { | |
754 | + unlink($resultFilePath); | |
755 | + } | |
756 | + return array('success' => FALSE, 'message' => 'Error to load parser result file'); | |
757 | + } | |
758 | + | |
759 | + $expressionNodes = $doc->getElementsByTagName('expression'); | |
760 | + if ($expressionNodes->length == 0) { | |
761 | + unlink($resultFilePath); | |
762 | + return array('success' => FALSE, 'message' => 'Cannot get expression nodes in parser result file'); | |
763 | + } | |
764 | + | |
765 | + $crtExpressionNode = NULL; | |
766 | + foreach ($expressionNodes as $expressionNode) { | |
767 | + $ihmExpressionNodes = $expressionNode->getElementsByTagName('ihm'); | |
768 | + if ($ihmExpressionNodes->length == 0) { | |
769 | + continue; | |
770 | + } | |
771 | + if ($ihmExpressionNodes->item(0)->nodeValue == $expression) { | |
772 | + $crtExpressionNode = $expressionNode; | |
773 | + break; | |
774 | + } | |
775 | + } | |
776 | + | |
777 | + if (!isset($crtExpressionNode)) { | |
778 | + unlink($resultFilePath); | |
779 | + return array('success' => FALSE, 'message' => 'Cannot retrieve expression in parser result file'); | |
780 | + } | |
781 | + | |
782 | + if ($crtExpressionNode->getAttribute('success') != "true") { | |
783 | + unlink($resultFilePath); | |
784 | + return array('success' => FALSE, 'message' => 'Synthax error in expression ' . $expression); | |
785 | + } | |
786 | + | |
787 | + $kernelExpressionNodes = $crtExpressionNode->getElementsByTagName('kernel'); | |
788 | + if ($kernelExpressionNodes->length == 0) { | |
789 | + unlink($resultFilePath); | |
790 | + return array('success' => FALSE, 'message' => 'Cannot retrieve kernel expression in parser result file'); | |
791 | + } | |
792 | + | |
793 | + $kernelExpression = $kernelExpressionNodes->item(0)->nodeValue; | |
794 | + | |
795 | + if (empty($kernelExpression)) { | |
796 | + unlink($resultFilePath); | |
797 | + return array('success' => FALSE, 'message' => 'Parser return an empty expression'); | |
798 | + } | |
799 | + | |
800 | + $params = array(); | |
801 | + $paramsNodes = $crtExpressionNode->getElementsByTagName('params'); | |
802 | + if ($paramsNodes->length != 0) { | |
803 | + $paramNodes = $paramsNodes->item(0)->getElementsByTagName('param'); | |
804 | + if ($paramNodes->length != 0) { | |
805 | + foreach ($paramNodes as $paramNode) { | |
806 | + if (!empty($paramNode->nodeValue)) { | |
807 | + $params[] = array( | |
808 | + 'paramid' => $paramNode->nodeValue | |
809 | + ); | |
810 | + } | |
811 | + } | |
812 | + } | |
813 | + } | |
814 | + | |
815 | + unlink($resultFilePath); | |
816 | + | |
817 | + if (empty($params)) { | |
818 | + return array('success' => FALSE, 'message' => 'Expression should contain at least one parameter'); | |
819 | + } | |
820 | + | |
821 | + foreach ($params as &$param) { | |
822 | + $templated_param = $this->templateParamsManager->parseTemplatedParam($param['paramid']); | |
823 | + if ($templated_param !== FALSE) { | |
824 | + $param = $templated_param; | |
825 | + } | |
826 | + } | |
827 | + | |
828 | + $this->cacheExpressionParser[$outputFileName] = array('success' => TRUE, 'expression' => $kernelExpression, 'params' => $params); | |
829 | + return $this->cacheExpressionParser[$outputFileName]; | |
830 | + } | |
831 | + | |
832 | + public function getTemplateParamsManager() { | |
833 | + return $this->templateParamsManager; | |
834 | + } | |
835 | + | |
850 | 836 | } | ... | ... |