Permalink
Browse files

Merge branch 'master' of github.com:piwik/piwik

  • Loading branch information...
2 parents 360ca40 + 41e8e34 commit b6b95920debdfe3d0feb3612fa4d571ff825298e @mattab mattab committed Mar 7, 2014
Showing with 573 additions and 254 deletions.
  1. +1 −1 misc/cron/archive.sh
  2. +1 −3 plugins/DBStats/API.php
  3. +5 −2 plugins/DevicesDetection/UserAgentParserEnhanced/regexes/browsers.yml
  4. +100 −55 plugins/Insights/API.php
  5. +12 −4 plugins/Insights/Controller.php
  6. +8 −6 plugins/Insights/DataTable/Filter/MinGrowth.php
  7. +74 −16 plugins/Insights/InsightReport.php
  8. +30 −16 plugins/Insights/Visualizations/Insight.php
  9. +0 −17 plugins/Insights/Visualizations/Insight/Config.php
  10. +13 −2 plugins/Insights/javascripts/insightsDataTable.js
  11. +4 −2 plugins/Insights/lang/en.json
  12. +4 −1 plugins/Insights/stylesheets/insightVisualization.less
  13. +3 −0 plugins/Insights/templates/cannotDisplayReport.twig
  14. +8 −9 plugins/Insights/templates/insightControls.twig
  15. +32 −25 plugins/Insights/templates/insightVisualization.twig
  16. +10 −0 plugins/Insights/templates/insightsOverviewWidget.twig
  17. +10 −0 plugins/Insights/templates/moversAndShakersOverviewWidget.twig
  18. +10 −10 plugins/Insights/templates/overviewWidget.twig
  19. +3 −2 plugins/Insights/templates/table_row.twig
  20. +5 −4 plugins/Insights/tests/ApiTest.php
  21. +14 −9 plugins/Insights/tests/FilterMinGrowthTest.php
  22. +108 −29 plugins/Insights/tests/InsightReportTest.php
  23. +2 −2 plugins/SegmentEditor/javascripts/Segmentation.js
  24. +0 −16 tests/PHPUnit/Fixtures/ManySitesImportedLogsWithXssAttempts.php
  25. +18 −0 tests/PHPUnit/Fixtures/UITestFixture.php
  26. +75 −11 tests/PHPUnit/Fixtures/userAgentParserEnhancedFixtures.yml
  27. +0 −7 tests/PHPUnit/TestingEnvironment.php
  28. +1 −0 tests/README.screenshots.md
  29. +5 −1 tests/lib/screenshot-testing/support/chai-extras.js
  30. +2 −1 tests/lib/screenshot-testing/support/diff-viewer.js
  31. +10 −0 tests/lib/screenshot-testing/support/page-renderer.js
  32. +4 −2 tests/lib/screenshot-testing/support/test-environment.js
  33. +1 −1 tests/resources/screenshot-override/override.css
