-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Proportional evolution comparison for incomplete periods (#18099)
* Multisite evolution metrics changed to calculate proportionally to percent of the current period which is complete * Use piwik date class, use report generated date if available, added unit test, added tooltip * Improved tooltip detail * Updated unit tested, added tests for evolution metric getRatio(), changes to allow row metadata to be preserved during datatable merges * Additional API test fixes * More test fixes * More test fixes * Remove ts_archived row metadata from final API output * Test fix reversions, added deleteRowsMetadata() method to DataTableInterface * More test fix reversions * Fixed integration test * Trigger Build * Update core/DataTable/Map.php Co-authored-by: Stefan Giehl <[email protected]> * Update core/DataTable.php Co-authored-by: Stefan Giehl <[email protected]> * Update core/Archive/DataCollection.php Co-authored-by: Stefan Giehl <[email protected]> * Update core/DataTable.php Co-authored-by: Stefan Giehl <[email protected]> * Update core/DataTable.php Co-authored-by: Stefan Giehl <[email protected]> * Update plugins/CoreHome/Columns/Metrics/EvolutionMetric.php Co-authored-by: Stefan Giehl <[email protected]> * Improved tooltips for translation, use NumberFormatter for percents, moved additional constructor param to end, null checks * Update plugins/CoreHome/Columns/Metrics/EvolutionMetric.php Co-authored-by: Stefan Giehl <[email protected]> * Update plugins/CoreHome/Columns/Metrics/EvolutionMetric.php Co-authored-by: Stefan Giehl <[email protected]> * Use localized period string, remove unnecessary tooltip percent digits * Formatting fixes * Fix for an issue where evolution values > 999% would be displayed incorrectly * Added data table processor option to provide raw copy of formatted metrics * Update plugins/MultiSites/API.php Fix for row metadata removed too early Co-authored-by: Stefan Giehl <[email protected]> * Replace evolution metrics 'add raw copy' api parameter with _trend column * ensure to use correct metric to check if lower value is better * updates expected test files * fix some more tests * update test file Co-authored-by: Stefan Giehl <[email protected]>
- Loading branch information
Showing
43 changed files
with
1,380 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* Piwik - free/libre analytics platform | ||
* | ||
* @link https://matomo.org | ||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later | ||
* | ||
*/ | ||
|
||
namespace Piwik\Plugins\CoreHome\tests\Unit; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Piwik\DataTable; | ||
use Piwik\Archive\DataCollection; | ||
use Piwik\DataTable\Row; | ||
use Piwik\Date; | ||
use Piwik\Plugins\CoreHome\Columns\Metrics\EvolutionMetric; | ||
|
||
/** | ||
* @group CoreHome | ||
* @group CoreHomeTest | ||
* @group EvolutionMetric | ||
*/ | ||
class EvolutionMetricTest extends TestCase | ||
{ | ||
public function test_shouldDoProportionalComparision_ifCurrentPeriodIncomplete() | ||
{ | ||
$currentData = new DataTable(); | ||
$cPeriod = new \Piwik\Period\Week(Date::factory('2021-10-10')); | ||
$currentData->setMetadata('period', $cPeriod); | ||
|
||
// If the archived date meta data value exists on the row then it will be used | ||
// as the current date for calculation purposes, we can use this to consistently test the | ||
// ratio calculation by supplying a fixed set of dates that should result in a 0.5 ratio | ||
|
||
$row = new Row(); | ||
$row->setMetadata(DataTable::ARCHIVED_DATE_METADATA_NAME, '2021-10-07 00:00:00'); | ||
|
||
$pastData = new DataTable(); | ||
$sPeriod = new \Piwik\Period\Week(Date::factory('2021-10-03')); | ||
$pastData->setMetadata('period', $sPeriod); | ||
|
||
$ratio = EvolutionMetric::getRatio($currentData, $pastData, $row); | ||
|
||
$this->assertEquals(0.429, $ratio); | ||
} | ||
|
||
public function test_shouldNotDoProportionalComparision_ifCurrentPeriodComplete() | ||
{ | ||
$currentData = new DataTable(); | ||
$cPeriod = new \Piwik\Period\Week(Date::factory('2021-10-10')); | ||
$currentData->setMetadata('period', $cPeriod); | ||
|
||
$pastData = new DataTable(); | ||
$sPeriod = new \Piwik\Period\Week(Date::factory('2021-10-03')); | ||
$pastData->setMetadata('period', $sPeriod); | ||
|
||
$ratio = EvolutionMetric::getRatio($currentData, $pastData, new Row()); | ||
|
||
$this->assertEquals(1, $ratio); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.