コード例 #1
0
ファイル: MetricsTest.php プロジェクト: mgou-net/piwik
 /**
  * @dataProvider getUnitColumns
  * @group Core
  */
 public function testGetUnit($column, $expected)
 {
     Site::setSites(array(1 => array('name' => 'TestSite', 'currency' => 'EUR')));
     FakeAccess::$superUser = true;
     $actual = Metrics::getUnit($column, 1);
     $this->assertEquals($expected, $actual);
 }
コード例 #2
0
ファイル: MetricsTest.php プロジェクト: a4tunado/piwik
 /**
  * @dataProvider getUnitColumns
  * @group Core
  */
 public function testGetUnit($column, $expected)
 {
     \Piwik\Site::setSites(array(1 => array('name' => 'TestSite', 'currency' => 'EUR')));
     $pseudoMockAccess = new FakeAccess();
     FakeAccess::$superUser = true;
     Access::setSingletonInstance($pseudoMockAccess);
     $actual = Metrics::getUnit($column, 1);
     $this->assertEquals($expected, $actual);
 }
コード例 #3
0
 private function deriveUnitsFromRequestedColumnNames()
 {
     $idSite = Common::getRequestVar('idSite', null, 'int');
     $units = array();
     foreach ($this->properties['columns_to_display'] as $columnName) {
         $derivedUnit = Metrics::getUnit($columnName, $idSite);
         $units[$columnName] = empty($derivedUnit) ? false : $derivedUnit;
     }
     return $units;
 }
コード例 #4
0
 /**
  * Prepare metrics toggles with spark lines
  * @return array
  */
 protected function getMetricsToggles()
 {
     $i = 0;
     $metrics = array();
     foreach ($this->availableMetrics as $metric => $metricData) {
         $unit = Metrics::getUnit($metric, $this->idSite);
         $change = isset($metricData['change']) ? $metricData['change'] : false;
         list($first, $last) = $this->getFirstAndLastDataPointsForMetric($metric);
         $details = Piwik::translate('RowEvolution_MetricBetweenText', array(NumberFormatter::getInstance()->format($first), NumberFormatter::getInstance()->format($last)));
         if ($change !== false) {
             $lowerIsBetter = Metrics::isLowerValueBetter($metric);
             if (substr($change, 0, 1) == '+') {
                 $changeClass = $lowerIsBetter ? 'bad' : 'good';
                 $changeImage = $lowerIsBetter ? 'arrow_up_red' : 'arrow_up';
             } else {
                 if (substr($change, 0, 1) == '-') {
                     $changeClass = $lowerIsBetter ? 'good' : 'bad';
                     $changeImage = $lowerIsBetter ? 'arrow_down_green' : 'arrow_down';
                 } else {
                     $changeClass = 'neutral';
                     $changeImage = false;
                 }
             }
             $change = '<span class="' . $changeClass . '">' . ($changeImage ? '<img src="plugins/MultiSites/images/' . $changeImage . '.png" /> ' : '') . $change . '</span>';
             $details .= ', ' . Piwik::translate('RowEvolution_MetricChangeText', $change);
         }
         // set metric min/max text (used as tooltip for details)
         $max = isset($metricData['max']) ? $metricData['max'] : 0;
         $min = isset($metricData['min']) ? $metricData['min'] : 0;
         $min .= $unit;
         $max .= $unit;
         $minmax = Piwik::translate('RowEvolution_MetricMinMax', array($metricData['name'], NumberFormatter::getInstance()->formatNumber($min), NumberFormatter::getInstance()->formatNumber($max)));
         $newMetric = array('label' => $metricData['name'], 'details' => $details, 'minmax' => $minmax, 'sparkline' => $this->getSparkline($metric));
         // Multi Rows, each metric can be for a particular row and display an icon
         if (!empty($metricData['logo'])) {
             $newMetric['logo'] = $metricData['logo'];
         }
         // TODO: this check should be determined by metric metadata, not hardcoded here
         if ($metric == 'nb_users' && $first == 0 && $last == 0) {
             $newMetric['hide'] = true;
         }
         $metrics[] = $newMetric;
         $i++;
     }
     return $metrics;
 }