View
@@ -64,7 +64,7 @@ PIWIK_CRON_FOLDER=`dirname ${ARCHIVE}`
PIWIK_PATH="$PIWIK_CRON_FOLDER"/../../index.php
PIWIK_TOKEN_GENERATOR="$PIWIK_CRON_FOLDER"/../../misc/cron/updatetoken.php
-FILENAME_TOKEN_CONTENT=`php $PIWIK_TOKEN_GENERATOR`
+FILENAME_TOKEN_CONTENT=`$PHP_BIN $PIWIK_TOKEN_GENERATOR`
TOKEN_AUTH=`cat $FILENAME_TOKEN_CONTENT | cut -f2`
CMD_GET_ID_SITES="$PHP_BIN -q $PIWIK_PATH -- module=API&method=SitesManager.getAllSitesId&token_auth=$TOKEN_AUTH&format=csv&convertToUnicode=0"
View
@@ -34,9 +34,7 @@ class API extends \Piwik\Plugin\API
*/
protected function __construct()
{
- if ($this->metadataProvider === null) {
- $this->metadataProvider = new MySQLMetadataProvider();
- }
+ $this->metadataProvider = new MySQLMetadataProvider();
}
/**
@@ -113,10 +113,13 @@
- regex: 'Opera Mini/(?:att/)?(\d+\.\d+)'
name: 'Opera Mini'
version: '$1'
-- regex: 'OPR[/ ](\d+\.\d+)'
+- regex: 'Opera.+Edition Next.+Version/(\d+\.\d+)'
name: 'Opera Next'
version: '$1'
-- regex: '(?:Opera)[/ ](?:9.80.*Version/)?(\d+\.\d+)'
+- regex: '(?:Opera|OPR)[/ ](?:9.80.*Version/)?(\d+\.\d+).+Edition Next'
+ name: 'Opera Next'
+ version: '$1'
+- regex: '(?:Opera|OPR)[/ ](?:9.80.*Version/)?(\d+\.\d+)'
name: 'Opera'
version: '$1'
View
@@ -33,16 +33,20 @@ class API extends \Piwik\Plugin\API
*/
private $model;
+ /**
+ * Those reports will be included in the insight / moversAndShakers overview reports.
+ * You can configure any API parameter for each report such as "flat", "limitIncreaser", "minGrowth", ...
+ * @var array
+ */
private $reportIds = array(
- 'Actions_getPageUrls',
- 'Actions_getPageTitles',
- 'Actions_getDownloads',
- 'Referrers_getAll',
- 'Referrers_getKeywords',
- 'Referrers_getCampaigns',
- 'Referrers_getSocials',
- 'Referrers_getSearchEngines',
- 'UserCountry_getCountry',
+ 'Actions_getPageUrls' => array(),
+ 'Actions_getPageTitles' => array(),
+ 'Actions_getDownloads' => array('flat' => 1),
+ 'Referrers_getWebsites' => array(),
+ 'Referrers_getCampaigns' => array(),
+ 'Referrers_getSocials' => array(),
+ 'Referrers_getSearchEngines' => array(),
+ 'UserCountry_getCountry' => array(),
);
protected function __construct()
@@ -52,45 +56,69 @@ protected function __construct()
$this->model = new Model();
}
- public function getInsightsOverview($idSite, $period, $date, $segment = false)
+ public function canGenerateInsights($period, $date)
{
- Piwik::checkUserHasViewAccess(array($idSite));
+ try {
+ $model = new Model();
+ $lastDate = $model->getLastDate($date, $period, 1);
+ } catch (\Exception $e) {
+ return false;
+ }
- $reportTableIds = array();
+ if (empty($lastDate)) {
+ return false;
+ }
- /** @var DataTable[] $tables */
- $tables = array();
- foreach ($this->reportIds as $reportId) {
- $firstTableId = DataTable\Manager::getInstance()->getMostRecentTableId();
- $table = $this->getInsights($idSite, $period, $date, $reportId, $segment, 3, 3, '', 2, 25);
- $reportTableIds[] = $table->getId();
- DataTable\Manager::getInstance()->deleteTablesExceptIgnored($reportTableIds, $firstTableId);
+ return true;
+ }
- $tables[] = $table;
- }
+ public function getInsightsOverview($idSite, $period, $date, $segment = false)
+ {
+ Piwik::checkUserHasViewAccess(array($idSite));
- $map = new DataTable\Map();
+ $defaultParams = array(
+ 'limitIncreaser' => 3,
+ 'limitDecreaser' => 3,
+ 'minImpactPercent' => 2,
+ 'minGrowthPercent' => 25,
+ );
- foreach ($tables as $table) {
- $map->addTable($table, $table->getMetadata('reportName'));
- }
+ $map = $this->generateOverviewReport('getInsights', $idSite, $period, $date, $segment, $defaultParams);
return $map;
}
- public function getOverallMoversAndShakers($idSite, $period, $date, $segment = false)
+ public function getMoversAndShakersOverview($idSite, $period, $date, $segment = false)
{
Piwik::checkUserHasViewAccess(array($idSite));
- $reportTableIds = array();
+ $defaultParams = array(
+ 'limitIncreaser' => 4,
+ 'limitDecreaser' => 4
+ );
+
+ $map = $this->generateOverviewReport('getMoversAndShakers', $idSite, $period, $date, $segment, $defaultParams);
+
+ return $map;
+ }
+
+ private function generateOverviewReport($method, $idSite, $period, $date, $segment, array $defaultParams)
+ {
+ $tableManager = DataTable\Manager::getInstance();
/** @var DataTable[] $tables */
$tables = array();
- foreach ($this->reportIds as $reportId) {
- $firstTableId = DataTable\Manager::getInstance()->getMostRecentTableId();
- $table = $this->getMoversAndShakers($idSite, $period, $date, $reportId, $segment, 4, 4);
+ foreach ($this->reportIds as $reportId => $reportParams) {
+ foreach ($defaultParams as $key => $defaultParam) {
+ if (!array_key_exists($key, $reportParams)) {
+ $reportParams[$key] = $defaultParam;
+ }
+ }
+
+ $firstTableId = $tableManager->getMostRecentTableId();
+ $table = $this->requestApiMethod($method, $idSite, $period, $date, $reportId, $segment, $reportParams);
$reportTableIds[] = $table->getId();
- DataTable\Manager::getInstance()->deleteTablesExceptIgnored($reportTableIds, $firstTableId);
+ $tableManager->deleteTablesExceptIgnored($reportTableIds, $firstTableId);
$tables[] = $table;
}
@@ -105,37 +133,24 @@ public function getOverallMoversAndShakers($idSite, $period, $date, $segment = f
}
public function getMoversAndShakers($idSite, $period, $date, $reportUniqueId, $segment = false,
- $limitIncreaser = 4, $limitDecreaser = 4)
+ $comparedToXPeriods = 1, $limitIncreaser = 4, $limitDecreaser = 4)
{
- $orderBy = 'absolute';
- $minGrowthPercent = 30;
- $minMoversPercent = 2;
- $minNewPercent = 2;
- $minDisappearedPercent = 2;
-
Piwik::checkUserHasViewAccess(array($idSite));
- $metric = 'nb_visits';
+ $metric = 'nb_visits';
+ $orderBy = InsightReport::ORDER_BY_ABSOLUTE;
$reportMetadata = $this->model->getReportByUniqueId($idSite, $reportUniqueId);
+
$totalValue = $this->model->getTotalValue($idSite, $period, $date, $metric);
$currentReport = $this->model->requestReport($idSite, $period, $date, $reportUniqueId, $metric, $segment);
- if ($period === 'day') {
- // if website is too young, than use website creation date
- // for faster performance just compare against last week?
- $pastDate = $this->model->getLastDate($date, $period, 7);
- $lastReport = $this->model->requestReport($idSite, 'week', $pastDate, $reportUniqueId, $metric, $segment);
- $lastReport->filter('Piwik\Plugins\Insights\DataTable\Filter\Average', array($metric, 7));
- $lastDate = Range::factory('week', $pastDate);
- $lastDate = $lastDate->getRangeString();
- } else {
- $lastDate = $this->model->getLastDate($date, $period, 1);
- $lastReport = $this->model->requestReport($idSite, $period, $lastDate, $reportUniqueId, $metric, $segment);
- }
+ $lastDate = $this->model->getLastDate($date, $period, $comparedToXPeriods);
+ $lastTotalValue = $this->model->getTotalValue($idSite, $period, $lastDate, $metric);
+ $lastReport = $this->model->requestReport($idSite, $period, $lastDate, $reportUniqueId, $metric, $segment);
$insight = new InsightReport();
- return $insight->generateInsight($reportMetadata, $period, $date, $lastDate, $metric, $currentReport, $lastReport, $totalValue, $minMoversPercent, $minNewPercent, $minDisappearedPercent, $minGrowthPercent, $orderBy, $limitIncreaser, $limitDecreaser);
+ return $insight->generateMoverAndShaker($reportMetadata, $period, $date, $lastDate, $metric, $currentReport, $lastReport, $totalValue, $lastTotalValue, $orderBy, $limitIncreaser, $limitDecreaser);
}
public function getInsights(
@@ -148,11 +163,15 @@ public function getInsights(
$metric = 'nb_visits';
$reportMetadata = $this->model->getReportByUniqueId($idSite, $reportUniqueId);
- $lastDate = $this->model->getLastDate($date, $period, $comparedToXPeriods);
+
$currentReport = $this->model->requestReport($idSite, $period, $date, $reportUniqueId, $metric, $segment);
- $lastReport = $this->model->requestReport($idSite, $period, $lastDate, $reportUniqueId, $metric, $segment);
$totalValue = $this->model->getRelevantTotalValue($currentReport, $idSite, $period, $date, $metric);
+ $lastDate = $this->model->getLastDate($date, $period, $comparedToXPeriods);
+ $lastReport = $this->model->requestReport($idSite, $period, $lastDate, $reportUniqueId, $metric, $segment);
+
+ $minGrowthPercentPositive = abs($minGrowthPercent);
+ $minGrowthPercentNegative = -1 * $minGrowthPercentPositive;
$minMoversPercent = -1;
$minNewPercent = -1;
$minDisappearedPercent = -1;
@@ -174,6 +193,32 @@ public function getInsights(
}
$insight = new InsightReport();
- return $insight->generateInsight($reportMetadata, $period, $date, $lastDate, $metric, $currentReport, $lastReport, $totalValue, $minMoversPercent, $minNewPercent, $minDisappearedPercent, $minGrowthPercent, $orderBy, $limitIncreaser, $limitDecreaser);
+ return $insight->generateInsight($reportMetadata, $period, $date, $lastDate, $metric, $currentReport, $lastReport, $totalValue, $minMoversPercent, $minNewPercent, $minDisappearedPercent, $minGrowthPercentPositive, $minGrowthPercentNegative, $orderBy, $limitIncreaser, $limitDecreaser);
}
+
+ private function requestApiMethod($method, $idSite, $period, $date, $reportId, $segment, $additionalParams)
+ {
+ $params = array(
+ 'method' => 'Insights.' . $method,
+ 'idSite' => $idSite,
+ 'date' => $date,
+ 'period' => $period,
+ 'format' => 'original',
+ 'reportUniqueId' => $reportId,
+ );
+
+ if ($segment) {
+ $params['segment'] = $segment;
+ }
+
+ if (!empty($additionalParams)) {
+ foreach ($additionalParams as $key => $value) {
+ $params[$key] = $value;
+ }
+ }
+
+ $request = new ApiRequest($params);
+ return $request->process();
+ }
+
}
@@ -10,6 +10,7 @@
use Piwik\Common;
use Piwik\Piwik;
+use Piwik\Plugins\Insights\Visualizations\Insight;
use Piwik\View;
/**
@@ -20,27 +21,34 @@ class Controller extends \Piwik\Plugin\Controller
public function getInsightsOverview()
{
- $view = $this->prepareWidget($apiReport = 'getInsightsOverview');
+ $view = $this->prepareWidget('insightsOverviewWidget.twig', $apiReport = 'getInsightsOverview');
return $view->render();
}
public function getOverallMoversAndShakers()
{
- $view = $this->prepareWidget($apiReport = 'getOverallMoversAndShakers');
+ $view = $this->prepareWidget('moversAndShakersOverviewWidget.twig', $apiReport = 'getMoversAndShakersOverview');
return $view->render();
}
- private function prepareWidget($apiReport)
+ private function prepareWidget($template, $apiReport)
{
$idSite = Common::getRequestVar('idSite', null, 'int');
$period = Common::getRequestVar('period', null, 'string');
$date = Common::getRequestVar('date', null, 'string');
Piwik::checkUserHasViewAccess(array($idSite));
- $view = new View('@Insights/overviewWidget.twig');
+ if (!API::getInstance()->canGenerateInsights($period, $date)) {
+
+ $view = new View('@Insights/cannotDisplayReport.twig');
+ $this->setBasicVariablesView($view);
+ return $view;
+ }
+
+ $view = new View('@Insights/' . $template);
$this->setBasicVariablesView($view);
$view->reports = API::getInstance()->$apiReport($idSite, $period, $date);
@@ -13,28 +13,30 @@
class MinGrowth extends BaseFilter
{
- private $minValue;
+ private $minPositiveGrowth;
+ private $minNegativeGrowth;
private $columnToRead;
- public function __construct($table, $columnToRead, $minValue)
+ public function __construct($table, $columnToRead, $minPositiveGrowth, $minNegativeGrowth)
{
$this->columnToRead = $columnToRead;
- $this->minValue = abs($minValue);
+ $this->minPositiveGrowth = $minPositiveGrowth;
+ $this->minNegativeGrowth = $minNegativeGrowth;
}
public function filter($table)
{
- if (!$this->minValue) {
+ if (!$this->minPositiveGrowth && !$this->minNegativeGrowth) {
return;
}
foreach ($table->getRows() as $key => $row) {
$growthNumeric = $row->getColumn($this->columnToRead);
- if ($growthNumeric >= $this->minValue) {
+ if ($growthNumeric >= $this->minPositiveGrowth && $growthNumeric >= 0) {
continue;
- } elseif ($growthNumeric <= -$this->minValue) {
+ } elseif ($growthNumeric <= $this->minNegativeGrowth && $growthNumeric < 0) {
continue;
}
Oops, something went wrong.

0 comments on commit b6b9592

Please sign in to comment.