예제 #1
0
파일: API.php 프로젝트: neolf/PIWIK4MOBILE
 /**
  * Utility function used by getAll. Performs a binary filter of two
  * DataTables in order to correctly calculate evolution metrics.
  * 
  * @param Piwik_DataTable|Piwik_DataTable_Array $currentData
  * @param Piwik_DataTable|Piwik_DataTable_Array $pastData
  * @param array $fields The array of string fields to calculate evolution
  *                      metrics for.
  */
 private function calculateEvolutionPercentages($currentData, $pastData, $fields)
 {
     if ($currentData instanceof Piwik_DataTable_Array) {
         $pastArray = $pastData->getArray();
         foreach ($currentData->getArray() as $label => $subTable) {
             $this->calculateEvolutionPercentages($subTable, current($pastArray), $fields);
             next($pastArray);
         }
     } else {
         foreach ($fields as $field) {
             $currentData->filter('Piwik_MultiSites_CalculateEvolutionFilter', array($pastData, $this->evolutionColumnNames[$field], $field, $quotientPrecision = 2));
         }
     }
 }
예제 #2
0
 /**
  * Enhance a $dataTable using metadata :
  *
  * - remove metrics based on $reportMetadata['metrics']
  * - add 0 valued metrics if $dataTable doesn't provide all $reportMetadata['metrics']
  * - format metric values to a 'human readable' format
  * - extract row metadata to a separate Piwik_DataTable_Simple|Piwik_DataTable_Array : $rowsMetadata
  * - translate metric names to a separate array : $columns
  *
  * @param int $idSite enables monetary value formatting based on site currency
  * @param Piwik_DataTable|Piwik_DataTable_Array $dataTable
  * @param array $reportMetadata
  * @param boolean $hasDimension
  * @return array Piwik_DataTable_Simple|Piwik_DataTable_Array $newReport with human readable format & array $columns list of translated column names & Piwik_DataTable_Simple|Piwik_DataTable_Array $rowsMetadata
  **/
 private function handleTableReport($idSite, $dataTable, &$reportMetadata, $hasDimension)
 {
     $columns = $reportMetadata['metrics'];
     if ($hasDimension) {
         $columns = array_merge(array('label' => $reportMetadata['dimension']), $columns);
         if (isset($reportMetadata['processedMetrics'])) {
             $processedMetricsAdded = $this->getDefaultProcessedMetrics();
             foreach ($processedMetricsAdded as $processedMetricId => $processedMetricTranslation) {
                 // this processed metric can be displayed for this report
                 if (isset($reportMetadata['processedMetrics'][$processedMetricId])) {
                     $columns[$processedMetricId] = $processedMetricTranslation;
                 }
             }
         }
         // Display the global Goal metrics
         if (isset($reportMetadata['metricsGoal'])) {
             $metricsGoalDisplay = array('revenue');
             // Add processed metrics to be displayed for this report
             foreach ($metricsGoalDisplay as $goalMetricId) {
                 if (isset($reportMetadata['metricsGoal'][$goalMetricId])) {
                     $columns[$goalMetricId] = $reportMetadata['metricsGoal'][$goalMetricId];
                 }
             }
         }
         if (isset($reportMetadata['processedMetrics'])) {
             // Add processed metrics
             $dataTable->filter('AddColumnsProcessedMetrics', array($deleteRowsWithNoVisit = false));
         }
     }
     // $dataTable is an instance of Piwik_DataTable_Array when multiple periods requested
     if ($dataTable instanceof Piwik_DataTable_Array) {
         // Need a new Piwik_DataTable_Array to store the 'human readable' values
         $newReport = new Piwik_DataTable_Array();
         $newReport->setKeyName("prettyDate");
         $dataTableMetadata = $dataTable->metadata;
         $newReport->metadata = $dataTableMetadata;
         // Need a new Piwik_DataTable_Array to store report metadata
         $rowsMetadata = new Piwik_DataTable_Array();
         $rowsMetadata->setKeyName("prettyDate");
         // Process each Piwik_DataTable_Simple entry
         foreach ($dataTable->getArray() as $label => $simpleDataTable) {
             list($enhancedSimpleDataTable, $rowMetadata) = $this->handleSimpleDataTable($idSite, $simpleDataTable, $columns, $hasDimension);
             $period = $dataTableMetadata[$label]['period']->getLocalizedLongString();
             $newReport->addTable($enhancedSimpleDataTable, $period);
             $rowsMetadata->addTable($rowMetadata, $period);
         }
     } else {
         list($newReport, $rowsMetadata) = $this->handleSimpleDataTable($idSite, $dataTable, $columns, $hasDimension);
     }
     return array($newReport, $columns, $rowsMetadata);
 }
예제 #3
0
파일: API.php 프로젝트: nnnnathann/piwik
 /**
  * Performs a binary filter of two
  * DataTables in order to correctly calculate evolution metrics.
  * 
  * @param Piwik_DataTable|Piwik_DataTable_Array $currentData
  * @param Piwik_DataTable|Piwik_DataTable_Array $pastData
  * @param array $fields The array of string fields to calculate evolution
  *                      metrics for.
  */
 private function calculateEvolutionPercentages($currentData, $pastData, $apiMetrics)
 {
     if ($currentData instanceof Piwik_DataTable_Array) {
         $pastArray = $pastData->getArray();
         foreach ($currentData->getArray() as $subTable) {
             $this->calculateEvolutionPercentages($subTable, current($pastArray), $apiMetrics);
             next($pastArray);
         }
     } else {
         foreach ($apiMetrics as $metricSettings) {
             $currentData->filter('Piwik_MultiSites_CalculateEvolutionFilter', array($pastData, $metricSettings[self::METRIC_EVOLUTION_COL_NAME_KEY], $metricSettings[self::METRIC_RECORD_NAME_KEY], $quotientPrecision = 2));
         }
     }
 }