From 9302709b4beccdd1d94b58e0791a8373b89d355e Mon Sep 17 00:00:00 2001 From: mattab Date: Fri, 10 May 2013 20:17:14 +1200 Subject: * fixing error/bug in Transition * Multi-Row evolution + Limit selector "10/50/100/500" now works as expected --- plugins/Transitions/API.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'plugins/Transitions') diff --git a/plugins/Transitions/API.php b/plugins/Transitions/API.php index 4457d71046..6712045238 100644 --- a/plugins/Transitions/API.php +++ b/plugins/Transitions/API.php @@ -139,7 +139,7 @@ class Piwik_Transitions_API if ($id < 0) { // an example where this is needed is urls containing < or > $actionName = $originalActionName; - $id = $actionsPlugin->getIdActionFromSegment($actionName, 'idaction_url', Piwik_SegmentExpression::MATCH_EQUALs, 'pageUrl'); + $id = $actionsPlugin->getIdActionFromSegment($actionName, 'idaction_url', Piwik_SegmentExpression::MATCH_EQUAL, 'pageUrl'); } return $id; @@ -289,9 +289,6 @@ class Piwik_Transitions_API } } - /** - * @ignore - */ public function getTranslations() { $controller = new Piwik_Transitions_Controller(); -- cgit v1.2.3 From 6bf302feef0d5624c18d6830be2c9a62826ef1e9 Mon Sep 17 00:00:00 2001 From: mattab Date: Wed, 5 Jun 2013 18:13:36 +1200 Subject: Factoring out + cleanup Provider, UserCountry, Goals --- plugins/Transitions/Transitions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/Transitions') diff --git a/plugins/Transitions/Transitions.php b/plugins/Transitions/Transitions.php index 4adaf3f997..765854bff7 100644 --- a/plugins/Transitions/Transitions.php +++ b/plugins/Transitions/Transitions.php @@ -118,7 +118,7 @@ class Piwik_Transitions extends Piwik_Plugin foreach ($subData as &$row) { if ($referrerType == Piwik_Common::REFERER_TYPE_SEARCH_ENGINE && empty($row['referrer_data'])) { - $row['referrer_data'] = Piwik_Referers::LABEL_KEYWORD_NOT_DEFINED; + $row['referrer_data'] = Piwik_Referers_API::LABEL_KEYWORD_NOT_DEFINED; } $referrerData[$referrerType][Piwik_Archive::INDEX_NB_VISITS] += $row[Piwik_Archive::INDEX_NB_VISITS]; -- cgit v1.2.3 From ea4498a9ce68d621861fa7d8732e922b838ed12d Mon Sep 17 00:00:00 2001 From: mattab Date: Fri, 7 Jun 2013 22:51:29 +1200 Subject: going deeper into the rabbit hole --- plugins/Transitions/API.php | 1 - 1 file changed, 1 deletion(-) (limited to 'plugins/Transitions') diff --git a/plugins/Transitions/API.php b/plugins/Transitions/API.php index 6712045238..897b14923a 100644 --- a/plugins/Transitions/API.php +++ b/plugins/Transitions/API.php @@ -66,7 +66,6 @@ class Piwik_Transitions_API $archiveProcessing->setSite(new Piwik_Site($idSite)); $archiveProcessing->setPeriod(Piwik_Period::advancedFactory($period, $date)); $archiveProcessing->setSegment(new Piwik_Segment($segment, $idSite)); - $archiveProcessing->initForLiveUsage(); // prepare the report $report = array( -- cgit v1.2.3 From c17139710a43b55b5f48377e6281db6ae602957c Mon Sep 17 00:00:00 2001 From: mattab Date: Mon, 10 Jun 2013 21:00:42 +1200 Subject: refactoring / improvements of Archiveprocessing (in progress) such as removing duplicate code and a lot of refactoring, the code is now much more readable! --- plugins/Transitions/Transitions.php | 62 +++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 34 deletions(-) (limited to 'plugins/Transitions') diff --git a/plugins/Transitions/Transitions.php b/plugins/Transitions/Transitions.php index 765854bff7..b92ef87b8c 100644 --- a/plugins/Transitions/Transitions.php +++ b/plugins/Transitions/Transitions.php @@ -79,16 +79,15 @@ class Piwik_Transitions extends Piwik_Plugin // group by. when we group by both, we don't get a single column for the keyword but instead // one column per keyword + search engine url. this way, we could not get the top keywords using // the ranking query. - $dimension = 'referrer_data'; + $dimensions = array('referrer_data', 'referer_type'); $rankingQuery->addLabelColumn('referrer_data'); - $select = ' - CASE referer_type + $selects = array( + 'CASE referer_type WHEN ' . Piwik_Common::REFERER_TYPE_DIRECT_ENTRY . ' THEN \'\' WHEN ' . Piwik_Common::REFERER_TYPE_SEARCH_ENGINE . ' THEN referer_keyword WHEN ' . Piwik_Common::REFERER_TYPE_WEBSITE . ' THEN referer_url WHEN ' . Piwik_Common::REFERER_TYPE_CAMPAIGN . ' THEN CONCAT(referer_name, \' \', referer_keyword) - END AS referrer_data, - referer_type'; + END AS referrer_data'); // get one limited group per referrer type $rankingQuery->partitionResultIntoMultipleGroups('referer_type', array( @@ -98,14 +97,11 @@ class Piwik_Transitions extends Piwik_Plugin Piwik_Common::REFERER_TYPE_CAMPAIGN )); - $orderBy = '`' . Piwik_Archive::INDEX_NB_VISITS . '` DESC'; - $type = $this->getColumnTypeSuffix($actionType); $where = 'visit_entry_idaction_' . $type . ' = ' . intval($idaction); $metrics = array(Piwik_Archive::INDEX_NB_VISITS); - $data = $archiveProcessing->queryVisitsByDimension($dimension, $where, $metrics, $orderBy, - $rankingQuery, $select, $selectGeneratesLabelColumn = true); + $data = $archiveProcessing->queryVisitsByDimension($dimensions, $where, $selects, $metrics, $rankingQuery); $referrerData = array(); $referrerSubData = array(); @@ -132,7 +128,9 @@ class Piwik_Transitions extends Piwik_Plugin } } - return $archiveProcessing->getDataTableWithSubtablesFromArraysIndexedByLabel($referrerSubData, $referrerData); + //FIXMEA refactor after integration tests written + $array = new Piwik_DataArray($referrerData, $referrerSubData); + return Piwik_ArchiveProcessing_Day::getDataTableFromDataArray($array); } /** @@ -161,14 +159,16 @@ class Piwik_Transitions extends Piwik_Plugin $dimension = 'idaction_name_ref'; } - $addSelect = ' - log_action.name, log_action.url_prefix, - CASE WHEN log_link_visit_action.idaction_' . $type . '_ref = ' . intval($idaction) . ' THEN 1 ELSE 0 END AS is_self, - CASE - WHEN log_action.type = ' . $mainActionType . ' THEN 1 - WHEN log_action.type = ' . Piwik_Tracker_Action::TYPE_SITE_SEARCH . ' THEN 2 - ELSE 0 - END AS action_partition'; + $selects = array( + 'log_action.name', + 'log_action.url_prefix', + 'CASE WHEN log_link_visit_action.idaction_' . $type . '_ref = ' . intval($idaction) . ' THEN 1 ELSE 0 END AS is_self', + 'CASE + WHEN log_action.type = ' . $mainActionType . ' THEN 1 + WHEN log_action.type = ' . Piwik_Tracker_Action::TYPE_SITE_SEARCH . ' THEN 2 + ELSE 0 + END AS action_partition' + ); $where = ' log_link_visit_action.idaction_' . $type . ' = ' . intval($idaction); @@ -183,11 +183,8 @@ class Piwik_Transitions extends Piwik_Plugin $dimension = array($dimension); } - $orderBy = '`' . Piwik_Archive::INDEX_NB_ACTIONS . '` DESC'; - $metrics = array(Piwik_Archive::INDEX_NB_ACTIONS); - $data = $archiveProcessing->queryActionsByDimension($dimension, $where, $metrics, $orderBy, - $rankingQuery, $joinLogActionOn, $addSelect); + $data = $archiveProcessing->queryActionsByDimension($dimension, $where, $selects, $metrics, $rankingQuery, $joinLogActionOn); $loops = 0; $nbPageviews = 0; @@ -278,7 +275,7 @@ class Piwik_Transitions extends Piwik_Plugin // site search referrers are logged with url=NULL // when we find one, we have to join on name $joinLogActionColumn = $dimension; - $addSelect = 'log_action.name, log_action.url_prefix, log_action.type'; + $selects = array('log_action.name', 'log_action.url_prefix', 'log_action.type'); } else { // specific setup for page titles: $types[Piwik_Tracker_Action::TYPE_ACTION_NAME] = 'followingPages'; @@ -295,25 +292,25 @@ class Piwik_Transitions extends Piwik_Plugin ELSE log_action1.idaction END '; - $addSelect = ' - CASE + $selects = array( + 'CASE ' /* following site search */ . ' WHEN log_link_visit_action.idaction_url IS NULL THEN log_action2.name ' /* following page view: use page title */ . ' WHEN log_action1.type = ' . Piwik_Tracker_Action::TYPE_ACTION_URL . ' THEN log_action2.name ' /* following download or outlink: use url */ . ' ELSE log_action1.name - END AS name, - CASE + END AS name', + 'CASE ' /* following site search */ . ' WHEN log_link_visit_action.idaction_url IS NULL THEN log_action2.type ' /* following page view: use page title */ . ' WHEN log_action1.type = ' . Piwik_Tracker_Action::TYPE_ACTION_URL . ' THEN log_action2.type ' /* following download or outlink: use url */ . ' ELSE log_action1.type - END AS type, - NULL AS url_prefix - '; + END AS type', + 'NULL AS url_prefix' + ); } // these types are available for both titles and urls @@ -332,11 +329,8 @@ class Piwik_Transitions extends Piwik_Plugin . 'log_link_visit_action.idaction_' . $type . ' != ' . intval($idaction) . ')'; } - $orderBy = '`' . Piwik_Archive::INDEX_NB_ACTIONS . '` DESC'; - $metrics = array(Piwik_Archive::INDEX_NB_ACTIONS); - $data = $archiveProcessing->queryActionsByDimension($dimension, $where, $metrics, $orderBy, - $rankingQuery, $joinLogActionColumn, $addSelect); + $data = $archiveProcessing->queryActionsByDimension($dimension, $where, $selects, $metrics, $rankingQuery, $joinLogActionColumn); $this->totalTransitionsToFollowingActions = 0; $dataTables = array(); -- cgit v1.2.3 From d8f110aca03ff8c73811a141631f12a7a1ddc16f Mon Sep 17 00:00:00 2001 From: mattab Date: Wed, 12 Jun 2013 16:23:51 +1200 Subject: More refactoring, moving SQL to classes and cleaning up logic so I can understand it (nearly there) --- plugins/Transitions/API.php | 8 ++++---- plugins/Transitions/Transitions.php | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'plugins/Transitions') diff --git a/plugins/Transitions/API.php b/plugins/Transitions/API.php index 897b14923a..7e17fa2996 100644 --- a/plugins/Transitions/API.php +++ b/plugins/Transitions/API.php @@ -62,10 +62,10 @@ class Piwik_Transitions_API } // prepare archive processing that can be used by the archiving code - $archiveProcessing = new Piwik_ArchiveProcessing_Day(); - $archiveProcessing->setSite(new Piwik_Site($idSite)); - $archiveProcessing->setPeriod(Piwik_Period::advancedFactory($period, $date)); - $archiveProcessing->setSegment(new Piwik_Segment($segment, $idSite)); + $segment = new Piwik_Segment($segment, $idSite); + $site = new Piwik_Site($idSite); + $period = Piwik_Period::advancedFactory($period, $date); + $archiveProcessing = Piwik_ArchiveProcessor::factory($period, $site, $segment); // prepare the report $report = array( diff --git a/plugins/Transitions/Transitions.php b/plugins/Transitions/Transitions.php index b92ef87b8c..b887669a70 100644 --- a/plugins/Transitions/Transitions.php +++ b/plugins/Transitions/Transitions.php @@ -64,7 +64,7 @@ class Piwik_Transitions extends Piwik_Plugin * * @param $idaction * @param $actionType - * @param Piwik_ArchiveProcessing_Day $archiveProcessing + * @param Piwik_ArchiveProcessor_Day $archiveProcessing * @param $limitBeforeGrouping * @return Piwik_DataTable */ @@ -130,7 +130,7 @@ class Piwik_Transitions extends Piwik_Plugin //FIXMEA refactor after integration tests written $array = new Piwik_DataArray($referrerData, $referrerSubData); - return Piwik_ArchiveProcessing_Day::getDataTableFromDataArray($array); + return Piwik_ArchiveProcessor_Day::getDataTableFromDataArray($array); } /** @@ -138,7 +138,7 @@ class Piwik_Transitions extends Piwik_Plugin * * @param $idaction * @param $actionType - * @param Piwik_ArchiveProcessing_Day $archiveProcessing + * @param Piwik_ArchiveProcessor_Day $archiveProcessing * @param $limitBeforeGrouping * @return array(previousPages:Piwik_DataTable, loops:integer) */ @@ -257,12 +257,12 @@ class Piwik_Transitions extends Piwik_Plugin * * @param $idaction * @param $actionType - * @param Piwik_ArchiveProcessing_Day $archiveProcessing + * @param Piwik_ArchiveProcessor_Day $archiveProcessing * @param $limitBeforeGrouping * @param $includeLoops * @return array(followingPages:Piwik_DataTable, outlinks:Piwik_DataTable, downloads:Piwik_DataTable) */ - public function queryFollowingActions($idaction, $actionType, Piwik_ArchiveProcessing_Day $archiveProcessing, + public function queryFollowingActions($idaction, $actionType, Piwik_ArchiveProcessor_Day $archiveProcessing, $limitBeforeGrouping = false, $includeLoops = false) { $types = array(); -- cgit v1.2.3 From 6be9fb2002a0a7da79af55e3263f23c5addfa79c Mon Sep 17 00:00:00 2001 From: mattab Date: Thu, 13 Jun 2013 11:52:49 +1200 Subject: Continuing the great cleanup. It looks like archiveProcessor will have to go (and merge with Archive) Moving Transitions logic from plugin class to API Cleaning up some separation of concerns NOTE: I'm breaking the Multisites API here, removing the _evolution. we should re-fix it... --- plugins/Transitions/API.php | 337 +++++++++++++++++++++++++++++++++++- plugins/Transitions/Transitions.php | 325 ---------------------------------- 2 files changed, 333 insertions(+), 329 deletions(-) (limited to 'plugins/Transitions') diff --git a/plugins/Transitions/API.php b/plugins/Transitions/API.php index 7e17fa2996..7294a78560 100644 --- a/plugins/Transitions/API.php +++ b/plugins/Transitions/API.php @@ -65,11 +65,11 @@ class Piwik_Transitions_API $segment = new Piwik_Segment($segment, $idSite); $site = new Piwik_Site($idSite); $period = Piwik_Period::advancedFactory($period, $date); - $archiveProcessing = Piwik_ArchiveProcessor::factory($period, $site, $segment); + $archiveProcessing = new Piwik_ArchiveProcessor_Day($period, $site, $segment); // prepare the report $report = array( - 'date' => Piwik_Period_Day::advancedFactory($period, $date)->getLocalizedShortString() + 'date' => Piwik_Period_Day::advancedFactory($period->getLabel(), $date)->getLocalizedShortString() ); // add data to the report @@ -178,7 +178,7 @@ class Piwik_Transitions_API $idaction, $actionType, $limitBeforeGrouping) { - $data = $transitionsArchiving->queryInternalReferrers( + $data = $this->queryInternalReferrers( $idaction, $actionType, $archiveProcessing, $limitBeforeGrouping); if ($data['pageviews'] == 0) { @@ -207,7 +207,7 @@ class Piwik_Transitions_API $idaction, $actionType, $limitBeforeGrouping, $includeLoops = false) { - $data = $transitionsArchiving->queryFollowingActions( + $data = $this->queryFollowingActions( $idaction, $actionType, $archiveProcessing, $limitBeforeGrouping, $includeLoops); foreach ($data as $tableName => $table) { @@ -215,6 +215,335 @@ class Piwik_Transitions_API } } + + + /** + * Get information about the following actions (following pages, site searches, outlinks, downloads) + * + * @param $idaction + * @param $actionType + * @param Piwik_ArchiveProcessor_Day $archiveProcessing + * @param $limitBeforeGrouping + * @param $includeLoops + * @return array(followingPages:Piwik_DataTable, outlinks:Piwik_DataTable, downloads:Piwik_DataTable) + */ + public function queryFollowingActions($idaction, $actionType, Piwik_ArchiveProcessor_Day $archiveProcessing, + $limitBeforeGrouping = false, $includeLoops = false) + { + $types = array(); + + $isTitle = ($actionType == 'title'); + if (!$isTitle) { + // specific setup for page urls + $types[Piwik_Tracker_Action::TYPE_ACTION_URL] = 'followingPages'; + $dimension = 'IF( idaction_url IS NULL, idaction_name, idaction_url )'; + // site search referrers are logged with url=NULL + // when we find one, we have to join on name + $joinLogActionColumn = $dimension; + $selects = array('log_action.name', 'log_action.url_prefix', 'log_action.type'); + } else { + // specific setup for page titles: + $types[Piwik_Tracker_Action::TYPE_ACTION_NAME] = 'followingPages'; + // join log_action on name and url and pick depending on url type + // the table joined on url is log_action1 + $joinLogActionColumn = array('idaction_url', 'idaction_name'); + $dimension = ' + CASE + ' /* following site search */ . ' + WHEN log_link_visit_action.idaction_url IS NULL THEN log_action2.idaction + ' /* following page view: use page title */ . ' + WHEN log_action1.type = ' . Piwik_Tracker_Action::TYPE_ACTION_URL . ' THEN log_action2.idaction + ' /* following download or outlink: use url */ . ' + ELSE log_action1.idaction + END + '; + $selects = array( + 'CASE + ' /* following site search */ . ' + WHEN log_link_visit_action.idaction_url IS NULL THEN log_action2.name + ' /* following page view: use page title */ . ' + WHEN log_action1.type = ' . Piwik_Tracker_Action::TYPE_ACTION_URL . ' THEN log_action2.name + ' /* following download or outlink: use url */ . ' + ELSE log_action1.name + END AS name', + 'CASE + ' /* following site search */ . ' + WHEN log_link_visit_action.idaction_url IS NULL THEN log_action2.type + ' /* following page view: use page title */ . ' + WHEN log_action1.type = ' . Piwik_Tracker_Action::TYPE_ACTION_URL . ' THEN log_action2.type + ' /* following download or outlink: use url */ . ' + ELSE log_action1.type + END AS type', + 'NULL AS url_prefix' + ); + } + + // these types are available for both titles and urls + $types[Piwik_Tracker_Action::TYPE_SITE_SEARCH] = 'followingSiteSearches'; + $types[Piwik_Tracker_Action::TYPE_OUTLINK] = 'outlinks'; + $types[Piwik_Tracker_Action::TYPE_DOWNLOAD] = 'downloads'; + + $rankingQuery = new Piwik_RankingQuery($limitBeforeGrouping ? $limitBeforeGrouping : $this->limitBeforeGrouping); + $rankingQuery->addLabelColumn(array('name', 'url_prefix')); + $rankingQuery->partitionResultIntoMultipleGroups('type', array_keys($types)); + + $type = $this->getColumnTypeSuffix($actionType); + $where = 'log_link_visit_action.idaction_' . $type . '_ref = ' . intval($idaction); + if (!$includeLoops) { + $where .= ' AND (log_link_visit_action.idaction_' . $type . ' IS NULL OR ' + . 'log_link_visit_action.idaction_' . $type . ' != ' . intval($idaction) . ')'; + } + + $metrics = array(Piwik_Archive::INDEX_NB_ACTIONS); + $data = $archiveProcessing->queryActionsByDimension(array($dimension), $where, $selects, $metrics, $rankingQuery, $joinLogActionColumn); + + $this->totalTransitionsToFollowingActions = 0; + $dataTables = array(); + foreach ($types as $type => $recordName) { + $dataTable = new Piwik_DataTable; + if (isset($data[$type])) { + foreach ($data[$type] as &$record) { + $actions = intval($record[Piwik_Archive::INDEX_NB_ACTIONS]); + $dataTable->addRow(new Piwik_DataTable_Row(array( + Piwik_DataTable_Row::COLUMNS => array( + 'label' => $this->getPageLabel($record, $isTitle), + Piwik_Archive::INDEX_NB_ACTIONS => $actions + ) + ))); + $this->totalTransitionsToFollowingActions += $actions; + } + } + $dataTables[$recordName] = $dataTable; + } + + return $dataTables; + } + + + /** + * After calling this method, the query*()-Methods will return urls in their + * normalized form (without the prefix reconstructed) + */ + public function returnNormalizedUrls() + { + $this->returnNormalizedUrls = true; + } + + /** + * Get information about external referrers (i.e. search engines, websites & campaigns) + * + * @param $idaction + * @param $actionType + * @param Piwik_ArchiveProcessor_Day $archiveProcessing + * @param $limitBeforeGrouping + * @return Piwik_DataTable + */ + public function queryExternalReferrers($idaction, $actionType, $archiveProcessing, + $limitBeforeGrouping = false) + { + $rankingQuery = new Piwik_RankingQuery($limitBeforeGrouping ? $limitBeforeGrouping : $this->limitBeforeGrouping); + + // we generate a single column that contains the interesting data for each referrer. + // the reason we cannot group by referer_* becomes clear when we look at search engine keywords. + // referer_url contains the url from the search engine, referer_keyword the keyword we want to + // group by. when we group by both, we don't get a single column for the keyword but instead + // one column per keyword + search engine url. this way, we could not get the top keywords using + // the ranking query. + $dimensions = array('referrer_data', 'referer_type'); + $rankingQuery->addLabelColumn('referrer_data'); + $selects = array( + 'CASE referer_type + WHEN ' . Piwik_Common::REFERER_TYPE_DIRECT_ENTRY . ' THEN \'\' + WHEN ' . Piwik_Common::REFERER_TYPE_SEARCH_ENGINE . ' THEN referer_keyword + WHEN ' . Piwik_Common::REFERER_TYPE_WEBSITE . ' THEN referer_url + WHEN ' . Piwik_Common::REFERER_TYPE_CAMPAIGN . ' THEN CONCAT(referer_name, \' \', referer_keyword) + END AS referrer_data'); + + // get one limited group per referrer type + $rankingQuery->partitionResultIntoMultipleGroups('referer_type', array( + Piwik_Common::REFERER_TYPE_DIRECT_ENTRY, + Piwik_Common::REFERER_TYPE_SEARCH_ENGINE, + Piwik_Common::REFERER_TYPE_WEBSITE, + Piwik_Common::REFERER_TYPE_CAMPAIGN + )); + + $type = $this->getColumnTypeSuffix($actionType); + $where = 'visit_entry_idaction_' . $type . ' = ' . intval($idaction); + + $metrics = array(Piwik_Archive::INDEX_NB_VISITS); + $data = $archiveProcessing->queryVisitsByDimension($dimensions, $where, $selects, $metrics, $rankingQuery); + + $referrerData = array(); + $referrerSubData = array(); + + foreach ($data as $referrerType => &$subData) { + $referrerData[$referrerType] = array(Piwik_Archive::INDEX_NB_VISITS => 0); + if ($referrerType != Piwik_Common::REFERER_TYPE_DIRECT_ENTRY) { + $referrerSubData[$referrerType] = array(); + } + + foreach ($subData as &$row) { + if ($referrerType == Piwik_Common::REFERER_TYPE_SEARCH_ENGINE && empty($row['referrer_data'])) { + $row['referrer_data'] = Piwik_Referers_API::LABEL_KEYWORD_NOT_DEFINED; + } + + $referrerData[$referrerType][Piwik_Archive::INDEX_NB_VISITS] += $row[Piwik_Archive::INDEX_NB_VISITS]; + + $label = $row['referrer_data']; + if ($label) { + $referrerSubData[$referrerType][$label] = array( + Piwik_Archive::INDEX_NB_VISITS => $row[Piwik_Archive::INDEX_NB_VISITS] + ); + } + } + } + + //FIXMEA refactor after integration tests written + $array = new Piwik_DataArray($referrerData, $referrerSubData); + return Piwik_ArchiveProcessor_Day::getDataTableFromDataArray($array); + } + + /** + * Get information about internal referrers (previous pages & loops, i.e. page refreshes) + * + * @param $idaction + * @param $actionType + * @param Piwik_ArchiveProcessor_Day $archiveProcessing + * @param $limitBeforeGrouping + * @return array(previousPages:Piwik_DataTable, loops:integer) + */ + protected function queryInternalReferrers($idaction, $actionType, $archiveProcessing, + $limitBeforeGrouping = false) + { + $rankingQuery = new Piwik_RankingQuery($limitBeforeGrouping ? $limitBeforeGrouping : $this->limitBeforeGrouping); + $rankingQuery->addLabelColumn(array('name', 'url_prefix')); + $rankingQuery->setColumnToMarkExcludedRows('is_self'); + $rankingQuery->partitionResultIntoMultipleGroups('action_partition', array(0, 1, 2)); + + $type = $this->getColumnTypeSuffix($actionType); + $mainActionType = Piwik_Tracker_Action::TYPE_ACTION_URL; + $dimension = 'idaction_url_ref'; + $isTitle = $actionType == 'title'; + + if ($isTitle) { + $mainActionType = Piwik_Tracker_Action::TYPE_ACTION_NAME; + $dimension = 'idaction_name_ref'; + } + + $selects = array( + 'log_action.name', + 'log_action.url_prefix', + 'CASE WHEN log_link_visit_action.idaction_' . $type . '_ref = ' . intval($idaction) . ' THEN 1 ELSE 0 END AS is_self', + 'CASE + WHEN log_action.type = ' . $mainActionType . ' THEN 1 + WHEN log_action.type = ' . Piwik_Tracker_Action::TYPE_SITE_SEARCH . ' THEN 2 + ELSE 0 + END AS action_partition' + ); + + $where = ' + log_link_visit_action.idaction_' . $type . ' = ' . intval($idaction); + + if ($dimension == 'idaction_url_ref') { + // site search referrers are logged with url_ref=NULL + // when we find one, we have to join on name_ref + $dimension = 'IF( idaction_url_ref IS NULL, idaction_name_ref, idaction_url_ref )'; + $joinLogActionOn = $dimension; + } else { + $joinLogActionOn = $dimension; + } + $metrics = array(Piwik_Archive::INDEX_NB_ACTIONS); + $data = $archiveProcessing->queryActionsByDimension(array($dimension), $where, $selects, $metrics, $rankingQuery, $joinLogActionOn); + + $loops = 0; + $nbPageviews = 0; + $previousPagesDataTable = new Piwik_DataTable; + if (isset($data['result'][1])) { + foreach ($data['result'][1] as &$page) { + $nbActions = intval($page[Piwik_Archive::INDEX_NB_ACTIONS]); + $previousPagesDataTable->addRow(new Piwik_DataTable_Row(array( + Piwik_DataTable_Row::COLUMNS => array( + 'label' => $this->getPageLabel($page, $isTitle), + Piwik_Archive::INDEX_NB_ACTIONS => $nbActions + ) + ))); + $nbPageviews += $nbActions; + } + } + + $previousSearchesDataTable = new Piwik_DataTable; + if (isset($data['result'][2])) { + foreach ($data['result'][2] as &$search) { + $nbActions = intval($search[Piwik_Archive::INDEX_NB_ACTIONS]); + $previousSearchesDataTable->addRow(new Piwik_DataTable_Row(array( + Piwik_DataTable_Row::COLUMNS => array( + 'label' => $search['name'], + Piwik_Archive::INDEX_NB_ACTIONS => $nbActions + ) + ))); + $nbPageviews += $nbActions; + } + } + + if (isset($data['result'][0])) { + foreach ($data['result'][0] as &$referrer) { + $nbPageviews += intval($referrer[Piwik_Archive::INDEX_NB_ACTIONS]); + } + } + + if (count($data['excludedFromLimit'])) { + $loops += intval($data['excludedFromLimit'][0][Piwik_Archive::INDEX_NB_ACTIONS]); + $nbPageviews += $loops; + } + + return array( + 'pageviews' => $nbPageviews, + 'previousPages' => $previousPagesDataTable, + 'previousSiteSearches' => $previousSearchesDataTable, + 'loops' => $loops + ); + } + + private function getPageLabel(&$pageRecord, $isTitle) + { + if ($isTitle) { + $label = $pageRecord['name']; + if (empty($label)) { + $label = Piwik_Actions_ArchivingHelper::getUnknownActionName( + Piwik_Tracker_Action::TYPE_ACTION_NAME); + } + return $label; + } else if ($this->returnNormalizedUrls) { + return $pageRecord['name']; + } else { + return Piwik_Tracker_Action::reconstructNormalizedUrl( + $pageRecord['name'], $pageRecord['url_prefix']); + } + } + + private function getColumnTypeSuffix($actionType) + { + if ($actionType == 'title') { + return 'name'; + } + return 'url'; + } + + private $limitBeforeGrouping = 5; + private $totalTransitionsToFollowingActions = 0; + + private $returnNormalizedUrls = false; + + + /** + * Get the sum of all transitions to following actions (pages, outlinks, downloads). + * Only works if queryFollowingActions() has been used directly before. + */ + protected function getTotalTransitionsToFollowingActions() + { + return $this->totalTransitionsToFollowingActions; + } + /** * Add the external referrers to the report: * direct entries, websites, campaigns, search engines diff --git a/plugins/Transitions/Transitions.php b/plugins/Transitions/Transitions.php index b887669a70..2c51da023e 100644 --- a/plugins/Transitions/Transitions.php +++ b/plugins/Transitions/Transitions.php @@ -15,11 +15,6 @@ class Piwik_Transitions extends Piwik_Plugin { - private $limitBeforeGrouping = 5; - private $totalTransitionsToFollowingActions = 0; - - private $returnNormalizedUrls = false; - public function getInformation() { return array( @@ -50,325 +45,5 @@ class Piwik_Transitions extends Piwik_Plugin $jsFiles[] = 'plugins/Transitions/templates/transitions.js'; } - /** - * After calling this method, the query*()-Methods will return urls in their - * normalized form (without the prefix reconstructed) - */ - public function returnNormalizedUrls() - { - $this->returnNormalizedUrls = true; - } - - /** - * Get information about external referrers (i.e. search engines, websites & campaigns) - * - * @param $idaction - * @param $actionType - * @param Piwik_ArchiveProcessor_Day $archiveProcessing - * @param $limitBeforeGrouping - * @return Piwik_DataTable - */ - public function queryExternalReferrers($idaction, $actionType, $archiveProcessing, - $limitBeforeGrouping = false) - { - $rankingQuery = new Piwik_RankingQuery($limitBeforeGrouping ? $limitBeforeGrouping : $this->limitBeforeGrouping); - - // we generate a single column that contains the interesting data for each referrer. - // the reason we cannot group by referer_* becomes clear when we look at search engine keywords. - // referer_url contains the url from the search engine, referer_keyword the keyword we want to - // group by. when we group by both, we don't get a single column for the keyword but instead - // one column per keyword + search engine url. this way, we could not get the top keywords using - // the ranking query. - $dimensions = array('referrer_data', 'referer_type'); - $rankingQuery->addLabelColumn('referrer_data'); - $selects = array( - 'CASE referer_type - WHEN ' . Piwik_Common::REFERER_TYPE_DIRECT_ENTRY . ' THEN \'\' - WHEN ' . Piwik_Common::REFERER_TYPE_SEARCH_ENGINE . ' THEN referer_keyword - WHEN ' . Piwik_Common::REFERER_TYPE_WEBSITE . ' THEN referer_url - WHEN ' . Piwik_Common::REFERER_TYPE_CAMPAIGN . ' THEN CONCAT(referer_name, \' \', referer_keyword) - END AS referrer_data'); - - // get one limited group per referrer type - $rankingQuery->partitionResultIntoMultipleGroups('referer_type', array( - Piwik_Common::REFERER_TYPE_DIRECT_ENTRY, - Piwik_Common::REFERER_TYPE_SEARCH_ENGINE, - Piwik_Common::REFERER_TYPE_WEBSITE, - Piwik_Common::REFERER_TYPE_CAMPAIGN - )); - - $type = $this->getColumnTypeSuffix($actionType); - $where = 'visit_entry_idaction_' . $type . ' = ' . intval($idaction); - - $metrics = array(Piwik_Archive::INDEX_NB_VISITS); - $data = $archiveProcessing->queryVisitsByDimension($dimensions, $where, $selects, $metrics, $rankingQuery); - - $referrerData = array(); - $referrerSubData = array(); - - foreach ($data as $referrerType => &$subData) { - $referrerData[$referrerType] = array(Piwik_Archive::INDEX_NB_VISITS => 0); - if ($referrerType != Piwik_Common::REFERER_TYPE_DIRECT_ENTRY) { - $referrerSubData[$referrerType] = array(); - } - - foreach ($subData as &$row) { - if ($referrerType == Piwik_Common::REFERER_TYPE_SEARCH_ENGINE && empty($row['referrer_data'])) { - $row['referrer_data'] = Piwik_Referers_API::LABEL_KEYWORD_NOT_DEFINED; - } - - $referrerData[$referrerType][Piwik_Archive::INDEX_NB_VISITS] += $row[Piwik_Archive::INDEX_NB_VISITS]; - - $label = $row['referrer_data']; - if ($label) { - $referrerSubData[$referrerType][$label] = array( - Piwik_Archive::INDEX_NB_VISITS => $row[Piwik_Archive::INDEX_NB_VISITS] - ); - } - } - } - - //FIXMEA refactor after integration tests written - $array = new Piwik_DataArray($referrerData, $referrerSubData); - return Piwik_ArchiveProcessor_Day::getDataTableFromDataArray($array); - } - - /** - * Get information about internal referrers (previous pages & loops, i.e. page refreshes) - * - * @param $idaction - * @param $actionType - * @param Piwik_ArchiveProcessor_Day $archiveProcessing - * @param $limitBeforeGrouping - * @return array(previousPages:Piwik_DataTable, loops:integer) - */ - public function queryInternalReferrers($idaction, $actionType, $archiveProcessing, - $limitBeforeGrouping = false) - { - $rankingQuery = new Piwik_RankingQuery($limitBeforeGrouping ? $limitBeforeGrouping : $this->limitBeforeGrouping); - $rankingQuery->addLabelColumn(array('name', 'url_prefix')); - $rankingQuery->setColumnToMarkExcludedRows('is_self'); - $rankingQuery->partitionResultIntoMultipleGroups('action_partition', array(0, 1, 2)); - - $type = $this->getColumnTypeSuffix($actionType); - $mainActionType = Piwik_Tracker_Action::TYPE_ACTION_URL; - $dimension = 'idaction_url_ref'; - $isTitle = $actionType == 'title'; - if ($isTitle) { - $mainActionType = Piwik_Tracker_Action::TYPE_ACTION_NAME; - $dimension = 'idaction_name_ref'; - } - - $selects = array( - 'log_action.name', - 'log_action.url_prefix', - 'CASE WHEN log_link_visit_action.idaction_' . $type . '_ref = ' . intval($idaction) . ' THEN 1 ELSE 0 END AS is_self', - 'CASE - WHEN log_action.type = ' . $mainActionType . ' THEN 1 - WHEN log_action.type = ' . Piwik_Tracker_Action::TYPE_SITE_SEARCH . ' THEN 2 - ELSE 0 - END AS action_partition' - ); - - $where = ' - log_link_visit_action.idaction_' . $type . ' = ' . intval($idaction); - - if ($dimension == 'idaction_url_ref') { - // site search referrers are logged with url_ref=NULL - // when we find one, we have to join on name_ref - $dimension = 'IF( idaction_url_ref IS NULL, idaction_name_ref, idaction_url_ref )'; - $joinLogActionOn = $dimension; - } else { - $joinLogActionOn = $dimension; - $dimension = array($dimension); - } - - $metrics = array(Piwik_Archive::INDEX_NB_ACTIONS); - $data = $archiveProcessing->queryActionsByDimension($dimension, $where, $selects, $metrics, $rankingQuery, $joinLogActionOn); - - $loops = 0; - $nbPageviews = 0; - $previousPagesDataTable = new Piwik_DataTable; - if (isset($data['result'][1])) { - foreach ($data['result'][1] as &$page) { - $nbActions = intval($page[Piwik_Archive::INDEX_NB_ACTIONS]); - $previousPagesDataTable->addRow(new Piwik_DataTable_Row(array( - Piwik_DataTable_Row::COLUMNS => array( - 'label' => $this->getPageLabel($page, $isTitle), - Piwik_Archive::INDEX_NB_ACTIONS => $nbActions - ) - ))); - $nbPageviews += $nbActions; - } - } - - $previousSearchesDataTable = new Piwik_DataTable; - if (isset($data['result'][2])) { - foreach ($data['result'][2] as &$search) { - $nbActions = intval($search[Piwik_Archive::INDEX_NB_ACTIONS]); - $previousSearchesDataTable->addRow(new Piwik_DataTable_Row(array( - Piwik_DataTable_Row::COLUMNS => array( - 'label' => $search['name'], - Piwik_Archive::INDEX_NB_ACTIONS => $nbActions - ) - ))); - $nbPageviews += $nbActions; - } - } - - if (isset($data['result'][0])) { - foreach ($data['result'][0] as &$referrer) { - $nbPageviews += intval($referrer[Piwik_Archive::INDEX_NB_ACTIONS]); - } - } - - if (count($data['excludedFromLimit'])) { - $loops += intval($data['excludedFromLimit'][0][Piwik_Archive::INDEX_NB_ACTIONS]); - $nbPageviews += $loops; - } - - return array( - 'pageviews' => $nbPageviews, - 'previousPages' => $previousPagesDataTable, - 'previousSiteSearches' => $previousSearchesDataTable, - 'loops' => $loops - ); - } - - private function getPageLabel(&$pageRecord, $isTitle) - { - if ($isTitle) { - $label = $pageRecord['name']; - if (empty($label)) { - $label = Piwik_Actions_ArchivingHelper::getUnknownActionName( - Piwik_Tracker_Action::TYPE_ACTION_NAME); - } - return $label; - } else if ($this->returnNormalizedUrls) { - return $pageRecord['name']; - } else { - return Piwik_Tracker_Action::reconstructNormalizedUrl( - $pageRecord['name'], $pageRecord['url_prefix']); - } - } - - /** - * Get information about the following actions (following pages, site searches, outlinks, downloads) - * - * @param $idaction - * @param $actionType - * @param Piwik_ArchiveProcessor_Day $archiveProcessing - * @param $limitBeforeGrouping - * @param $includeLoops - * @return array(followingPages:Piwik_DataTable, outlinks:Piwik_DataTable, downloads:Piwik_DataTable) - */ - public function queryFollowingActions($idaction, $actionType, Piwik_ArchiveProcessor_Day $archiveProcessing, - $limitBeforeGrouping = false, $includeLoops = false) - { - $types = array(); - - $isTitle = ($actionType == 'title'); - if (!$isTitle) { - // specific setup for page urls - $types[Piwik_Tracker_Action::TYPE_ACTION_URL] = 'followingPages'; - $dimension = 'IF( idaction_url IS NULL, idaction_name, idaction_url )'; - // site search referrers are logged with url=NULL - // when we find one, we have to join on name - $joinLogActionColumn = $dimension; - $selects = array('log_action.name', 'log_action.url_prefix', 'log_action.type'); - } else { - // specific setup for page titles: - $types[Piwik_Tracker_Action::TYPE_ACTION_NAME] = 'followingPages'; - // join log_action on name and url and pick depending on url type - // the table joined on url is log_action1 - $joinLogActionColumn = array('idaction_url', 'idaction_name'); - $dimension = ' - CASE - ' /* following site search */ . ' - WHEN log_link_visit_action.idaction_url IS NULL THEN log_action2.idaction - ' /* following page view: use page title */ . ' - WHEN log_action1.type = ' . Piwik_Tracker_Action::TYPE_ACTION_URL . ' THEN log_action2.idaction - ' /* following download or outlink: use url */ . ' - ELSE log_action1.idaction - END - '; - $selects = array( - 'CASE - ' /* following site search */ . ' - WHEN log_link_visit_action.idaction_url IS NULL THEN log_action2.name - ' /* following page view: use page title */ . ' - WHEN log_action1.type = ' . Piwik_Tracker_Action::TYPE_ACTION_URL . ' THEN log_action2.name - ' /* following download or outlink: use url */ . ' - ELSE log_action1.name - END AS name', - 'CASE - ' /* following site search */ . ' - WHEN log_link_visit_action.idaction_url IS NULL THEN log_action2.type - ' /* following page view: use page title */ . ' - WHEN log_action1.type = ' . Piwik_Tracker_Action::TYPE_ACTION_URL . ' THEN log_action2.type - ' /* following download or outlink: use url */ . ' - ELSE log_action1.type - END AS type', - 'NULL AS url_prefix' - ); - } - - // these types are available for both titles and urls - $types[Piwik_Tracker_Action::TYPE_SITE_SEARCH] = 'followingSiteSearches'; - $types[Piwik_Tracker_Action::TYPE_OUTLINK] = 'outlinks'; - $types[Piwik_Tracker_Action::TYPE_DOWNLOAD] = 'downloads'; - - $rankingQuery = new Piwik_RankingQuery($limitBeforeGrouping ? $limitBeforeGrouping : $this->limitBeforeGrouping); - $rankingQuery->addLabelColumn(array('name', 'url_prefix')); - $rankingQuery->partitionResultIntoMultipleGroups('type', array_keys($types)); - - $type = $this->getColumnTypeSuffix($actionType); - $where = 'log_link_visit_action.idaction_' . $type . '_ref = ' . intval($idaction); - if (!$includeLoops) { - $where .= ' AND (log_link_visit_action.idaction_' . $type . ' IS NULL OR ' - . 'log_link_visit_action.idaction_' . $type . ' != ' . intval($idaction) . ')'; - } - - $metrics = array(Piwik_Archive::INDEX_NB_ACTIONS); - $data = $archiveProcessing->queryActionsByDimension($dimension, $where, $selects, $metrics, $rankingQuery, $joinLogActionColumn); - - $this->totalTransitionsToFollowingActions = 0; - $dataTables = array(); - foreach ($types as $type => $recordName) { - $dataTable = new Piwik_DataTable; - if (isset($data[$type])) { - foreach ($data[$type] as &$record) { - $actions = intval($record[Piwik_Archive::INDEX_NB_ACTIONS]); - $dataTable->addRow(new Piwik_DataTable_Row(array( - Piwik_DataTable_Row::COLUMNS => array( - 'label' => $this->getPageLabel($record, $isTitle), - Piwik_Archive::INDEX_NB_ACTIONS => $actions - ) - ))); - $this->totalTransitionsToFollowingActions += $actions; - } - } - $dataTables[$recordName] = $dataTable; - } - - return $dataTables; - } - - /** - * Get the sum of all transitions to following actions (pages, outlinks, downloads). - * Only works if queryFollowingActions() has been used directly before. - */ - public function getTotalTransitionsToFollowingActions() - { - return $this->totalTransitionsToFollowingActions; - } - - private function getColumnTypeSuffix($actionType) - { - if ($actionType == 'title') { - return 'name'; - } - return 'url'; - } } \ No newline at end of file -- cgit v1.2.3 From e2b74053c61b0f3d6d44e11472f037a853f5e98a Mon Sep 17 00:00:00 2001 From: mattab Date: Thu, 13 Jun 2013 17:31:17 +1200 Subject: Renaming ArchiveProcessing in comments as well, adding missing header --- plugins/Transitions/API.php | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'plugins/Transitions') diff --git a/plugins/Transitions/API.php b/plugins/Transitions/API.php index 7294a78560..bdc79b6e4f 100644 --- a/plugins/Transitions/API.php +++ b/plugins/Transitions/API.php @@ -65,7 +65,7 @@ class Piwik_Transitions_API $segment = new Piwik_Segment($segment, $idSite); $site = new Piwik_Site($idSite); $period = Piwik_Period::advancedFactory($period, $date); - $archiveProcessing = new Piwik_ArchiveProcessor_Day($period, $site, $segment); + $archiveProcessor = new Piwik_ArchiveProcessor_Day($period, $site, $segment); // prepare the report $report = array( @@ -81,16 +81,16 @@ class Piwik_Transitions_API $partsArray = explode(',', $parts); if ($parts == 'all' || in_array('internalReferrers', $partsArray)) { - $this->addInternalReferrers($transitionsArchiving, $archiveProcessing, $report, $idaction, + $this->addInternalReferrers($transitionsArchiving, $archiveProcessor, $report, $idaction, $actionType, $limitBeforeGrouping); } if ($parts == 'all' || in_array('followingActions', $partsArray)) { $includeLoops = $parts != 'all' && !in_array('internalReferrers', $partsArray); - $this->addFollowingActions($transitionsArchiving, $archiveProcessing, $report, $idaction, + $this->addFollowingActions($transitionsArchiving, $archiveProcessor, $report, $idaction, $actionType, $limitBeforeGrouping, $includeLoops); } if ($parts == 'all' || in_array('externalReferrers', $partsArray)) { - $this->addExternalReferrers($transitionsArchiving, $archiveProcessing, $report, $idaction, + $this->addExternalReferrers($transitionsArchiving, $archiveProcessor, $report, $idaction, $actionType, $limitBeforeGrouping); } @@ -167,19 +167,19 @@ class Piwik_Transitions_API * previous pages and previous site searches * * @param Piwik_Transitions $transitionsArchiving - * @param $archiveProcessing + * @param $archiveProcessor * @param $report * @param $idaction * @param string $actionType * @param $limitBeforeGrouping * @throws Exception */ - private function addInternalReferrers($transitionsArchiving, $archiveProcessing, &$report, + private function addInternalReferrers($transitionsArchiving, $archiveProcessor, &$report, $idaction, $actionType, $limitBeforeGrouping) { $data = $this->queryInternalReferrers( - $idaction, $actionType, $archiveProcessing, $limitBeforeGrouping); + $idaction, $actionType, $archiveProcessor, $limitBeforeGrouping); if ($data['pageviews'] == 0) { throw new Exception('NoDataForAction'); @@ -196,19 +196,19 @@ class Piwik_Transitions_API * following pages, downloads, outlinks * * @param Piwik_Transitions $transitionsArchiving - * @param $archiveProcessing + * @param $archiveProcessor * @param $report * @param $idaction * @param string $actionType * @param $limitBeforeGrouping * @param boolean $includeLoops */ - private function addFollowingActions($transitionsArchiving, $archiveProcessing, &$report, + private function addFollowingActions($transitionsArchiving, $archiveProcessor, &$report, $idaction, $actionType, $limitBeforeGrouping, $includeLoops = false) { $data = $this->queryFollowingActions( - $idaction, $actionType, $archiveProcessing, $limitBeforeGrouping, $includeLoops); + $idaction, $actionType, $archiveProcessor, $limitBeforeGrouping, $includeLoops); foreach ($data as $tableName => $table) { $report[$tableName] = $table; @@ -222,12 +222,12 @@ class Piwik_Transitions_API * * @param $idaction * @param $actionType - * @param Piwik_ArchiveProcessor_Day $archiveProcessing + * @param Piwik_ArchiveProcessor_Day $archiveProcessor * @param $limitBeforeGrouping * @param $includeLoops * @return array(followingPages:Piwik_DataTable, outlinks:Piwik_DataTable, downloads:Piwik_DataTable) */ - public function queryFollowingActions($idaction, $actionType, Piwik_ArchiveProcessor_Day $archiveProcessing, + public function queryFollowingActions($idaction, $actionType, Piwik_ArchiveProcessor_Day $archiveProcessor, $limitBeforeGrouping = false, $includeLoops = false) { $types = array(); @@ -295,7 +295,7 @@ class Piwik_Transitions_API } $metrics = array(Piwik_Archive::INDEX_NB_ACTIONS); - $data = $archiveProcessing->queryActionsByDimension(array($dimension), $where, $selects, $metrics, $rankingQuery, $joinLogActionColumn); + $data = $archiveProcessor->queryActionsByDimension(array($dimension), $where, $selects, $metrics, $rankingQuery, $joinLogActionColumn); $this->totalTransitionsToFollowingActions = 0; $dataTables = array(); @@ -334,11 +334,11 @@ class Piwik_Transitions_API * * @param $idaction * @param $actionType - * @param Piwik_ArchiveProcessor_Day $archiveProcessing + * @param Piwik_ArchiveProcessor_Day $archiveProcessor * @param $limitBeforeGrouping * @return Piwik_DataTable */ - public function queryExternalReferrers($idaction, $actionType, $archiveProcessing, + public function queryExternalReferrers($idaction, $actionType, $archiveProcessor, $limitBeforeGrouping = false) { $rankingQuery = new Piwik_RankingQuery($limitBeforeGrouping ? $limitBeforeGrouping : $this->limitBeforeGrouping); @@ -371,7 +371,7 @@ class Piwik_Transitions_API $where = 'visit_entry_idaction_' . $type . ' = ' . intval($idaction); $metrics = array(Piwik_Archive::INDEX_NB_VISITS); - $data = $archiveProcessing->queryVisitsByDimension($dimensions, $where, $selects, $metrics, $rankingQuery); + $data = $archiveProcessor->queryVisitsByDimension($dimensions, $where, $selects, $metrics, $rankingQuery); $referrerData = array(); $referrerSubData = array(); @@ -408,11 +408,11 @@ class Piwik_Transitions_API * * @param $idaction * @param $actionType - * @param Piwik_ArchiveProcessor_Day $archiveProcessing + * @param Piwik_ArchiveProcessor_Day $archiveProcessor * @param $limitBeforeGrouping * @return array(previousPages:Piwik_DataTable, loops:integer) */ - protected function queryInternalReferrers($idaction, $actionType, $archiveProcessing, + protected function queryInternalReferrers($idaction, $actionType, $archiveProcessor, $limitBeforeGrouping = false) { $rankingQuery = new Piwik_RankingQuery($limitBeforeGrouping ? $limitBeforeGrouping : $this->limitBeforeGrouping); @@ -453,7 +453,7 @@ class Piwik_Transitions_API $joinLogActionOn = $dimension; } $metrics = array(Piwik_Archive::INDEX_NB_ACTIONS); - $data = $archiveProcessing->queryActionsByDimension(array($dimension), $where, $selects, $metrics, $rankingQuery, $joinLogActionOn); + $data = $archiveProcessor->queryActionsByDimension(array($dimension), $where, $selects, $metrics, $rankingQuery, $joinLogActionOn); $loops = 0; $nbPageviews = 0; @@ -549,18 +549,18 @@ class Piwik_Transitions_API * direct entries, websites, campaigns, search engines * * @param Piwik_Transitions $transitionsArchiving - * @param $archiveProcessing + * @param $archiveProcessor * @param $report * @param $idaction * @param string $actionType * @param $limitBeforeGrouping */ - private function addExternalReferrers($transitionsArchiving, $archiveProcessing, &$report, + private function addExternalReferrers($transitionsArchiving, $archiveProcessor, &$report, $idaction, $actionType, $limitBeforeGrouping) { $data = $transitionsArchiving->queryExternalReferrers( - $idaction, $actionType, $archiveProcessing, $limitBeforeGrouping); + $idaction, $actionType, $archiveProcessor, $limitBeforeGrouping); $report['pageMetrics']['entries'] = 0; $report['referrers'] = array(); -- cgit v1.2.3 From e1e29012f17c02ee130083105c4fafada2fc36ac Mon Sep 17 00:00:00 2001 From: mattab Date: Sat, 15 Jun 2013 15:42:48 +1200 Subject: Fixing transitions and few other things. Still one failing test. --- plugins/Transitions/API.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'plugins/Transitions') diff --git a/plugins/Transitions/API.php b/plugins/Transitions/API.php index bdc79b6e4f..a18b1d6324 100644 --- a/plugins/Transitions/API.php +++ b/plugins/Transitions/API.php @@ -97,7 +97,7 @@ class Piwik_Transitions_API // derive the number of exits from the other metrics if ($parts == 'all') { $report['pageMetrics']['exits'] = $report['pageMetrics']['pageviews'] - - $transitionsArchiving->getTotalTransitionsToFollowingActions() + - $this->getTotalTransitionsToFollowingActions() - $report['pageMetrics']['loops']; } @@ -178,8 +178,7 @@ class Piwik_Transitions_API $idaction, $actionType, $limitBeforeGrouping) { - $data = $this->queryInternalReferrers( - $idaction, $actionType, $archiveProcessor, $limitBeforeGrouping); + $data = $this->queryInternalReferrers($idaction, $actionType, $archiveProcessor, $limitBeforeGrouping); if ($data['pageviews'] == 0) { throw new Exception('NoDataForAction'); @@ -265,7 +264,7 @@ class Piwik_Transitions_API WHEN log_action1.type = ' . Piwik_Tracker_Action::TYPE_ACTION_URL . ' THEN log_action2.name ' /* following download or outlink: use url */ . ' ELSE log_action1.name - END AS name', + END AS `name`', 'CASE ' /* following site search */ . ' WHEN log_link_visit_action.idaction_url IS NULL THEN log_action2.type @@ -273,8 +272,8 @@ class Piwik_Transitions_API WHEN log_action1.type = ' . Piwik_Tracker_Action::TYPE_ACTION_URL . ' THEN log_action2.type ' /* following download or outlink: use url */ . ' ELSE log_action1.type - END AS type', - 'NULL AS url_prefix' + END AS `type`', + 'NULL AS `url_prefix`' ); } @@ -357,7 +356,7 @@ class Piwik_Transitions_API WHEN ' . Piwik_Common::REFERER_TYPE_SEARCH_ENGINE . ' THEN referer_keyword WHEN ' . Piwik_Common::REFERER_TYPE_WEBSITE . ' THEN referer_url WHEN ' . Piwik_Common::REFERER_TYPE_CAMPAIGN . ' THEN CONCAT(referer_name, \' \', referer_keyword) - END AS referrer_data'); + END AS `referrer_data`'); // get one limited group per referrer type $rankingQuery->partitionResultIntoMultipleGroups('referer_type', array( @@ -433,12 +432,12 @@ class Piwik_Transitions_API $selects = array( 'log_action.name', 'log_action.url_prefix', - 'CASE WHEN log_link_visit_action.idaction_' . $type . '_ref = ' . intval($idaction) . ' THEN 1 ELSE 0 END AS is_self', + 'CASE WHEN log_link_visit_action.idaction_' . $type . '_ref = ' . intval($idaction) . ' THEN 1 ELSE 0 END AS `is_self`', 'CASE WHEN log_action.type = ' . $mainActionType . ' THEN 1 WHEN log_action.type = ' . Piwik_Tracker_Action::TYPE_SITE_SEARCH . ' THEN 2 ELSE 0 - END AS action_partition' + END AS `action_partition`' ); $where = ' @@ -559,7 +558,7 @@ class Piwik_Transitions_API $idaction, $actionType, $limitBeforeGrouping) { - $data = $transitionsArchiving->queryExternalReferrers( + $data = $this->queryExternalReferrers( $idaction, $actionType, $archiveProcessor, $limitBeforeGrouping); $report['pageMetrics']['entries'] = 0; -- cgit v1.2.3 From c1576a5e6cf303f8136e690e063c5974a526b1e0 Mon Sep 17 00:00:00 2001 From: mattab Date: Sun, 16 Jun 2013 16:17:18 +1200 Subject: Moving Log Aggregation logic to new LogAggregator object --- plugins/Transitions/API.php | 52 +++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 30 deletions(-) (limited to 'plugins/Transitions') diff --git a/plugins/Transitions/API.php b/plugins/Transitions/API.php index a18b1d6324..6d8890039b 100644 --- a/plugins/Transitions/API.php +++ b/plugins/Transitions/API.php @@ -66,7 +66,7 @@ class Piwik_Transitions_API $site = new Piwik_Site($idSite); $period = Piwik_Period::advancedFactory($period, $date); $archiveProcessor = new Piwik_ArchiveProcessor_Day($period, $site, $segment); - + $logAggregator = $archiveProcessor->getLogAggregator(); // prepare the report $report = array( 'date' => Piwik_Period_Day::advancedFactory($period->getLabel(), $date)->getLocalizedShortString() @@ -81,17 +81,14 @@ class Piwik_Transitions_API $partsArray = explode(',', $parts); if ($parts == 'all' || in_array('internalReferrers', $partsArray)) { - $this->addInternalReferrers($transitionsArchiving, $archiveProcessor, $report, $idaction, - $actionType, $limitBeforeGrouping); + $this->addInternalReferrers($logAggregator, $report, $idaction, $actionType, $limitBeforeGrouping); } if ($parts == 'all' || in_array('followingActions', $partsArray)) { $includeLoops = $parts != 'all' && !in_array('internalReferrers', $partsArray); - $this->addFollowingActions($transitionsArchiving, $archiveProcessor, $report, $idaction, - $actionType, $limitBeforeGrouping, $includeLoops); + $this->addFollowingActions($logAggregator, $report, $idaction, $actionType, $limitBeforeGrouping, $includeLoops); } if ($parts == 'all' || in_array('externalReferrers', $partsArray)) { - $this->addExternalReferrers($transitionsArchiving, $archiveProcessor, $report, $idaction, - $actionType, $limitBeforeGrouping); + $this->addExternalReferrers($logAggregator, $report, $idaction, $actionType, $limitBeforeGrouping); } // derive the number of exits from the other metrics @@ -166,19 +163,17 @@ class Piwik_Transitions_API * Add the internal referrers to the report: * previous pages and previous site searches * - * @param Piwik_Transitions $transitionsArchiving - * @param $archiveProcessor + * @param Piwik_DataAccess_LogAggregator $logAggregator * @param $report * @param $idaction * @param string $actionType * @param $limitBeforeGrouping * @throws Exception */ - private function addInternalReferrers($transitionsArchiving, $archiveProcessor, &$report, - $idaction, $actionType, $limitBeforeGrouping) + private function addInternalReferrers($logAggregator, &$report, $idaction, $actionType, $limitBeforeGrouping) { - $data = $this->queryInternalReferrers($idaction, $actionType, $archiveProcessor, $limitBeforeGrouping); + $data = $this->queryInternalReferrers($idaction, $actionType, $logAggregator, $limitBeforeGrouping); if ($data['pageviews'] == 0) { throw new Exception('NoDataForAction'); @@ -194,20 +189,18 @@ class Piwik_Transitions_API * Add the following actions to the report: * following pages, downloads, outlinks * - * @param Piwik_Transitions $transitionsArchiving - * @param $archiveProcessor + * @param Piwik_DataAccess_LogAggregator $logAggregator * @param $report * @param $idaction * @param string $actionType * @param $limitBeforeGrouping * @param boolean $includeLoops */ - private function addFollowingActions($transitionsArchiving, $archiveProcessor, &$report, - $idaction, $actionType, $limitBeforeGrouping, $includeLoops = false) + private function addFollowingActions($logAggregator, &$report, $idaction, $actionType, $limitBeforeGrouping, $includeLoops = false) { $data = $this->queryFollowingActions( - $idaction, $actionType, $archiveProcessor, $limitBeforeGrouping, $includeLoops); + $idaction, $actionType, $logAggregator, $limitBeforeGrouping, $includeLoops); foreach ($data as $tableName => $table) { $report[$tableName] = $table; @@ -221,12 +214,12 @@ class Piwik_Transitions_API * * @param $idaction * @param $actionType - * @param Piwik_ArchiveProcessor_Day $archiveProcessor + * @param Piwik_DataAccess_LogAggregator $logAggregator * @param $limitBeforeGrouping * @param $includeLoops * @return array(followingPages:Piwik_DataTable, outlinks:Piwik_DataTable, downloads:Piwik_DataTable) */ - public function queryFollowingActions($idaction, $actionType, Piwik_ArchiveProcessor_Day $archiveProcessor, + public function queryFollowingActions($idaction, $actionType, Piwik_DataAccess_LogAggregator $logAggregator, $limitBeforeGrouping = false, $includeLoops = false) { $types = array(); @@ -294,7 +287,7 @@ class Piwik_Transitions_API } $metrics = array(Piwik_Archive::INDEX_NB_ACTIONS); - $data = $archiveProcessor->queryActionsByDimension(array($dimension), $where, $selects, $metrics, $rankingQuery, $joinLogActionColumn); + $data = $logAggregator->queryActionsByDimension(array($dimension), $where, $selects, $metrics, $rankingQuery, $joinLogActionColumn); $this->totalTransitionsToFollowingActions = 0; $dataTables = array(); @@ -333,11 +326,11 @@ class Piwik_Transitions_API * * @param $idaction * @param $actionType - * @param Piwik_ArchiveProcessor_Day $archiveProcessor + * @param Piwik_ArchiveProcessor_Day $logAggregator * @param $limitBeforeGrouping * @return Piwik_DataTable */ - public function queryExternalReferrers($idaction, $actionType, $archiveProcessor, + public function queryExternalReferrers($idaction, $actionType, $logAggregator, $limitBeforeGrouping = false) { $rankingQuery = new Piwik_RankingQuery($limitBeforeGrouping ? $limitBeforeGrouping : $this->limitBeforeGrouping); @@ -370,7 +363,7 @@ class Piwik_Transitions_API $where = 'visit_entry_idaction_' . $type . ' = ' . intval($idaction); $metrics = array(Piwik_Archive::INDEX_NB_VISITS); - $data = $archiveProcessor->queryVisitsByDimension($dimensions, $where, $selects, $metrics, $rankingQuery); + $data = $logAggregator->queryVisitsByDimension($dimensions, $where, $selects, $metrics, $rankingQuery); $referrerData = array(); $referrerSubData = array(); @@ -407,11 +400,11 @@ class Piwik_Transitions_API * * @param $idaction * @param $actionType - * @param Piwik_ArchiveProcessor_Day $archiveProcessor + * @param Piwik_ArchiveProcessor_Day $logAggregator * @param $limitBeforeGrouping * @return array(previousPages:Piwik_DataTable, loops:integer) */ - protected function queryInternalReferrers($idaction, $actionType, $archiveProcessor, + protected function queryInternalReferrers($idaction, $actionType, $logAggregator, $limitBeforeGrouping = false) { $rankingQuery = new Piwik_RankingQuery($limitBeforeGrouping ? $limitBeforeGrouping : $this->limitBeforeGrouping); @@ -452,7 +445,7 @@ class Piwik_Transitions_API $joinLogActionOn = $dimension; } $metrics = array(Piwik_Archive::INDEX_NB_ACTIONS); - $data = $archiveProcessor->queryActionsByDimension(array($dimension), $where, $selects, $metrics, $rankingQuery, $joinLogActionOn); + $data = $logAggregator->queryActionsByDimension(array($dimension), $where, $selects, $metrics, $rankingQuery, $joinLogActionOn); $loops = 0; $nbPageviews = 0; @@ -547,19 +540,18 @@ class Piwik_Transitions_API * Add the external referrers to the report: * direct entries, websites, campaigns, search engines * - * @param Piwik_Transitions $transitionsArchiving - * @param $archiveProcessor + * @param Piwik_DataAccess_LogAggregator $logAggregator * @param $report * @param $idaction * @param string $actionType * @param $limitBeforeGrouping */ - private function addExternalReferrers($transitionsArchiving, $archiveProcessor, &$report, + private function addExternalReferrers($logAggregator, &$report, $idaction, $actionType, $limitBeforeGrouping) { $data = $this->queryExternalReferrers( - $idaction, $actionType, $archiveProcessor, $limitBeforeGrouping); + $idaction, $actionType, $logAggregator, $limitBeforeGrouping); $report['pageMetrics']['entries'] = 0; $report['referrers'] = array(); -- cgit v1.2.3 From 621db6a16a37374aed623f75ea8cdabdf2b8e8d0 Mon Sep 17 00:00:00 2001 From: mattab Date: Tue, 18 Jun 2013 16:14:49 +1200 Subject: Adding new Metrics class that knows about all metrics. Moving from Piwik_Archive class. Also moved some other const to Piwik class. --- plugins/Transitions/API.php | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'plugins/Transitions') diff --git a/plugins/Transitions/API.php b/plugins/Transitions/API.php index 6d8890039b..1c2934ca74 100644 --- a/plugins/Transitions/API.php +++ b/plugins/Transitions/API.php @@ -109,9 +109,9 @@ class Piwik_Transitions_API ); foreach ($reportNames as $reportName => $replaceLabel) { if (isset($report[$reportName])) { - $columnNames = array(Piwik_Archive::INDEX_NB_ACTIONS => 'referrals'); + $columnNames = array(Piwik_Metrics::INDEX_NB_ACTIONS => 'referrals'); if ($replaceLabel) { - $columnNames[Piwik_Archive::INDEX_NB_ACTIONS] = 'referrals'; + $columnNames[Piwik_Metrics::INDEX_NB_ACTIONS] = 'referrals'; } $report[$reportName]->filter('ReplaceColumnNames', array($columnNames)); } @@ -286,7 +286,7 @@ class Piwik_Transitions_API . 'log_link_visit_action.idaction_' . $type . ' != ' . intval($idaction) . ')'; } - $metrics = array(Piwik_Archive::INDEX_NB_ACTIONS); + $metrics = array(Piwik_Metrics::INDEX_NB_ACTIONS); $data = $logAggregator->queryActionsByDimension(array($dimension), $where, $selects, $metrics, $rankingQuery, $joinLogActionColumn); $this->totalTransitionsToFollowingActions = 0; @@ -295,11 +295,11 @@ class Piwik_Transitions_API $dataTable = new Piwik_DataTable; if (isset($data[$type])) { foreach ($data[$type] as &$record) { - $actions = intval($record[Piwik_Archive::INDEX_NB_ACTIONS]); + $actions = intval($record[Piwik_Metrics::INDEX_NB_ACTIONS]); $dataTable->addRow(new Piwik_DataTable_Row(array( Piwik_DataTable_Row::COLUMNS => array( 'label' => $this->getPageLabel($record, $isTitle), - Piwik_Archive::INDEX_NB_ACTIONS => $actions + Piwik_Metrics::INDEX_NB_ACTIONS => $actions ) ))); $this->totalTransitionsToFollowingActions += $actions; @@ -362,14 +362,14 @@ class Piwik_Transitions_API $type = $this->getColumnTypeSuffix($actionType); $where = 'visit_entry_idaction_' . $type . ' = ' . intval($idaction); - $metrics = array(Piwik_Archive::INDEX_NB_VISITS); + $metrics = array(Piwik_Metrics::INDEX_NB_VISITS); $data = $logAggregator->queryVisitsByDimension($dimensions, $where, $selects, $metrics, $rankingQuery); $referrerData = array(); $referrerSubData = array(); foreach ($data as $referrerType => &$subData) { - $referrerData[$referrerType] = array(Piwik_Archive::INDEX_NB_VISITS => 0); + $referrerData[$referrerType] = array(Piwik_Metrics::INDEX_NB_VISITS => 0); if ($referrerType != Piwik_Common::REFERER_TYPE_DIRECT_ENTRY) { $referrerSubData[$referrerType] = array(); } @@ -379,12 +379,12 @@ class Piwik_Transitions_API $row['referrer_data'] = Piwik_Referers_API::LABEL_KEYWORD_NOT_DEFINED; } - $referrerData[$referrerType][Piwik_Archive::INDEX_NB_VISITS] += $row[Piwik_Archive::INDEX_NB_VISITS]; + $referrerData[$referrerType][Piwik_Metrics::INDEX_NB_VISITS] += $row[Piwik_Metrics::INDEX_NB_VISITS]; $label = $row['referrer_data']; if ($label) { $referrerSubData[$referrerType][$label] = array( - Piwik_Archive::INDEX_NB_VISITS => $row[Piwik_Archive::INDEX_NB_VISITS] + Piwik_Metrics::INDEX_NB_VISITS => $row[Piwik_Metrics::INDEX_NB_VISITS] ); } } @@ -444,7 +444,7 @@ class Piwik_Transitions_API } else { $joinLogActionOn = $dimension; } - $metrics = array(Piwik_Archive::INDEX_NB_ACTIONS); + $metrics = array(Piwik_Metrics::INDEX_NB_ACTIONS); $data = $logAggregator->queryActionsByDimension(array($dimension), $where, $selects, $metrics, $rankingQuery, $joinLogActionOn); $loops = 0; @@ -452,11 +452,11 @@ class Piwik_Transitions_API $previousPagesDataTable = new Piwik_DataTable; if (isset($data['result'][1])) { foreach ($data['result'][1] as &$page) { - $nbActions = intval($page[Piwik_Archive::INDEX_NB_ACTIONS]); + $nbActions = intval($page[Piwik_Metrics::INDEX_NB_ACTIONS]); $previousPagesDataTable->addRow(new Piwik_DataTable_Row(array( Piwik_DataTable_Row::COLUMNS => array( 'label' => $this->getPageLabel($page, $isTitle), - Piwik_Archive::INDEX_NB_ACTIONS => $nbActions + Piwik_Metrics::INDEX_NB_ACTIONS => $nbActions ) ))); $nbPageviews += $nbActions; @@ -466,11 +466,11 @@ class Piwik_Transitions_API $previousSearchesDataTable = new Piwik_DataTable; if (isset($data['result'][2])) { foreach ($data['result'][2] as &$search) { - $nbActions = intval($search[Piwik_Archive::INDEX_NB_ACTIONS]); + $nbActions = intval($search[Piwik_Metrics::INDEX_NB_ACTIONS]); $previousSearchesDataTable->addRow(new Piwik_DataTable_Row(array( Piwik_DataTable_Row::COLUMNS => array( 'label' => $search['name'], - Piwik_Archive::INDEX_NB_ACTIONS => $nbActions + Piwik_Metrics::INDEX_NB_ACTIONS => $nbActions ) ))); $nbPageviews += $nbActions; @@ -479,12 +479,12 @@ class Piwik_Transitions_API if (isset($data['result'][0])) { foreach ($data['result'][0] as &$referrer) { - $nbPageviews += intval($referrer[Piwik_Archive::INDEX_NB_ACTIONS]); + $nbPageviews += intval($referrer[Piwik_Metrics::INDEX_NB_ACTIONS]); } } if (count($data['excludedFromLimit'])) { - $loops += intval($data['excludedFromLimit'][0][Piwik_Archive::INDEX_NB_ACTIONS]); + $loops += intval($data['excludedFromLimit'][0][Piwik_Metrics::INDEX_NB_ACTIONS]); $nbPageviews += $loops; } @@ -557,7 +557,7 @@ class Piwik_Transitions_API $report['referrers'] = array(); foreach ($data->getRows() as $row) { $referrerId = $row->getColumn('label'); - $visits = $row->getColumn(Piwik_Archive::INDEX_NB_VISITS); + $visits = $row->getColumn(Piwik_Metrics::INDEX_NB_VISITS); if ($visits) { // load details (i.e. subtables) $details = array(); @@ -566,7 +566,7 @@ class Piwik_Transitions_API foreach ($subTable->getRows() as $subRow) { $details[] = array( 'label' => $subRow->getColumn('label'), - 'referrals' => $subRow->getColumn(Piwik_Archive::INDEX_NB_VISITS) + 'referrals' => $subRow->getColumn(Piwik_Metrics::INDEX_NB_VISITS) ); } } -- cgit v1.2.3