Permalink
Browse files

Merge remote-tracking branch 'origin/master'

  • Loading branch information...
2 parents 61be595 + 4e51781 commit 69166694778fb3b13ea100e35e00f2e65b9cc93c @mattab mattab committed Mar 5, 2014
View
@@ -9,6 +9,7 @@
namespace Piwik;
use Exception;
+use Piwik\Period\Range;
use Piwik\Translate;
use Piwik\Visualization\Sparkline;
use Piwik\View\RenderTokenParser;
@@ -63,6 +64,7 @@ public function __construct()
$this->addFilter_truncate();
$this->addFilter_notificiation();
$this->addFilter_percentage();
+ $this->addFilter_prettyDate();
$this->twig->addFilter(new Twig_SimpleFilter('implode', 'implode'));
$this->twig->addFilter(new Twig_SimpleFilter('ucwords', 'ucwords'));
@@ -187,6 +189,14 @@ protected function addFilter_notificiation()
$this->twig->addFilter($notificationFunction);
}
+ protected function addFilter_prettyDate()
+ {
+ $prettyDate = new Twig_SimpleFilter('prettyDate', function ($dateString, $period) {
+ return Range::factory($period, $dateString)->getLocalizedShortString();
+ });
+ $this->twig->addFilter($prettyDate);
+ }
+
protected function addFilter_percentage()
{
$percentage = new Twig_SimpleFilter('percentage', function ($string, $totalValue, $precision = 1) {
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -18,26 +18,36 @@
class Controller extends \Piwik\Plugin\Controller
{
- public function getInsightOverview()
+ public function getInsightsOverview()
+ {
+ $view = $this->prepareWidget($apiReport = 'getInsightsOverview');
+
+ return $view->render();
+ }
+
+ public function getOverallMoversAndShakers()
+ {
+ $view = $this->prepareWidget($apiReport = 'getOverallMoversAndShakers');
+
+ return $view->render();
+ }
+
+ private function prepareWidget($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/index.twig');
+ $view = new View('@Insights/overviewWidget.twig');
$this->setBasicVariablesView($view);
- $view->moversAndShakers = API::getInstance()->getInsightsOverview($idSite, $period, $date);
- $view->showNoDataMessage = false;
- $view->showInsightsControls = false;
+ $view->reports = API::getInstance()->$apiReport($idSite, $period, $date);
$view->properties = array(
- 'show_increase' => true,
- 'show_decrease' => true,
'order_by' => 'absolute'
);
- return $view->render();
+ return $view;
}
}
@@ -14,11 +14,21 @@ class ExcludeLowValue extends DataTable\BaseFilter
{
private $minimumValue;
private $columnToRead;
+ private $columnToCheckToBeTrue;
- public function __construct($table, $columnToRead, $minimumValue)
+ /**
+ * @param DataTable $table
+ * @param string $columnToRead
+ * @param int $minimumValue
+ * @param string $columnToCheckToBeTrue if set, we will delete a row only if this column evaluates to true. If
+ * column does not evaluate to true we will not delete the row even if
+ * the value is lower than the minimumValue.
+ */
+ public function __construct($table, $columnToRead, $minimumValue, $columnToCheckToBeTrue = '')
{
$this->columnToRead = $columnToRead;
$this->minimumValue = $minimumValue;
+ $this->columnToCheckToBeTrue = $columnToCheckToBeTrue;
}
public function filter($table)
@@ -27,11 +37,17 @@ public function filter($table)
return;
}
- $minimumValue = $this->minimumValue;
- $isValueLowPopulation = function ($value) use ($minimumValue) {
- return $value < $minimumValue;
- };
+ foreach ($table->getRows() as $key => $row) {
- $table->filter('ColumnCallbackDeleteRow', array($this->columnToRead, $isValueLowPopulation));
+ if ($this->columnToCheckToBeTrue && !$row->getColumn($this->columnToCheckToBeTrue)) {
+ continue;
+ }
+
+ $value = $row->getColumn($this->columnToRead);
+
+ if ($this->minimumValue > $value) {
+ $table->deleteRow($key);
+ }
+ }
}
}
@@ -30,61 +30,77 @@ public function __construct($table, $currentDataTable, $pastDataTable, $columnTo
public function filter($table)
{
- foreach ($this->currentDataTable->getRows() as $key => $row) {
- $pastRow = $this->getPastRowFromCurrent($row);
- $oldValue = 0;
+ foreach ($this->currentDataTable->getRows() as $row) {
+ $this->addRowIfNewOrMover($table, $row);
+ }
- if (!$pastRow && !$this->considerNew) {
- continue;
+ if ($this->considerDisappeared) {
+ foreach ($this->pastDataTable->getRows() as $row) {
+ $this->addRowIfDisappeared($table, $row);
}
+ }
+ }
- if ($pastRow && $this->considerMovers) {
- $oldValue = $pastRow->getColumn($this->columnValueToRead);
- } elseif ($pastRow) {
- continue;
- }
+ private function addRowIfDisappeared(DataTable $table, DataTable\Row $row)
+ {
+ if ($this->getRowFromTable($this->currentDataTable, $row)) {
+ return;
+ }
- $difference = $this->getDividend($row);
- if ($difference === false) {
- continue;
- }
+ $newValue = 0;
+ $oldValue = $row->getColumn($this->columnValueToRead);
+ $difference = $newValue - $oldValue;
+
+ if ($oldValue == 0 && $newValue == 0) {
+ $growthPercentage = '0%';
+ } else {
+ $growthPercentage = '-100%';
+ }
- $newValue = $row->getColumn($this->columnValueToRead);
- $divisor = $this->getDivisor($row);
+ $this->addRow($table, $row, $growthPercentage, $newValue, $oldValue, $difference, $isDisappeared = true);
+ }
- $growthPercentage = $this->formatValue($difference, $divisor);
+ private function addRowIfNewOrMover(DataTable $table, DataTable\Row $row)
+ {
+ $pastRow = $this->getPastRowFromCurrent($row);
- $this->addRow($table, $row, $growthPercentage, $newValue, $oldValue, $difference);
+ if (!$pastRow && !$this->considerNew) {
+ return;
+ } elseif ($pastRow && !$this->considerMovers) {
+ return;
}
- if ($this->considerDisappeared) {
- foreach ($this->pastDataTable->getRows() as $key => $row) {
+ $isNew = false;
+ $isMover = false;
+ $isDisappeared = false;
+
+ if (!$pastRow) {
+ $isNew = true;
+ $oldValue = 0;
+ } else {
+ $isMover = true;
+ $oldValue = $pastRow->getColumn($this->columnValueToRead);
+ }
- if ($this->getRowFromTable($this->currentDataTable, $row)) {
- continue;
- }
+ $difference = $this->getDividend($row);
+ if ($difference === false) {
+ return;
+ }
- $newValue = 0;
- $oldValue = $row->getColumn($this->columnValueToRead);
- $difference = $newValue - $oldValue;
+ $newValue = $row->getColumn($this->columnValueToRead);
+ $divisor = $this->getDivisor($row);
- if ($oldValue == 0 && $newValue == 0) {
- $growthPercentage = '0%';
- } else {
- $growthPercentage = '-100%';
- }
+ $growthPercentage = $this->formatValue($difference, $divisor);
- $this->addRow($table, $row, $growthPercentage, $newValue, $oldValue, $difference);
- }
- }
+ $this->addRow($table, $row, $growthPercentage, $newValue, $oldValue, $difference, $isDisappeared, $isNew, $isMover);
}
private function getRowFromTable(DataTable $table, DataTable\Row $row)
{
return $table->getRowFromLabel($row->getColumn('label'));
}
- private function addRow(DataTable $table, DataTable\Row $row, $growthPercentage, $newValue, $oldValue, $difference)
+ private function addRow(DataTable $table, DataTable\Row $row, $growthPercentage, $newValue, $oldValue, $difference, $disappeared = false, $isNew = false, $isMover = false)
{
$columns = $row->getColumns();
$columns['growth_percent'] = $growthPercentage;
@@ -94,6 +110,9 @@ private function addRow(DataTable $table, DataTable\Row $row, $growthPercentage,
$columns['value_new'] = $newValue;
$columns['difference'] = $difference;
$columns['importance'] = abs($difference);
+ $columns['isDisappeared'] = $disappeared;
+ $columns['isNew'] = $isNew;
+ $columns['isMover'] = $isMover;
$table->addRowFromArray(array(DataTable\Row::COLUMNS => $columns));
}
@@ -34,7 +34,8 @@ public function getAvailableVisualizations(&$visualizations)
public function addWidgets()
{
- WidgetsList::add('Insights_Category', 'Insights_OverviewWidgetTitle', 'Insights', 'getInsightOverview');
+ WidgetsList::add('Insights_WidgetCategory', 'Insights_OverviewWidgetTitle', 'Insights', 'getInsightsOverview');
+ WidgetsList::add('Insights_WidgetCategory', 'Insights_MoversAndShakersWidgetTitle', 'Insights', 'getOverallMoversAndShakers');
}
public function getStylesheetFiles(&$stylesheets)
@@ -25,7 +25,7 @@ class Insight extends Visualization
{
const ID = 'insightsVisualization';
const TEMPLATE_FILE = '@Insights/insightVisualization.twig';
- const FOOTER_ICON_TITLE = 'InsightsVisualization';
+ const FOOTER_ICON_TITLE = 'Insights';
const FOOTER_ICON = 'plugins/Insights/images/idea.png';
public function beforeLoadDataTable()
@@ -80,8 +80,6 @@ public function isThereDataToDisplay()
public function afterAllFiltersAreApplied()
{
- $this->assignTemplateVar('showNoDataMessage', true);
- $this->assignTemplateVar('showInsightsControls', true);
$this->assignTemplateVar('period', Common::getRequestVar('period', null, 'string'));
}
@@ -1,7 +1,12 @@
{
"Insights": {
"OverviewWidgetTitle": "Insights Overview",
- "Category": "Insights",
- "NoResultMatchesCriteria": "No rows match the criteria"
+ "WidgetCategory": "Insights",
+ "NoResultMatchesCriteria": "No rows match the criteria",
+ "MoversAndShakersWidgetTitle": "Movers and Shakers",
+ "TitleConsideredVisits": "Considered rows having at least %s visits (%s%% of %s visits) with 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.",
+ "TitleReportBasedOn": "Based on %s %s, rows less than %s %s were ignored",
+ "TitleRowChangeDetails": "'%s' changed from %s (%s) to %s (%s) %s"
}
}
@@ -25,4 +25,11 @@
.notGrown {
color:red;
}
+
+ table td {
+ &.labelodd, &.labeleven {
+
+ background-image: none;
+ }
+ }
}
@@ -1,5 +0,0 @@
-{% for dataTable in moversAndShakers.getDataTables() %}
-
- {% include "@Insights/insightVisualization.twig" %}
-
-{% endfor %}
@@ -1,13 +1,13 @@
<div style="padding: 10px;padding-bottom: 0px;">
- Minimum impact of
+ Minimum visits of
<select name="minVisitsPercent" title="Based on a total of {{ dataTable.getMetadata('totalValue') }} visitors or metricname">
{% for i in range(0, 10) %}
<option {% if i == properties.min_visits_percent %}selected{% endif %} value="{{ i }}">{{ i }}%</option>
{% endfor %}
{% for i in range(12, 30, 2) %}
<option {% if i == properties.min_visits_percent %}selected{% endif %} value="{{ i }}">{{ i }}%</option>
{% endfor %}
- {% for i in range(35, 100, 5) %}
+ {% for i in range(40, 100, 10) %}
<option {% if i == properties.min_visits_percent %}selected{% endif %} value="{{ i }}">{{ i }}%</option>
{% endfor %}
</select>
@@ -25,28 +25,30 @@
{% endfor %}
</select>
- compared to
- {% if period == 'day' %}
- <select size="1" name="comparedToXPeriodsAgo">
- <option value="1" {% if properties.compared_to_x_periods_ago == 1 %}selected{% endif %}>
- previous day
- </option>
- <option value="7" {% if properties.compared_to_x_periods_ago == 7 %}selected{% endif %}>
- same day in previous week
- </option>
- <option value="365" {% if properties.compared_to_x_periods_ago == 365 %}selected{% endif %}>
- same day in previous year
- </option>
- </select>
- {% elseif period == 'month' %}
- <select size="1" name="comparedToXPeriodsAgo">
- <option value="1" {% if properties.compared_to_x_periods_ago == 1 %}selected{% endif %}>
- previous month
- </option>
- <option value="12" {% if properties.compared_to_x_periods_ago == 12 %}selected{% endif %}>
- same month in previous year
- </option>
- </select>
+ {% if period == 'day' or period == 'month' %}
+ compared to
+ {% if period == 'day' %}
+ <select size="1" name="comparedToXPeriodsAgo">
+ <option value="1" {% if properties.compared_to_x_periods_ago == 1 %}selected{% endif %}>
+ previous day
+ </option>
+ <option value="7" {% if properties.compared_to_x_periods_ago == 7 %}selected{% endif %}>
+ same day in previous week
+ </option>
+ <option value="365" {% if properties.compared_to_x_periods_ago == 365 %}selected{% endif %}>
+ same day in previous year
+ </option>
+ </select>
+ {% elseif period == 'month' %}
+ <select size="1" name="comparedToXPeriodsAgo">
+ <option value="1" {% if properties.compared_to_x_periods_ago == 1 %}selected{% endif %}>
+ previous month
+ </option>
+ <option value="12" {% if properties.compared_to_x_periods_ago == 12 %}selected{% endif %}>
+ same month in previous year
+ </option>
+ </select>
+ {% endif %}
{% endif %}
<hr style="height: 1px;border: 0px;background-color: #cccccc;" />
Oops, something went wrong.

0 comments on commit 6916669

Please sign in to comment.