diff --git a/plugins/Insights/InsightReport.php b/plugins/Insights/InsightReport.php index 7c62df9344d..88644f265af 100644 --- a/plugins/Insights/InsightReport.php +++ b/plugins/Insights/InsightReport.php @@ -37,13 +37,12 @@ class InsightReport */ public function generateMoverAndShaker($reportMetadata, $period, $date, $lastDate, $metric, $currentReport, $lastReport, $totalValue, $lastTotalValue, $orderBy, $limitIncreaser, $limitDecreaser) { - $totalEvolution = Piwik::getPercentageSafe($totalValue - $lastTotalValue, $lastTotalValue, 1); + $totalEvolution = $this->getTotalEvolution($totalValue, $lastTotalValue); $minMoversPercent = 1; if ($totalEvolution >= 100) { // eg change from 50 to 150 = 200% - // $evolutionReverse = Piwik::getPercentageSafe($totalValue > $lastTotal ? $lastTotal : $totalValue, $totalValue > $lastTotal ? $totalValue : $lastTotal, 1); $factor = (int) ceil($totalEvolution / 500); $minGrowthPercentPositive = $totalEvolution + ($factor * 40); // min +240% $minGrowthPercentNegative = -70; // min -70% @@ -64,7 +63,7 @@ public function generateMoverAndShaker($reportMetadata, $period, $date, $lastDat $minNewPercent = 5; } - if ($totalValue < 200 && $totalValue > 0) { + if ($totalValue < 200 && $totalValue != 0) { // force at least a change of 2 visits $minMoversPercent = (int) ceil(2 / ($totalValue / 100)); $minNewPercent = max($minNewPercent, $minMoversPercent); @@ -73,9 +72,7 @@ public function generateMoverAndShaker($reportMetadata, $period, $date, $lastDat $dataTable = $this->generateInsight($reportMetadata, $period, $date, $lastDate, $metric, $currentReport, $lastReport, $totalValue, $minMoversPercent, $minNewPercent, $minDisappearedPercent, $minGrowthPercentPositive, $minGrowthPercentNegative, $orderBy, $limitIncreaser, $limitDecreaser); - $dataTable->setMetadata('lastTotalValue', $lastTotalValue); - $dataTable->setMetadata('evolutionTotal', $totalEvolution); - $dataTable->setMetadata('evolutionDifference', $totalValue - $lastTotalValue); + $this->addMoversAndShakersMetadata($dataTable, $totalValue, $lastTotalValue); return $dataTable; } @@ -113,6 +110,8 @@ public function markMoversAndShakers(DataTable $insight, $currentReport, $lastRe $row->setColumn('isMoverAndShaker', false); } } + + $this->addMoversAndShakersMetadata($insight, $totalValue, $lastTotalValue); } /** @@ -266,4 +265,18 @@ private function getMinVisits($totalValue, $percent) return (int) $minVisits; } + + private function addMoversAndShakersMetadata(DataTable $dataTable, $totalValue, $lastTotalValue) + { + $totalEvolution = $this->getTotalEvolution($totalValue, $lastTotalValue); + + $dataTable->setMetadata('lastTotalValue', $lastTotalValue); + $dataTable->setMetadata('evolutionTotal', $totalEvolution); + $dataTable->setMetadata('evolutionDifference', $totalValue - $lastTotalValue); + } + + private function getTotalEvolution($totalValue, $lastTotalValue) + { + return Piwik::getPercentageSafe($totalValue - $lastTotalValue, $lastTotalValue, 1); + } } diff --git a/plugins/Insights/lang/en.json b/plugins/Insights/lang/en.json index 3a7667db508..5dc5bd260ca 100644 --- a/plugins/Insights/lang/en.json +++ b/plugins/Insights/lang/en.json @@ -4,12 +4,30 @@ "WidgetCategory": "Insights", "NoResultMatchesCriteria": "No rows match the criteria", "MoversAndShakersWidgetTitle": "Movers and Shakers", - "TitleConsideredVisits": "Considered rows having a growth of at least %s%% compared to %s.", - "TitleConsideredChanges": "Considered movers only if they increased or decreased by more than %s visits, new entries only if they increase by more than %s visits, and disappeared rows if they decreased by more than %s visits based on %s total visits.", - "TitleReportBasedOn": "Based on %s %s, rows less than %s %s were ignored", - "TitleRowChangeDetails": "'%s' changed from %s (%s) to %s (%s) %s", - "TitleIgnoredChanges": "Changes affecting less than %s visits were ignored.", - "TitleConsideredMoversAndShakers": "Visits changed from %s to %s compared to %s. Based on this an evolution of each row of %s%% is expected.", - "TitleConsideredChangesMoversAndShakers": "Considered movers only if they grew by more than %s%% visits or less than %s%% visits, new entries only if they increased by more than %s%% visits (%s), and disappeared rows if they descreased by less than %s%% visits (%s)" + "TitleRowChangeDetails": "'%s' changed from %s (%s) to %s (%s) %s.", + "TitleRowNewDetails": "'%s' increased by %s and is new compared to %s.", + "TitleRowDisappearedDetails": "'%s' decreased by %s and disappeared in %s compared to %s.", + "TitleRowMoverAndShaker": "This row had an higher impact than the average.", + "IgnoredChanges": "Changes affecting less than %s visits were ignored.", + "TitleConsideredInsightsGrowth": "The following rows have a growth of at least %s%% compared to %s.", + "TitleConsideredInsightsChanges": "The rows increased or decreased by at least %s visits (%s%% of %s total visits).", + "TitleConsideredMoversAndShakersGrowth": "%s changed from %s to %s compared to %s. Based on this an evolution of each row of %s%% is expected.", + "TitleConsideredMoversAndShakersChanges": "Considered movers only if they grew by more than %s%% visits or shrank by less than %s%% visits, new entries only if they increased by more than %s%% visits (%s), and disappeared rows if they shrank by less than %s%% visits (%s).", + "DatePeriodCombinationNotSupported": "It is not possible to generate insights for this date / period combination.", + "ControlGrowthDescription": "Minimum growth of", + "ControlComparedToDescription": "compared to the", + "DayComparedToPreviousDay": "previous day", + "DayComparedToPreviousWeek": "same day in the previous week", + "DayComparedToPreviousYear": "same day in the previous year", + "WeekComparedToPreviousWeek": "previous week", + "MonthComparedToPreviousMonth": "previous month", + "MonthComparedToPreviousYear": "same month in the previous year", + "Filter": "Filter", + "FilterOnlyMovers": "Only movers", + "FilterOnlyNew": "Only new", + "FilterOnlyDisappeared": "Only disappeared", + "FilterIncreaserAndDecreaser": "Increaser & decreaser", + "FilterOnlyIncreaser": "Only increaser", + "FilterOnlyDecreaser": "Only decreaser" } } \ No newline at end of file diff --git a/plugins/Insights/stylesheets/insightVisualization.less b/plugins/Insights/stylesheets/insightVisualization.less index f70ea83ee5c..2c983d514ef 100644 --- a/plugins/Insights/stylesheets/insightVisualization.less +++ b/plugins/Insights/stylesheets/insightVisualization.less @@ -5,6 +5,13 @@ } .insightsDataTable { + + .controlSeparator { + height: 1px; + border: 0px; + background-color: #cccccc; + } + th.orderBy { width: 20%; } diff --git a/plugins/Insights/templates/cannotDisplayReport.twig b/plugins/Insights/templates/cannotDisplayReport.twig index d32a9d1a364..7c996e28379 100644 --- a/plugins/Insights/templates/cannotDisplayReport.twig +++ b/plugins/Insights/templates/cannotDisplayReport.twig @@ -1,3 +1,3 @@
- It is not possible to generate insights for this date / period combination. + {{ 'Insights_DatePeriodCombinationNotSupported'|translate }}
\ No newline at end of file diff --git a/plugins/Insights/templates/insightControls.twig b/plugins/Insights/templates/insightControls.twig index a572ee85073..e9d1e3f27f3 100644 --- a/plugins/Insights/templates/insightControls.twig +++ b/plugins/Insights/templates/insightControls.twig @@ -1,6 +1,7 @@
- Minimum growth of + {{ 'Insights_ControlGrowthDescription'|translate }} + {% if period == 'day' or period == 'month' or period == 'week' %} - compared to + + {{ 'Insights_ControlComparedToDescription'|translate }} + {% if period == 'day' %} {% elseif period == 'month' %} {% elseif period == 'week' %} - previous week + {{ 'Insights_WeekComparedToPreviousWeek'|translate }} {% endif %} {% endif %} -
+
- Filter + {{ 'Insights_Filter'|translate }}
\ No newline at end of file diff --git a/plugins/Insights/templates/insightVisualization.twig b/plugins/Insights/templates/insightVisualization.twig index 196b3909095..6dd35e3697e 100644 --- a/plugins/Insights/templates/insightVisualization.twig +++ b/plugins/Insights/templates/insightVisualization.twig @@ -2,14 +2,14 @@ {% include "@Insights/cannotDisplayReport.twig" %} {% else %} {% set metadata = dataTable.getAllTableMetadata%} - {% set consideredVisits = 'Insights_TitleConsideredVisits'|translate(metadata.minGrowthPercentPositive, metadata.lastDate|prettyDate(metadata.period)) %} + {% set consideredGrowth = 'Insights_TitleConsideredInsightsGrowth'|translate(metadata.minGrowthPercentPositive, metadata.lastDate|prettyDate(metadata.period)) %} {% set consideredChanges = '' %} {% if metadata.minChangeMovers and metadata.minChangeMovers > 1 %} - {% set consideredChanges = 'Insights_TitleIgnoredChanges'|translate(metadata.minChangeMovers) %} + {% set consideredChanges = 'Insights_IgnoredChanges'|translate(metadata.minChangeMovers) %} {% endif %} -
+
{% if dataTable.getRowsCount %} diff --git a/plugins/Insights/templates/insightsOverviewWidget.twig b/plugins/Insights/templates/insightsOverviewWidget.twig index 8f99ba11ba7..cf8bfe166d7 100644 --- a/plugins/Insights/templates/insightsOverviewWidget.twig +++ b/plugins/Insights/templates/insightsOverviewWidget.twig @@ -1,10 +1,5 @@ {% set allMetadata = reports.getFirstRow.getAllTableMetadata %} - -{% set consideredVisits = 'Insights_TitleConsideredVisits'|translate(allMetadata.minGrowthPercentPositive, allMetadata.lastDate|prettyDate(allMetadata.period)) %} +{% set consideredGrowth = 'Insights_TitleConsideredInsightsGrowth'|translate(allMetadata.minGrowthPercentPositive, allMetadata.lastDate|prettyDate(allMetadata.period)) %} {% set consideredChanges = '' %} -{% if allMetadata.minChangeMovers or allMetadata.minIncreaseNew or allMetadata.minDecreaseDisappeared %} - {% set consideredChanges = 'Insights_TitleConsideredChanges'|translate(allMetadata.minChangeMovers, allMetadata.minIncreaseNew, allMetadata.minDecreaseDisappeared, allMetadata.totalValue) %} -{% endif %} - {% include "@Insights/overviewWidget.twig" %} \ No newline at end of file diff --git a/plugins/Insights/templates/moversAndShakersOverviewWidget.twig b/plugins/Insights/templates/moversAndShakersOverviewWidget.twig index 185a61b37ed..f2326df1eae 100644 --- a/plugins/Insights/templates/moversAndShakersOverviewWidget.twig +++ b/plugins/Insights/templates/moversAndShakersOverviewWidget.twig @@ -1,10 +1,6 @@ {% set allMetadata = reports.getFirstRow.getAllTableMetadata %} -{% set consideredVisits = 'Insights_TitleConsideredMoversAndShakers'|translate(allMetadata.lastTotalValue, allMetadata.totalValue, allMetadata.lastDate|prettyDate(allMetadata.period), allMetadata.evolutionTotal) %} -{% set consideredChanges = '' %} - -{% if allMetadata.minChangeMovers or allMetadata.minIncreaseNew or allMetadata.minDecreaseDisappeared %} - {% set consideredChanges = 'Insights_TitleConsideredChangesMoversAndShakers'|translate(allMetadata.minGrowthPercentPositive, allMetadata.minGrowthPercentNegative, allMetadata.minNewPercent, allMetadata.minIncreaseNew, allMetadata.minDisappearedPercent, allMetadata.minDecreaseDisappeared, allMetadata.totalValue) %} -{% endif %} +{% set consideredGrowth = 'Insights_TitleConsideredMoversAndShakersGrowth'|translate(allMetadata.metricName, allMetadata.lastTotalValue, allMetadata.totalValue, allMetadata.lastDate|prettyDate(allMetadata.period), allMetadata.evolutionTotal) %} +{% set consideredChanges = 'Insights_TitleConsideredMoversAndShakersChanges'|translate(allMetadata.minGrowthPercentPositive, allMetadata.minGrowthPercentNegative, allMetadata.minNewPercent, allMetadata.minIncreaseNew, allMetadata.minDisappearedPercent, allMetadata.minDecreaseDisappeared, allMetadata.totalValue) %} {% include "@Insights/overviewWidget.twig" %} \ No newline at end of file diff --git a/plugins/Insights/templates/overviewWidget.twig b/plugins/Insights/templates/overviewWidget.twig index d3c43b917ba..648025f9136 100644 --- a/plugins/Insights/templates/overviewWidget.twig +++ b/plugins/Insights/templates/overviewWidget.twig @@ -1,14 +1,15 @@
+ data-table-onlyinsightsinit="1"> {% if reports.getColumns|length > 0 %} -
- {% for dataTable in reports.getDataTables() if dataTable.getRowsCount > 0 %} - {% set metadata = dataTable.getAllTableMetadata %} + {% for dataTable in reports.getDataTables() if dataTable.getRowsCount > 0 %} + {% set metadata = dataTable.getAllTableMetadata %} - +
+ + {% include "@Insights/table_header.twig" %} @@ -18,8 +19,8 @@ {% endfor %} - {% endfor %} -
+ + {% endfor %}