Blame view

src/InputOutput/WSImpl/Params/PlotImpl/WSInputOutputParamsPlotClass.php 5.57 KB
1dc764e6   Elena.Budnik   getPlot partial c...
1
<?php
1dc764e6   Elena.Budnik   getPlot partial c...
2
3
4
5
6
7
8
9
/**
 * @class WSInputOutputParamsPlotClass
 * @brief Implementation of IHMInputOutputParamsAbstractClass to treat plot request
 * @details
*/
class WSInputOutputParamsPlotClass extends IHMInputOutputParamsAbstractClass
{
	/*
09dfbe39   Elena.Budnik   getPlot final + c...
10
	 * @brief Constructor
1dc764e6   Elena.Budnik   getPlot partial c...
11
	*/
09dfbe39   Elena.Budnik   getPlot final + c...
12
13
14
15
16
	function __construct()
	{
		$this->paramManager     = new IHMParamManagerClass();
		$this->jobsManager      = new WSJobsManagerClass();
	}	
131e60ff   Benjamin Renard   Implement real co...
17
18
19
20
21
22
23
24

	/*
	 * @brief Get Task
	 */
	protected function getTask($input)
	{
		return WSInputOutputClass::getService();
	}
1dc764e6   Elena.Budnik   getPlot partial c...
25
	
09dfbe39   Elena.Budnik   getPlot final + c...
26
27
28
	/*
	 * @brief method to unmarshall a plot request
	*/
1dc764e6   Elena.Budnik   getPlot partial c...
29
30
31
	protected function unmarshallRequest($input)
	{
		//Request
1dc764e6   Elena.Budnik   getPlot partial c...
32
33
34
		$postProcessCmd = "";
	 
		$requestNode = $this->paramsData->addRequestNode();
1dc764e6   Elena.Budnik   getPlot partial c...
35
36
37
38
		$outputsNode = $requestNode->getOutputsNode();
		$paramsNode  = $requestNode->getParamsNode();

		//unmarshall time definition
ddaf5ac2   Benjamin Renard   Fix WS plot request
39
		$this->unmarshallTimeDefinition($input, 0);
1dc764e6   Elena.Budnik   getPlot partial c...
40
41
42
	
		$plotOutputNode = $outputsNode->addNewOutput(RequestOutputTypeEnum::PLOT);
		$plotOutputNode->setWriteContextFile("false");
09dfbe39   Elena.Budnik   getPlot final + c...
43
		
1dc764e6   Elena.Budnik   getPlot partial c...
44
45
46
		$plotOutputNode->setStructure(RequestOutputPlotStructureEnum::ONE_FILE);
			
		//prefix
09dfbe39   Elena.Budnik   getPlot final + c...
47
48

		$filePrefix = "plot";
1dc764e6   Elena.Budnik   getPlot partial c...
49
50

		$plotOutputNode->setFilePrefix($filePrefix);
09dfbe39   Elena.Budnik   getPlot final + c...
51
	
1dc764e6   Elena.Budnik   getPlot partial c...
52
53
54
		//page
		$pageNode = $plotOutputNode->getPage();
		
1dc764e6   Elena.Budnik   getPlot partial c...
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
		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");
		
09dfbe39   Elena.Budnik   getPlot final + c...
89
90
		$parametersToPlot = $input->{'parameters'}; // one parameter on panel

1dc764e6   Elena.Budnik   getPlot partial c...
91
		$panelN = 1;
09dfbe39   Elena.Budnik   getPlot final + c...
92
		foreach ($parametersToPlot as $param)
1dc764e6   Elena.Budnik   getPlot partial c...
93
94
95
96
97
98
99
		{
			$panelNode = $pageNode->addPanel();
			$panelNode->setId($panelN);
			$panelNode->setIndex($panelN -1);
			$plotNode = $panelNode->addPlotElement(RequestOutputPlotElementTypeEnum::TIMEPLOT);
			
			//Axes
09dfbe39   Elena.Budnik   getPlot final + c...
100
101
			$timeAxisNode = $plotNode->getTimeAxis();
			$yAxisNode = $plotNode->addYAxis('y-left'); 
1dc764e6   Elena.Budnik   getPlot partial c...
102
103

			//Params
09dfbe39   Elena.Budnik   getPlot final + c...
104
			$this->unmarshallParams($param, $paramsNode, $plotNode, $panelNode);
1dc764e6   Elena.Budnik   getPlot partial c...
105
106
107
108
			$panelN++;
		}

		$resultFile = $filePrefix."_*".$extension;
09dfbe39   Elena.Budnik   getPlot final + c...
109
		$waitingResultFile = $input->{'result-file'}.$extension;
1dc764e6   Elena.Budnik   getPlot partial c...
110
	
09dfbe39   Elena.Budnik   getPlot final + c...
111
		$this->paramsData->addWaitingResult(WSInputOutputClass::getService(), $waitingResultFile);
1dc764e6   Elena.Budnik   getPlot partial c...
112
113
		
		//Post process command to apply to the result file
09dfbe39   Elena.Budnik   getPlot final + c...
114
		$postProcessCmd .= "mv ".$resultFile." ".WSConfigClass::getWsResultDir().$waitingResultFile;
1dc764e6   Elena.Budnik   getPlot partial c...
115

1dc764e6   Elena.Budnik   getPlot partial c...
116
117
118

		$this->paramsData->setBatchEnable(true);
		$this->paramsData->setPostCmd($postProcessCmd);
2c928626   Benjamin Renard   Add info to know ...
119
120

		$this->paramsData->setFromWS(true);
1dc764e6   Elena.Budnik   getPlot partial c...
121
122
123
124
125
		
		return $this->paramsData;
	}

	
09dfbe39   Elena.Budnik   getPlot final + c...
126
	protected function unmarshallParams($paramData, $requestParamsNode, $plotNode, $panelNode)
1dc764e6   Elena.Budnik   getPlot partial c...
127
128
	{
		//Main drawing element parameter
09dfbe39   Elena.Budnik   getPlot final + c...
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
		$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");
1dc764e6   Elena.Budnik   getPlot partial c...
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
		}
	}
	
		
	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);
	}
09dfbe39   Elena.Budnik   getPlot final + c...
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
	
	/*
	* @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,
131e60ff   Benjamin Renard   Implement real co...
179
180
				$data->getErrorCode(),
				$data->getExecTime()); 
09dfbe39   Elena.Budnik   getPlot final + c...
181
182
	}
	
1dc764e6   Elena.Budnik   getPlot partial c...
183
184
185
186
187
	/*
	 * @brief method to marshall the result of a download request
	*/
	protected function marshallResult($data)
	{
09dfbe39   Elena.Budnik   getPlot final + c...
188
189
190
191
		if (!$data->getSuccess())
			return array(
					'success' => false,
					'message' => $data->getLastErrorMessage());
1dc764e6   Elena.Budnik   getPlot partial c...
192

09dfbe39   Elena.Budnik   getPlot final + c...
193
194
195
196
197
198
199
200
201
202
203
		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');
		}
1dc764e6   Elena.Budnik   getPlot partial c...
204
205
206
	}
}
?>