WSInputOutputParamsPlotClass.php
5.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
/**
* @class WSInputOutputParamsPlotClass
* @brief Implementation of IHMInputOutputParamsAbstractClass to treat plot request
* @details
*/
class WSInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass
{
/*
* @brief Constructor
*/
function __construct()
{
$this->paramManager = new IHMParamManagerClass();
$this->jobsManager = new WSJobsManagerClass();
}
/*
* @brief Get Task
*/
protected function getTask($input)
{
return WSInputOutputClass::getService();
}
/*
* @brief method to unmarshall a plot request
*/
protected function unmarshallRequest($input)
{
//Request
$postProcessCmd = "";
$requestNode = $this->paramsData->addRequestNode();
$outputsNode = $requestNode->getOutputsNode();
$paramsNode = $requestNode->getParamsNode();
//unmarshall time definition
$this->unmarshallTimeDefinition($input, 0);
$plotOutputNode = $outputsNode->addNewOutput(RequestOutputTypeEnum::PLOT);
$plotOutputNode->setWriteContextFile("false");
$plotOutputNode->setStructure(RequestOutputPlotStructureEnum::ONE_FILE);
//prefix
$filePrefix = "plot";
$plotOutputNode->setFilePrefix($filePrefix);
//page
$pageNode = $plotOutputNode->getPage();
switch ($input->{'file-format'})
{
case 'PNG' :
$fileFormat = RequestOutputPlotPageFormatEnum::PNG;
$extension = ".png";
break;
case 'PDF' :
$fileFormat = RequestOutputPlotPageFormatEnum::PDF;
$extension = ".pdf";
break;
case 'PS' :
$fileFormat = RequestOutputPlotPageFormatEnum::PS;
$extension = ".ps";
break;
case 'SVG' :
$fileFormat = RequestOutputPlotPageFormatEnum::SVG;
$extension = ".svg";
break;
default:
throw new Exception('File format not implemented.');
}
$pageNode->setFormat($fileFormat);
$pageNode->setOrientation(RequestOutputPlotPageOrientationEnum::LANDSCAPE);
$pageNode->setDimension(RequestOutputPlotPageDimensionEnum::ISO_A4);
$pageNode->setMode(RequestOutputPlotPageModeEnum::COLOR);
// Layout
$pageNode->getLayout()->setType(RequestOutputPlotLayoutTypeEnum::VERTICAL);
$pageNode->getLayout()->setPanelHeight("0.5");
$pageNode->getLayout()->setPanelSpacing("0");
$pageNode->getLayout()->setExpand("false"); // true ?
$pageNode->getLayout()->setOnlyLowerTimeAxesLegend("true");
$parametersToPlot = $input->{'parameters'}; // one parameter on panel
$panelN = 1;
foreach ($parametersToPlot as $param)
{
$panelNode = $pageNode->addPanel();
$panelNode->setId($panelN);
$panelNode->setIndex($panelN -1);
$plotNode = $panelNode->addPlotElement(RequestOutputPlotElementTypeEnum::TIMEPLOT);
//Axes
$timeAxisNode = $plotNode->getTimeAxis();
$yAxisNode = $plotNode->addYAxis('y-left');
//Params
$this->unmarshallParams($param, $paramsNode, $plotNode, $panelNode);
$panelN++;
}
$resultFile = $filePrefix."_*".$extension;
$waitingResultFile = $input->{'result-file'}.$extension;
$this->paramsData->addWaitingResult(WSInputOutputClass::getService(), $waitingResultFile);
//Post process command to apply to the result file
$postProcessCmd .= "mv ".$resultFile." ".WSConfigClass::getWsResultDir().$waitingResultFile;
$this->paramsData->setBatchEnable(true);
$this->paramsData->setPostCmd($postProcessCmd);
$this->paramsData->setFromWS(true);
return $this->paramsData;
}
protected function unmarshallParams($paramData, $requestParamsNode, $plotNode, $panelNode)
{
//Main drawing element parameter
$paramInfo = $this->paramManager->addExistingParam($paramData->{'paramid'}, $this->paramsData, NULL);
$requestParamsNode->addParam($paramInfo['id']);
$paramNode = $plotNode->getParams()->getParamById($paramInfo['id']);
$serieNode = $paramNode->addYSerie('y-left', -1);
$serieNode->setId('1');
$lineNode = $serieNode->getLine();
$lineNode->setType(RequestOutputPlotLineTypeEnum::LINE);
if ($this->isVector($paramInfo['id'])) { // vector - activate legend
$paramLegendNode = $plotNode->getLegends()->getParamsLegend();
$paramLegendNode->setType(RequestOutputPlotParamsLegendTypeEnum::TEXTONLY);
$paramLegendNode->setShowParamInfo("true");
$paramLegendNode->setShowIntervalInfo("false");
$paramLegendNode->setPosition("outside");
}
}
protected function isVector($paramId)
{
$paramPath = IHMConfigClass::getLocalParamDBPath().$paramId.".xml";
$dom = new DomDocument("1.0");
if (!@$dom->load($paramPath))
return false;
// TODO use tensor_order
$components = $dom->getElementsByTagName("components")->item(0)->nodeValue;
$arr = explode(",",$components);
return (count($arr) == 3);
}
/*
* @brief Add a job to the job manager
*/
protected function addToJobsFile($data,$resultKey)
{
$waitingResult = $data->getWaitingResult($resultKey);
return $this->jobsManager->addJob(
$this->input,
$data->getId(),
$this->getWorkingDirName(),
$data->getStatus() == ProcessStatusEnumClass::RUNNING,
$data->getStart(),
$waitingResult,
$data->getErrorCode(),
$data->getExecTime());
}
/*
* @brief method to marshall the result of a download request
*/
protected function marshallResult($data)
{
if (!$data->getSuccess())
return array(
'success' => false,
'message' => $data->getLastErrorMessage());
switch ($data->getStatus())
{
case ProcessStatusEnumClass::ERROR :
case ProcessStatusEnumClass::RUNNING :
case ProcessStatusEnumClass::DONE :
return $this->addToJobsFile($data, WSInputOutputClass::getService());
default :
return array(
'success' => false,
'message' => 'Unknown Process Status');
}
}
}
?>