IHMInputOutputParamsStatisticsClass.php 2.46 KB
<?php

define ("STATISTICS_RESULT_FILE_KEY", "statistic");

/**
 * @class IHMInputOutputParamsStatisticsClass
 * @brief Implementation of IHMInputOutputParamsAbstractClass to treat catalog generation request
 * @details
*/
class IHMInputOutputParamsStatisticsClass extends IHMInputOutputParamsAbstractClass
{
	/*
	 * @brief method to unmarshall a catalog generation request
	*/
	protected function unmarshallRequest($input)
	{
		/*
		   {"id":"","timesrc":"TimeTable","name":"test","created":null,"description":"first","objName":"","objFormat":"","folderId":"","nbIntervals":0,"cacheToken":"","parameter":[{"param":"imf_gsm","function":"min"},{"param":"imf_mag","function":"max"}],"timeTables":[{"id":"sharedtt_26"},{"id":"sharedtt_27"}],"leaf":true,"nodeType":"catalog"}]'
		 */
		$requestNode = $this->paramsData->addRequestNode();

		$paramsNode = $requestNode->getParamsNode();

		//unmarshall time definition
		$this->unmarshallTimeDefinition($input);

		//unmarshall statistic output definition
		$outputsNode = $requestNode->getOutputsNode();
		$catalogNode = $outputsNode->addNewOutput(RequestOutputTypeEnum::STATISTIC);
		$catalogNode->setTimeFormat(RequestOutputStatisticTimeFormatEnum::ISO);
		$catalogNode->setFileFormat(RequestOutputStatisticFileFormatEnum::XML);
		
		// parse parameters / functions array                       
                foreach ($input->parameter as $obj) { 
                   $paramFunctionAssociation[$obj->param][] = $obj->function;                
                }
                
                foreach ($paramFunctionAssociation as $param => $functions) {
                     $paramsNode->addParam($param);
                     $outputParamNode = $catalogNode->addParam($param);
                     foreach ($functions as $function) $outputParamNode->addFunction($function);
                     $paramInfo = $this->paramManager->addExistingParam($param,$this->paramsData);
                } 

 		$resultFile = "result_".$this->requestID;
		$this->paramsData->addWaitingResult(STATISTICS_RESULT_FILE_KEY, $resultFile);
// 
		$postProcessCmd  = "mv statistic-*";
		$postProcessCmd .= " ".$resultFile.".xml";
 
// 
		$this->paramsData->setPostCmd($postProcessCmd);
 		return $this->paramsData;
	}

	/*
	 * @brief method to marshall the result of a catalog generation request
	*/
	protected function marshallResult($data)
	{
		return $this->commonMarshallResult($data,STATISTICS_RESULT_FILE_KEY);
	}
}
?>