diff options
author | Fabian Becker <halfdan@xnorfz.de> | 2013-06-22 23:47:29 +0400 |
---|---|---|
committer | Fabian Becker <halfdan@xnorfz.de> | 2013-06-22 23:47:29 +0400 |
commit | 165ac7aeec855234e8c60bd758fad39bd6659adf (patch) | |
tree | e42ace9f7f45e420f883245a8df1beefa8eac9b0 /plugins/VisitorInterest | |
parent | 89d41940a87d449114f529df115b62d3987f88ce (diff) | |
parent | e2e5176279255b7ff2d80f0f511a1ef5f3748ebe (diff) |
Huge merge! Lets see how the tests run..
Merge branch 'master' into 2.x-twig
Conflicts:
core/ReportRenderer/Html.php
core/SmartyPlugins/function.ajaxLoadingDiv.php
plugins/CoreAdminHome/templates/jsTrackingGenerator.tpl
plugins/CoreHome/templates/donate.tpl
plugins/CoreHome/templates/html_report_header.tpl
plugins/CoreHome/templates/menu.tpl
plugins/CoreHome/templates/period_select.tpl
plugins/CoreHome/templates/reports_by_dimension.tpl
plugins/Feedback/templates/index.tpl
plugins/Goals/Controller.php
plugins/Goals/templates/overview.tpl
plugins/Live/API.php
plugins/Live/templates/lastVisits.tpl
plugins/Live/templates/visitorLog.tpl
plugins/MobileMessaging/templates/SMSReport.tpl
plugins/PDFReports/templates/add.tpl
plugins/PDFReports/templates/list.tpl
plugins/PDFReports/templates/report_parameters.tpl
plugins/SEO/templates/index.tpl
plugins/SegmentEditor/templates/selector.twig
plugins/UserCountry/javascripts/userCountry.js
plugins/Zeitgeist/stylesheets/common.css
tests/PHPUnit/Integration/expected/test_ManyVisitorsOneWebsiteTest__UserCountry.getCity_month.xml
tests/PHPUnit/Integration/expected/test_ManyVisitorsOneWebsiteTest__UserCountry.getCountry_month.xml
tests/PHPUnit/Integration/expected/test_ManyVisitorsOneWebsiteTest__UserCountry.getRegion_month.xml
tests/PHPUnit/Integration/expected/test_ManyVisitorsOneWebsiteTest_segment_continent__UserCountry.getCountry_month.xml
Diffstat (limited to 'plugins/VisitorInterest')
-rw-r--r-- | plugins/VisitorInterest/API.php | 13 | ||||
-rw-r--r-- | plugins/VisitorInterest/Archiver.php | 146 | ||||
-rw-r--r-- | plugins/VisitorInterest/VisitorInterest.php | 184 |
3 files changed, 161 insertions, 182 deletions
diff --git a/plugins/VisitorInterest/API.php b/plugins/VisitorInterest/API.php index 7adfd7ca4e..deaec5a68e 100644 --- a/plugins/VisitorInterest/API.php +++ b/plugins/VisitorInterest/API.php @@ -27,7 +27,7 @@ class Piwik_VisitorInterest_API return self::$instance; } - protected function getDataTable($name, $idSite, $period, $date, $segment, $column = Piwik_Archive::INDEX_NB_VISITS) + protected function getDataTable($name, $idSite, $period, $date, $segment, $column = Piwik_Metrics::INDEX_NB_VISITS) { Piwik::checkUserHasViewAccess($idSite); $archive = Piwik_Archive::build($idSite, $period, $date, $segment); @@ -38,7 +38,7 @@ class Piwik_VisitorInterest_API public function getNumberOfVisitsPerVisitDuration($idSite, $period, $date, $segment = false) { - $dataTable = $this->getDataTable('VisitorInterest_timeGap', $idSite, $period, $date, $segment); + $dataTable = $this->getDataTable(Piwik_VisitorInterest_Archiver::TIME_SPENT_RECORD_NAME, $idSite, $period, $date, $segment); $dataTable->queueFilter('Sort', array('label', 'asc', true)); $dataTable->queueFilter('BeautifyTimeRangeLabels', array( Piwik_Translate('VisitorInterest_BetweenXYSeconds'), @@ -49,7 +49,7 @@ class Piwik_VisitorInterest_API public function getNumberOfVisitsPerPage($idSite, $period, $date, $segment = false) { - $dataTable = $this->getDataTable('VisitorInterest_pageGap', $idSite, $period, $date, $segment); + $dataTable = $this->getDataTable(Piwik_VisitorInterest_Archiver::PAGES_VIEWED_RECORD_NAME, $idSite, $period, $date, $segment); $dataTable->queueFilter('Sort', array('label', 'asc', true)); $dataTable->queueFilter('BeautifyRangeLabels', array( Piwik_Translate('VisitorInterest_OnePage'), @@ -69,9 +69,8 @@ class Piwik_VisitorInterest_API */ public function getNumberOfVisitsByDaysSinceLast($idSite, $period, $date, $segment = false) { - $recordName = 'VisitorInterest_daysSinceLastVisit'; $dataTable = $this->getDataTable( - $recordName, $idSite, $period, $date, $segment, Piwik_Archive::INDEX_NB_VISITS); + Piwik_VisitorInterest_Archiver::DAYS_SINCE_LAST_RECORD_NAME, $idSite, $period, $date, $segment, Piwik_Metrics::INDEX_NB_VISITS); $dataTable->queueFilter('BeautifyRangeLabels', array( Piwik_Translate('General_OneDay'), Piwik_Translate('General_NDays'))); @@ -92,7 +91,7 @@ class Piwik_VisitorInterest_API public function getNumberOfVisitsByVisitCount($idSite, $period, $date, $segment = false) { $dataTable = $this->getDataTable( - 'VisitorInterest_visitsByVisitCount', $idSite, $period, $date, $segment, Piwik_Archive::INDEX_NB_VISITS); + Piwik_VisitorInterest_Archiver::VISITS_COUNT_RECORD_NAME, $idSite, $period, $date, $segment, Piwik_Metrics::INDEX_NB_VISITS); $dataTable->queueFilter('BeautifyRangeLabels', array( Piwik_Translate('General_OneVisit'), Piwik_Translate('General_NVisits'))); @@ -117,7 +116,7 @@ class Piwik_VisitorInterest_API self::addVisitsPercentColumn($table); } } else { - $totalVisits = array_sum($dataTable->getColumn(Piwik_Archive::INDEX_NB_VISITS)); + $totalVisits = array_sum($dataTable->getColumn(Piwik_Metrics::INDEX_NB_VISITS)); $dataTable->queueFilter('ColumnCallbackAddColumnPercentage', array( 'nb_visits_percentage', 'nb_visits', $totalVisits)); } diff --git a/plugins/VisitorInterest/Archiver.php b/plugins/VisitorInterest/Archiver.php new file mode 100644 index 0000000000..1720589a7f --- /dev/null +++ b/plugins/VisitorInterest/Archiver.php @@ -0,0 +1,146 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + * @category Piwik_Plugins + * @package Piwik_VisitorInterest + */ + +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 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'), + array(31, 60, 's'), + array(1, 2), + array(2, 4), + array(4, 7), + array(7, 10), + array(10, 15), + array(15, 30), + array(30) + ); + protected static $pageGap = array( + array(1, 1), + array(2, 2), + array(3, 3), + array(4, 4), + array(5, 5), + array(6, 7), + array(8, 10), + array(11, 14), + array(15, 20), + array(20) + ); + /** + * The set of ranges used when calculating the 'visitors who visited at least N times' report. + */ + protected static $visitNumberGap = array( + array(1, 1), + array(2, 2), + array(3, 3), + array(4, 4), + array(5, 5), + array(6, 6), + array(7, 7), + array(8, 8), + array(9, 14), + array(15, 25), + array(26, 50), + array(51, 100), + array(101, 200), + array(200) + ); + /** + * The set of ranges used when calculating the 'days since last visit' report. + */ + protected static $daysSinceLastVisitGap = array( + array(0, 0), + array(1, 1), + array(2, 2), + array(3, 3), + array(4, 4), + array(5, 5), + array(6, 6), + array(7, 7), + array(8, 14), + array(15, 30), + array(31, 60), + array(61, 120), + array(121, 364), + array(364) + ); + + public function archiveDay() + { + // 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. + $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', + ); + + $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->getLogAggregator()->queryVisitsByDimension(array(), $where = false, $selects, array()); + $row = $query->fetch(); + foreach($prefixes as $recordName => $selectAsPrefix) { + $cleanRow = Piwik_DataAccess_LogAggregator::makeArrayOneColumn($row, Piwik_Metrics::INDEX_NB_VISITS, $selectAsPrefix); + $dataTable = Piwik_DataTable::makeFromIndexedArray($cleanRow); + $this->getProcessor()->insertBlobRecord($recordName, $dataTable->getSerialized()); + } + } + + /** + * 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. + */ + protected static function getSecondsGap() + { + $secondsGap = array(); + foreach (self::$timeGap as $gap) { + if (count($gap) == 3 && $gap[2] == 's') // if the units are already in seconds, just assign them + { + $secondsGap[] = array($gap[0], $gap[1]); + } else if (count($gap) == 2) { + $secondsGap[] = array($gap[0] * 60, $gap[1] * 60); + } else { + $secondsGap[] = array($gap[0] * 60); + } + } + return $secondsGap; + } + + public function archivePeriod() + { + $dataTableToSum = array( + self::TIME_SPENT_RECORD_NAME, + self::PAGES_VIEWED_RECORD_NAME, + self::VISITS_COUNT_RECORD_NAME, + self::DAYS_SINCE_LAST_RECORD_NAME + ); + $this->getProcessor()->aggregateDataTableReports($dataTableToSum); + } +}
\ No newline at end of file diff --git a/plugins/VisitorInterest/VisitorInterest.php b/plugins/VisitorInterest/VisitorInterest.php index 00689e5c2c..c2a46f1f9e 100644 --- a/plugins/VisitorInterest/VisitorInterest.php +++ b/plugins/VisitorInterest/VisitorInterest.php @@ -123,192 +123,26 @@ class Piwik_VisitorInterest extends Piwik_Plugin Piwik_AddAction('template_footerVisitsFrequency', array('Piwik_VisitorInterest', 'footerVisitsFrequency')); } - // third element is unit (s for seconds, default is munutes) - protected static $timeGap = array( - array(0, 10, 's'), - array(11, 30, 's'), - array(31, 60, 's'), - array(1, 2), - array(2, 4), - array(4, 7), - array(7, 10), - array(10, 15), - array(15, 30), - array(30) - ); - - protected static $pageGap = array( - array(1, 1), - array(2, 2), - array(3, 3), - array(4, 4), - array(5, 5), - array(6, 7), - array(8, 10), - array(11, 14), - array(15, 20), - array(20) - ); - - /** - * The set of ranges used when calculating the 'visitors who visited at least N times' report. - */ - protected static $visitNumberGap = array( - array(1, 1), - array(2, 2), - array(3, 3), - array(4, 4), - array(5, 5), - array(6, 6), - array(7, 7), - array(8, 8), - array(9, 14), - array(15, 25), - array(26, 50), - array(51, 100), - array(101, 200), - array(200) - ); - - /** - * The set of ranges used when calculating the 'days since last visit' report. - */ - protected static $daysSinceLastVisitGap = array( - array(0, 0), - array(1, 1), - array(2, 2), - array(3, 3), - array(4, 4), - array(5, 5), - array(6, 6), - array(7, 7), - array(8, 14), - array(15, 30), - array(31, 60), - array(61, 120), - array(121, 364), - array(364) - ); - - /** - * @param Piwik_Event_Notification $notification notification object - * @return mixed - */ function archivePeriod($notification) { - $archiveProcessing = $notification->getNotificationObject(); - - if (!$archiveProcessing->shouldProcessReportsForPlugin($this->getPluginName())) return; + $archiveProcessor = $notification->getNotificationObject(); - $dataTableToSum = array( - 'VisitorInterest_timeGap', - 'VisitorInterest_pageGap', - 'VisitorInterest_visitsByVisitCount', - 'VisitorInterest_daysSinceLastVisit' - ); - $archiveProcessing->archiveDataTable($dataTableToSum); + $archiving = new Piwik_VisitorInterest_Archiver($archiveProcessor); + if($archiving->shouldArchive()) { + $archiving->archivePeriod(); + } } - /** - * @param Piwik_Event_Notification $notification notification object - * @return mixed - */ public function archiveDay($notification) { - $this->archiveProcessing = $notification->getNotificationObject(); - - if (!$this->archiveProcessing->shouldProcessReportsForPlugin($this->getPluginName())) return; - - // 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'; + $archiveProcessor = $notification->getNotificationObject(); - // 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'; - $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); - $pageGapSelects = Piwik_ArchiveProcessing_Day::buildReduceByRangeSelect( - 'visit_total_actions', self::$pageGap, 'log_visit', $pageGapPrefix); - $visitsByVisitNumSelects = Piwik_ArchiveProcessing_Day::buildReduceByRangeSelect( - 'visitor_count_visits', self::$visitNumberGap, 'log_visit', $visitsByVisitNumPrefix); - - $daysSinceLastVisitSelects = Piwik_ArchiveProcessing_Day::buildReduceByRangeSelect( - 'visitor_days_since_last', self::$daysSinceLastVisitGap, 'log_visit', $daysSinceLastVisitPrefix, - $daysSinceLastExtraCondition); - array_unshift($daysSinceLastVisitSelects, $newVisitCountSelect); - - $selects = array_merge( - $timeGapSelects, $pageGapSelects, $visitsByVisitNumSelects, $daysSinceLastVisitSelects); - - // select data for every report - $row = $this->archiveProcessing->queryVisitsSimple(implode(',', $selects)); - - // archive visits by total time report - $recordName = 'VisitorInterest_timeGap'; - $this->archiveRangeStats($recordName, $row, Piwik_Archive::INDEX_NB_VISITS, $timeGapPrefix); - - // archive visits by total actions report - $recordName = 'VisitorInterest_pageGap'; - $this->archiveRangeStats($recordName, $row, Piwik_Archive::INDEX_NB_VISITS, $pageGapPrefix); - - // archive visits by visit number report - $recordName = 'VisitorInterest_visitsByVisitCount'; - $this->archiveRangeStats($recordName, $row, Piwik_Archive::INDEX_NB_VISITS, $visitsByVisitNumPrefix); - - // archive days since last visit report - $recordName = 'VisitorInterest_daysSinceLastVisit'; - $this->archiveRangeStats($recordName, $row, Piwik_Archive::INDEX_NB_VISITS, $daysSinceLastVisitPrefix); - } - - /** - * 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. - */ - protected static function getSecondsGap() - { - $secondsGap = array(); - foreach (self::$timeGap as $gap) { - if (count($gap) == 3 && $gap[2] == 's') // if the units are already in seconds, just assign them - { - $secondsGap[] = array($gap[0], $gap[1]); - } else if (count($gap) == 2) { - $secondsGap[] = array($gap[0] * 60, $gap[1] * 60); - } else { - $secondsGap[] = array($gap[0] * 60); - } + $archiving = new Piwik_VisitorInterest_Archiver($archiveProcessor); + if($archiving->shouldArchive()) { + $archiving->archiveDay(); } - return $secondsGap; } - /** - * Creates and archives a DataTable from some (or all) elements of a supplied database - * row. - * - * @param string $recordName The record name to use when inserting the new archive. - * @param array $row The database row to use. - * @param string $selectAsPrefix The string to look for as the prefix of SELECT as - * expressions. Elements in $row that have a SELECT as - * with this string as a prefix are used in creating - * the DataTable.' - */ - protected function archiveRangeStats($recordName, $row, $index, $selectAsPrefix) - { - // create the DataTable from parts of the result row - $dataTable = $this->archiveProcessing->getSimpleDataTableFromRow($row, $index, $selectAsPrefix); - - // insert the data table as a blob archive - $this->archiveProcessing->insertBlobRecord($recordName, $dataTable->getSerialized()); - destroy($dataTable); - } /** * @param Piwik_Event_Notification $notification notification object |