diff --git a/plugins/Insights/DataTable/Filter/Average.php b/plugins/Insights/DataTable/Filter/Average.php deleted file mode 100644 index 5c13095b15c633034afe3453b4e3f605e313af1f..0000000000000000000000000000000000000000 --- a/plugins/Insights/DataTable/Filter/Average.php +++ /dev/null @@ -1,38 +0,0 @@ -<?php -/** - * Piwik - Open source web analytics - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - * - */ -namespace Piwik\Plugins\Insights\DataTable\Filter; - -use Piwik\DataTable; - -class Average extends DataTable\BaseFilter -{ - private $divisor; - - public function __construct($table, $columnToRead, $divisor) - { - $this->columnToRead = $columnToRead; - $this->divisor = $divisor; - } - - public function filter($table) - { - if (!$this->divisor) { - return; - } - - foreach ($table->getRows() as $row) { - - $value = $row->getColumn($this->columnToRead); - - if (false !== $value && is_numeric($value)) { - $row->setColumn($this->columnToRead, round($value / $this->divisor)); - } - } - } -} \ No newline at end of file diff --git a/plugins/Insights/tests/FilterAverageTest.php b/plugins/Insights/tests/FilterAverageTest.php deleted file mode 100644 index 302cd2e23250cf54bf140aed9c71ec1a7cd6de6c..0000000000000000000000000000000000000000 --- a/plugins/Insights/tests/FilterAverageTest.php +++ /dev/null @@ -1,77 +0,0 @@ -<?php -/** - * Piwik - Open source web analytics - * - * @link http://piwik.org - * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later - */ - -namespace Piwik\Plugins\Insights\tests; - -use Piwik\DataTable; -use Piwik\DataTable\Row; -use Piwik\Plugins\Insights\DataTable\Filter\Average; - -/** - * @group Insights - * @group FilterAverageTest - * @group Unit - * @group Core - */ -class FilterAverageTest extends BaseUnitTest -{ - public function setUp() - { - $this->table = new DataTable(); - $this->table->addRowsFromArray(array( - array(Row::COLUMNS => array('label' => 'val1', 'growth' => 22)), - array(Row::COLUMNS => array('label' => 'val2', 'growth' => 14)), - array(Row::COLUMNS => array('label' => 'val3', 'growth' => 18)), - array(Row::COLUMNS => array('label' => 'val4', 'growth' => 20)), - array(Row::COLUMNS => array('label' => 'val5', 'growth' => 25)), - array(Row::COLUMNS => array('label' => 'val6', 'growth' => 17)), - array(Row::COLUMNS => array('label' => 'val7', 'growth' => 0)), - array(Row::COLUMNS => array('label' => 'val8', 'growth' => 4)), - array(Row::COLUMNS => array('label' => 'val9', 'growth' => -4)), - array(Row::COLUMNS => array('label' => 'val10', 'growth' => null)), - array(Row::COLUMNS => array('label' => 'val11', 'growth' => false)), - )); - } - - public function testShouldNotChangeAnythingIfAverageIsZeroOrOne() - { - $rowsBefore = $this->table->getRows(); - - $this->calculateAverage(0); - $this->assertSame($rowsBefore, $this->table->getRows()); - - $this->calculateAverage(1); - $this->assertSame($rowsBefore, $this->table->getRows()); - } - - public function testShouldDivideNumericValuesByDivisorAndRound() - { - $this->calculateAverage(4); - - $this->assertColumnValues(array( - array('label' => 'val1', 'growth' => 6), - array('label' => 'val2', 'growth' => 4), - array('label' => 'val3', 'growth' => 5), - array('label' => 'val4', 'growth' => 5), - array('label' => 'val5', 'growth' => 6), - array('label' => 'val6', 'growth' => 4), - array('label' => 'val7', 'growth' => 0), - array('label' => 'val8', 'growth' => 1), - array('label' => 'val9', 'growth' => -1), - array('label' => 'val10', 'growth' => null), - array('label' => 'val11', 'growth' => false), - )); - } - - private function calculateAverage($divisor) - { - $filter = new Average($this->table, 'growth', $divisor); - $filter->filter($this->table); - } - -}