Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattab <matthieu.aubry@gmail.com>2013-06-07 06:37:20 +0400
committermattab <matthieu.aubry@gmail.com>2013-06-07 06:37:20 +0400
commite7267041b56679f3f95d0a1d35836eec37d0d85c (patch)
treed5e2c0ce9f935cfa2a010f3853f97156b7ca1bbb /plugins/VisitorInterest/Archiver.php
parentb53839f7e40f584066c13f60e5b37542b3c10cad (diff)
factoring out record names as const
Diffstat (limited to 'plugins/VisitorInterest/Archiver.php')
-rw-r--r--plugins/VisitorInterest/Archiver.php52
1 files changed, 28 insertions, 24 deletions
diff --git a/plugins/VisitorInterest/Archiver.php b/plugins/VisitorInterest/Archiver.php
index 59e7e348c1..fc797e44f3 100644
--- a/plugins/VisitorInterest/Archiver.php
+++ b/plugins/VisitorInterest/Archiver.php
@@ -14,8 +14,9 @@ class Piwik_VisitorInterest_Archiver extends Piwik_PluginsArchiver
// third element is unit (s for seconds, default is munutes)
const TIME_SPENT_RECORD_NAME = 'VisitorInterest_timeGap';
const PAGES_VIEWED_RECORD_NAME = 'VisitorInterest_pageGap';
- const BY_VISIT_COUNT_RECORD_NAME = 'VisitorInterest_visitsByVisitCount';
+ const VISITS_COUNT_RECORD_NAME = 'VisitorInterest_visitsByVisitCount';
const DAYS_SINCE_LAST_RECORD_NAME = 'VisitorInterest_daysSinceLastVisit';
+
protected static $timeGap = array(
array(0, 10, 's'),
array(11, 30, 's'),
@@ -83,29 +84,44 @@ class Piwik_VisitorInterest_Archiver extends Piwik_PluginsArchiver
{
// these prefixes are prepended to the 'SELECT as' parts of each SELECT expression. detecting
// these prefixes allows us to get all the data in one query.
- $timeGapPrefix = 'tg';
- $pageGapPrefix = 'pg';
- $visitsByVisitNumPrefix = 'vbvn';
- $daysSinceLastVisitPrefix = 'dslv';
+ $prefixes = array(
+ self::TIME_SPENT_RECORD_NAME => 'tg',
+ self::PAGES_VIEWED_RECORD_NAME => 'pg',
+ self::VISITS_COUNT_RECORD_NAME => 'vbvn',
+ self::DAYS_SINCE_LAST_RECORD_NAME => 'dslv',
+ );
+ $row = $this->aggregateFromVisits($prefixes);
+
+ foreach($prefixes as $recordName => $selectAsPrefix) {
+ $processor = $this->getProcessor();
+ $dataTable = $processor->getSimpleDataTableFromRow($row, Piwik_Archive::INDEX_NB_VISITS, $selectAsPrefix);
+ $processor->insertBlobRecord($recordName, $dataTable->getSerialized());
+ }
+ }
+ protected function aggregateFromVisits($prefixes)
+ {
// extra condition for the SQL SELECT that makes sure only returning visits are counted
// when creating the 'days since last visit' report. the SELECT expression below it
// is used to count all new visits.
$daysSinceLastExtraCondition = 'and log_visit.visitor_returning = 1';
- $selectAs = $daysSinceLastVisitPrefix . 'General_NewVisits';
+ $selectAs = $prefixes[self::DAYS_SINCE_LAST_RECORD_NAME] . 'General_NewVisits';
$newVisitCountSelect = "sum(case when log_visit.visitor_returning = 0 then 1 else 0 end) as `$selectAs`";
// create the select expressions to use
$timeGapSelects = Piwik_ArchiveProcessing_Day::buildReduceByRangeSelect(
- 'visit_total_time', self::getSecondsGap(), 'log_visit', $timeGapPrefix);
+ 'visit_total_time', self::getSecondsGap(), 'log_visit', $prefixes[self::TIME_SPENT_RECORD_NAME]);
+
$pageGapSelects = Piwik_ArchiveProcessing_Day::buildReduceByRangeSelect(
- 'visit_total_actions', self::$pageGap, 'log_visit', $pageGapPrefix);
+ 'visit_total_actions', self::$pageGap, 'log_visit', $prefixes[self::PAGES_VIEWED_RECORD_NAME]);
+
$visitsByVisitNumSelects = Piwik_ArchiveProcessing_Day::buildReduceByRangeSelect(
- 'visitor_count_visits', self::$visitNumberGap, 'log_visit', $visitsByVisitNumPrefix);
+ 'visitor_count_visits', self::$visitNumberGap, 'log_visit', $prefixes[self::VISITS_COUNT_RECORD_NAME]);
$daysSinceLastVisitSelects = Piwik_ArchiveProcessing_Day::buildReduceByRangeSelect(
- 'visitor_days_since_last', self::$daysSinceLastVisitGap, 'log_visit', $daysSinceLastVisitPrefix,
+ 'visitor_days_since_last', self::$daysSinceLastVisitGap, 'log_visit', $prefixes[self::DAYS_SINCE_LAST_RECORD_NAME],
$daysSinceLastExtraCondition);
+
array_unshift($daysSinceLastVisitSelects, $newVisitCountSelect);
$selects = array_merge(
@@ -113,19 +129,7 @@ class Piwik_VisitorInterest_Archiver extends Piwik_PluginsArchiver
// select data for every report
$row = $this->getProcessor()->queryVisitsSimple(implode(',', $selects));
-
- $prefixes = array(
- self::TIME_SPENT_RECORD_NAME => $timeGapPrefix,
- self::PAGES_VIEWED_RECORD_NAME => $pageGapPrefix,
- self::BY_VISIT_COUNT_RECORD_NAME => $visitsByVisitNumPrefix,
- self::DAYS_SINCE_LAST_RECORD_NAME => $daysSinceLastVisitPrefix,
- );
-
- foreach($prefixes as $recordName => $selectAsPrefix) {
- $processor = $this->getProcessor();
- $dataTable = $processor->getSimpleDataTableFromRow($row, Piwik_Archive::INDEX_NB_VISITS, $selectAsPrefix);
- $processor->insertBlobRecord($recordName, $dataTable->getSerialized());
- }
+ return $row;
}
/**
@@ -153,7 +157,7 @@ class Piwik_VisitorInterest_Archiver extends Piwik_PluginsArchiver
$dataTableToSum = array(
self::TIME_SPENT_RECORD_NAME,
self::PAGES_VIEWED_RECORD_NAME,
- self::BY_VISIT_COUNT_RECORD_NAME,
+ self::VISITS_COUNT_RECORD_NAME,
self::DAYS_SINCE_LAST_RECORD_NAME
);
$this->getProcessor()->archiveDataTable($dataTableToSum);