Commit 988817373d1ddf66f578e326163f3ff35962eed4
1 parent
49311864
Exists in
master
and in
66 other branches
Add post processing for a plot request
Showing
2 changed files
with
66 additions
and
18 deletions
Show diff stats
src/InputOutput/IHMImpl/Params/PlotImpl/IHMInputOutputParamsPlotClass.php
... | ... | @@ -9,6 +9,8 @@ define ("PLOT_RESULT_FILE_KEY","plot"); |
9 | 9 | */ |
10 | 10 | class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass |
11 | 11 | { |
12 | + private $isInteractiveRequest = false; | |
13 | + | |
12 | 14 | /* |
13 | 15 | * @brief method to unmarshall a plot request |
14 | 16 | */ |
... | ... | @@ -19,6 +21,8 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass |
19 | 21 | |
20 | 22 | //Request |
21 | 23 | $requestIndex = 0; |
24 | + $this->isInteractiveRequest = ($input->{'file-output'} == 'INTERACTIVE'); | |
25 | + $postProcessCmd = ""; | |
22 | 26 | foreach ($input->tabs as $tab) |
23 | 27 | { |
24 | 28 | $requestNode = $this->paramsData->addRequestNode(); |
... | ... | @@ -29,15 +33,23 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass |
29 | 33 | |
30 | 34 | $plotOutputNode = $outputsNode->addNewOutput(RequestOutputTypeEnum::PLOT); |
31 | 35 | |
32 | - switch ($input->{'file-output'}) | |
36 | + $compression = ""; | |
37 | + if (!$this->isInteractiveRequest) | |
33 | 38 | { |
34 | - case 'TGZ' : | |
35 | - $plotOutputNode->addPostProcessing(RequestOutputPostProcessingEnumClass::TAR); | |
36 | - $plotOutputNode->addPostProcessing(RequestOutputPostProcessingEnumClass::GZIP); | |
37 | - break; | |
38 | - case 'ZIP' : | |
39 | - $plotOutputNode->addPostProcessing(RequestOutputPostProcessingEnumClass::ZIP); | |
40 | - break; | |
39 | + switch ($input->{'file-output'}) | |
40 | + { | |
41 | + case 'TGZ' : | |
42 | + $plotOutputNode->addPostProcessing(RequestOutputPostProcessingEnumClass::TAR); | |
43 | + $plotOutputNode->addPostProcessing(RequestOutputPostProcessingEnumClass::GZIP); | |
44 | + $compression = ".tar.gz"; | |
45 | + break; | |
46 | + case 'ZIP' : | |
47 | + $plotOutputNode->addPostProcessing(RequestOutputPostProcessingEnumClass::ZIP); | |
48 | + $compression = ".zip"; | |
49 | + break; | |
50 | + default: | |
51 | + throw new Exception('Compression not implemented.'); | |
52 | + } | |
41 | 53 | } |
42 | 54 | |
43 | 55 | if ($input->{'one-file-per-interval'}) |
... | ... | @@ -46,10 +58,8 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass |
46 | 58 | $plotOutputNode->setStructure(RequestOutputPlotStructureEnum::ONE_FILE); |
47 | 59 | |
48 | 60 | //prefix |
49 | - $filePrefix = ""; | |
50 | - if ($input->{'file-prefix'} == "") | |
51 | - $filePrefix = "plot"; | |
52 | - else | |
61 | + $filePrefix = "plot"; | |
62 | + if ($input->{'file-prefix'} && ($input->{'file-prefix'} != "")) | |
53 | 63 | $filePrefix = $input->{'file-prefix'}; |
54 | 64 | $filePrefix .= $requestIndex; |
55 | 65 | |
... | ... | @@ -59,19 +69,24 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass |
59 | 69 | $pageNode = $plotOutputNode->getPage(); |
60 | 70 | |
61 | 71 | $fileFormat = RequestOutputPlotPageFormatEnum::PNG; |
72 | + $extension = ".png"; | |
62 | 73 | switch ($input->{'file-format'}) |
63 | 74 | { |
64 | 75 | case 'PNG' : |
65 | 76 | $fileFormat = RequestOutputPlotPageFormatEnum::PNG; |
77 | + $extension = ".png"; | |
66 | 78 | break; |
67 | 79 | case 'PDF' : |
68 | 80 | $fileFormat = RequestOutputPlotPageFormatEnum::PDF; |
81 | + $extension = ".pdf"; | |
69 | 82 | break; |
70 | 83 | case 'PS' : |
71 | 84 | $fileFormat = RequestOutputPlotPageFormatEnum::PS; |
85 | + $extension = ".ps"; | |
72 | 86 | break; |
73 | 87 | case 'SVG' : |
74 | 88 | $fileFormat = RequestOutputPlotPageFormatEnum::SVG; |
89 | + $extension = ".svg"; | |
75 | 90 | break; |
76 | 91 | default: |
77 | 92 | throw new Exception('File format not implemented.'); |
... | ... | @@ -81,6 +96,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass |
81 | 96 | |
82 | 97 | $this->unmarshallTitle($tab, 'page-title', $pageNode->getTitle()); |
83 | 98 | |
99 | + $isPortrait = false; | |
84 | 100 | switch ($tab->{'page-orientation'}) |
85 | 101 | { |
86 | 102 | case 'landscape' : |
... | ... | @@ -88,6 +104,7 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass |
88 | 104 | break; |
89 | 105 | case 'portrait' : |
90 | 106 | $pageNode->setOrientation(RequestOutputPlotPageOrientationEnum::PORTRAIT); |
107 | + $isPortrait = true; | |
91 | 108 | break; |
92 | 109 | } |
93 | 110 | |
... | ... | @@ -126,10 +143,37 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass |
126 | 143 | |
127 | 144 | $pageNode->getLayout()->setType(RequestOutputPlotLayoutTypeEnum::VERTICAL); |
128 | 145 | |
146 | + if ($this->isInteractiveRequest) | |
147 | + { | |
148 | + $resultFile = $filePrefix."_*".$extension; | |
149 | + $waitingResultFile = $filePrefix.$extension; | |
150 | + } | |
151 | + else | |
152 | + { | |
153 | + $resultFile = $filePrefix."_*".$compression; | |
154 | + $waitingResultFile = $filePrefix.$compression; | |
155 | + } | |
156 | + | |
157 | + $this->paramsData->addWaitingResult(PLOT_RESULT_FILE_KEY."_".$requestIndex, $waitingResultFile); | |
158 | + | |
159 | + //Remove old result files | |
160 | + foreach (glob($this->paramsData->getWorkingPath().$resultFile) as $oldFile) { | |
161 | + unlink($oldFile); | |
162 | + } | |
163 | + | |
164 | + //Post process command to apply to the result file | |
165 | + if ($postProcessCmd != "") | |
166 | + $postProcessCmd .= " | "; | |
167 | + $postProcessCmd .= "mv ".$resultFile." ".$waitingResultFile; | |
168 | + | |
169 | + if ($this->isInteractiveRequest && $isPortrait) | |
170 | + $postProcessCmd .= " | convert ".$resultFile." -rotate -90 ".$resultFile; | |
171 | + | |
129 | 172 | ++$requestIndex; |
130 | 173 | } |
131 | 174 | |
132 | - $this->paramsData->setBatchEnable(!(($fileFormat == RequestOutputPlotPageFormatEnum::PNG) && ($input->{'file-output'} == 'INTERACTIVE'))); | |
175 | + $this->paramsData->setBatchEnable(!(($fileFormat == RequestOutputPlotPageFormatEnum::PNG) && $this->isInteractiveRequest)); | |
176 | + $this->paramsData->setPostCmd($postProcessCmd); | |
133 | 177 | |
134 | 178 | //determine extension and add post processing if needed |
135 | 179 | return $this->paramsData; |
... | ... | @@ -220,10 +264,10 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass |
220 | 264 | */ |
221 | 265 | protected function marshallResult($data) |
222 | 266 | { |
223 | - if (!$this->isInterractive) | |
267 | + if (!$this->isInteractiveRequest) | |
224 | 268 | { |
225 | 269 | //add to job |
226 | - $commonRes = $this->commonMarshallResult($data,PLOT_RESULT_FILE_KEY); | |
270 | + $commonRes = $this->commonMarshallResult($data,PLOT_RESULT_FILE_KEY."_0"); | |
227 | 271 | |
228 | 272 | return $commonRes; |
229 | 273 | } |
... | ... | @@ -235,12 +279,12 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass |
235 | 279 | |
236 | 280 | switch ($data->getStatus()) |
237 | 281 | { |
238 | - case ProcessStatusEnumClass::DONE : | |
282 | + case ProcessStatusEnumClass::DONE : | |
239 | 283 | return array( |
240 | 284 | 'success' => true, |
241 | 285 | 'id' => $data->getId(), |
242 | 286 | 'folder' => $this->getWorkingDirName(), |
243 | - 'result' => $data->getWaitingResult(PLOT_RESULT_FILE_KEY), | |
287 | + 'result' => $data->getWaitingResults(), | |
244 | 288 | 'format' => 'PNG', |
245 | 289 | 'compression' => 'unknown', |
246 | 290 | 'status' => 'done', |
... | ... | @@ -252,7 +296,6 @@ class IHMInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass |
252 | 296 | "umax" => "1" |
253 | 297 | ) |
254 | 298 | ), |
255 | - 'tabId' => $this->currentTabId, | |
256 | 299 | 'startDate' => $this->startTime, |
257 | 300 | 'stopDate' => $this->stopTime |
258 | 301 | ); |
... | ... |
src/Request/ParamsRequestImpl/ParamsRequestDataClass.php
... | ... | @@ -76,6 +76,11 @@ class ParamsRequestDataClass extends ProcessRequestDataClass |
76 | 76 | return $this->requestNodes; |
77 | 77 | } |
78 | 78 | |
79 | + public function getWaitingResults() | |
80 | + { | |
81 | + return $this->waitingResults; | |
82 | + } | |
83 | + | |
79 | 84 | public function getWaitingResult($key) |
80 | 85 | { |
81 | 86 | return $this->waitingResults[$key]; |
... | ... |