diff options
author | mattab <matthieu.aubry@gmail.com> | 2013-06-10 13:00:42 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2013-06-16 12:10:27 +0400 |
commit | c17139710a43b55b5f48377e6281db6ae602957c (patch) | |
tree | 42fda2ab71074d8d273fab1c444a1fec53957df9 /plugins/VisitorInterest/Archiver.php | |
parent | 7fdd382b2880f291752e33ec6f6f44a5dbb21dec (diff) |
refactoring / improvements of Archiveprocessing (in progress)
such as removing duplicate code and a lot of refactoring, the code is now much more readable!
Diffstat (limited to 'plugins/VisitorInterest/Archiver.php')
-rw-r--r-- | plugins/VisitorInterest/Archiver.php | 56 |
1 files changed, 18 insertions, 38 deletions
diff --git a/plugins/VisitorInterest/Archiver.php b/plugins/VisitorInterest/Archiver.php index f90ea3d2a0..5f0a15d3d0 100644 --- a/plugins/VisitorInterest/Archiver.php +++ b/plugins/VisitorInterest/Archiver.php @@ -90,49 +90,29 @@ class Piwik_VisitorInterest_Archiver extends Piwik_PluginsArchiver self::VISITS_COUNT_RECORD_NAME => 'vbvn', self::DAYS_SINCE_LAST_RECORD_NAME => 'dslv', ); - $row = $this->aggregateFromVisits($prefixes); + $aggregatesMetadata = array( + array('visit_total_time', self::getSecondsGap(), 'log_visit', $prefixes[self::TIME_SPENT_RECORD_NAME]), + array('visit_total_actions', self::$pageGap, 'log_visit', $prefixes[self::PAGES_VIEWED_RECORD_NAME]), + array('visitor_count_visits', self::$visitNumberGap, 'log_visit', $prefixes[self::VISITS_COUNT_RECORD_NAME]), + array('visitor_days_since_last', self::$daysSinceLastVisitGap, 'log_visit', $prefixes[self::DAYS_SINCE_LAST_RECORD_NAME], + $i_am_your_nightmare_DELETE_ME = true + ), + ); + $selects = array(); + foreach($aggregatesMetadata as $aggregateMetadata) { + $selectsFromRangedColumn = Piwik_DataAccess_LogAggregator::getSelectsFromRangedColumn($aggregateMetadata); + $selects = array_merge( $selects, $selectsFromRangedColumn); + } + $query = $this->getProcessor()->queryVisitsByDimension(array(), $where = false, $selects, array()); + $row = $query->fetch(); foreach($prefixes as $recordName => $selectAsPrefix) { - $processor = $this->getProcessor(); - $dataTable = $processor->getSimpleDataTableFromRow($row, Piwik_Archive::INDEX_NB_VISITS, $selectAsPrefix); - $processor->insertBlobRecord($recordName, $dataTable->getSerialized()); + $cleanRow = Piwik_DataAccess_LogAggregator::makeArrayOneColumn($row, Piwik_Archive::INDEX_NB_VISITS, $selectAsPrefix); + $dataTable = Piwik_DataTable::makeFromIndexedArray($cleanRow); + $this->getProcessor()->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 = $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`"; - - $daysSinceLastVisitSelects = Piwik_DataAccess_LogAggregator::buildReduceByRangeSelect( - 'visitor_days_since_last', self::$daysSinceLastVisitGap, 'log_visit', $prefixes[self::DAYS_SINCE_LAST_RECORD_NAME], - $daysSinceLastExtraCondition); - - // create the select expressions to use - $timeGapSelects = Piwik_DataAccess_LogAggregator::buildReduceByRangeSelect( - 'visit_total_time', self::getSecondsGap(), 'log_visit', $prefixes[self::TIME_SPENT_RECORD_NAME]); - - $pageGapSelects = Piwik_DataAccess_LogAggregator::buildReduceByRangeSelect( - 'visit_total_actions', self::$pageGap, 'log_visit', $prefixes[self::PAGES_VIEWED_RECORD_NAME]); - - $visitsByVisitNumSelects = Piwik_DataAccess_LogAggregator::buildReduceByRangeSelect( - 'visitor_count_visits', self::$visitNumberGap, 'log_visit', $prefixes[self::VISITS_COUNT_RECORD_NAME]); - - - array_unshift($daysSinceLastVisitSelects, $newVisitCountSelect); - - $selects = array_merge( - $timeGapSelects, $pageGapSelects, $visitsByVisitNumSelects, $daysSinceLastVisitSelects); - - // select data for every report - $row = $this->getProcessor()->queryVisitsSimple(implode(',', $selects)); - return $row; - } - /** * Transforms and returns the set of ranges used to calculate the 'visits by total time' * report from ranges in minutes to equivalent ranges in seconds. |