Skip to content

Commit

Permalink
Refs matomo-org#4200, document last method in LogAggregator.
Browse files Browse the repository at this point in the history
  • Loading branch information
diosmosis committed Nov 11, 2013
1 parent e0e83ef commit b43402d
Showing 1 changed file with 95 additions and 11 deletions.
106 changes: 95 additions & 11 deletions core/DataAccess/LogAggregator.php
Expand Up @@ -29,9 +29,19 @@
*
* ** TODO (explain 'dimension') **
*
* ### Aggregation Functions
*
* ** TODO (describe how to use functions)
*
* ### Examples
*
* ** TODO **
* **Aggregating visit data**
*
* // TODO
*
* **Aggregating conversion data**
*
* // TODO
*/
class LogAggregator
{
Expand Down Expand Up @@ -575,12 +585,27 @@ protected function getActionsMetricFields()
* group.
* - **[Metrics::INDEX_GOAL_NB_VISITS_CONVERTED](#)**: The total number of visits during which these
* conversions were converted.
* - **[Metrics::INDEX_GOAL_REVENUE](#)**: The total revenue generated by these conversions.
* - **[Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_SUBTOTAL](#)**: **TODO (this & below)**
* - **[Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_TAX](#)**:
* - **[Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_SHIPPING](#)**:
* - **[Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_DISCOUNT](#)**:
* - **[Metrics::INDEX_GOAL_ECOMMERCE_ITEMS](#)**:
* - **[Metrics::INDEX_GOAL_REVENUE](#)**: The total revenue generated by these conversions. This value
* includes the revenue from individual ecommerce items.
* - **[Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_SUBTOTAL](#)**: The total cost of all ecommerce items sold
* within these conversions. This value does not
* include tax, shipping or any applied discount.
* _This metric will only be applicable to the special
* **ecommerce** goal (where `idGoal == 'ecommerceOrder'`)._
* - **[Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_TAX](#)**: The total tax applied to every transaction in these
* conversions. This metric is only applicable to the special
* **ecommerce** goal (where `idGoal == 'ecommerceOrder'`).
* - **[Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_SHIPPING](#)**: The total shipping cost for every transaction
* in these conversions. _This metric is only applicable
* to the special **ecommerce** goal (where
* `idGoal == 'ecommerceOrder'`)._
* - **[Metrics::INDEX_GOAL_ECOMMERCE_REVENUE_DISCOUNT](#)**: The total discount applied to every transaction
* in these conversions. _This metric is only applicable
* to the special **ecommerce** goal (where
* `idGoal == 'ecommerceOrder'`)._
* - **[Metrics::INDEX_GOAL_ECOMMERCE_ITEMS](#)**: The total number of ecommerce items sold in each transaction
* in these conversions. _This metric is only applicable to the
* special **ecommerce** goal (where `idGoal =='ecommerceOrder'`).
*
* Additional data can be selected through the `$additionalSelects` parameter.
*
Expand Down Expand Up @@ -612,14 +637,73 @@ public function queryConversionsByDimension($dimensions = array(), $where = fals
}

/**
* Creates and returns an array of SQL SELECT expressions that will summarize
* the data in a column of a specified table, over a set of ranges.
* Creates and returns an array of SQL SELECT expressions that will count the number
* of rows for which a specific column falls within specific ranges.
*
* The SELECT expressions will count the number of column values that are
* within each range.
*
* @param $metadata
* @return array An array of SQL SELECT expressions.
* **Note:** The result of this function is meant for use in the `$additionalSelects` parameter
* in one of the query... methods (for example [queryVisitsByDimension](#queryVisitsByDimension)).
*
* **Example**
*
* // summarize one column
* $visitTotalActionsRanges = array(
* array(1, 1),
* array(2, 10),
* array(10)
* );
* $selects = LogAggregator::getSelectsFromRangedColumn('visit_total_actions', $visitTotalActionsRanges, 'log_visit', 'vta');
*
* // summarize another column in the same request
* $visitCountVisitsRanges = array(
* array(1, 1),
* array(2, 20),
* array(20)
* );
* $selects = array_merge(
* $selects,
* LogAggregator::getSelectsFromRangedColumn('visitor_count_visits', $visitCountVisitsRanges, 'log_visit', 'vcv')
* );
*
* // perform query
* $logAggregator = // get the LogAggregator somehow
* $query = $logAggregator->queryVisitsByDimension($dimensions = array(), $where = false, $selects);
* $tableSummary = $query->fetch();
*
* $numberOfVisitsWithOneAction = $tableSummary['vta0'];
*
* @param string $column The name of a column in `$table` that will be summarized.
* @param array $ranges An array of arrays describing the ranges over which the data in the table
* will be summarized. For example,
* ```
* array(
* array(1, 1),
* array(2, 2),
* array(3, 5),
* array(6, 10),
* array(10) // everything over 10
* )
* ```
* @param string $table The unprefixed name of the table whose rows will be summarized.
* @param string $selectColumnPrefix The prefix to prepend to each SELECT expression. This
* prefix is used to differentiate different sets of
* range summarization SELECTs. You can supply different
* values to this argument to summarize several columns
* in one query (see above for an example).
* @param bool $restrictToReturningVisitors Whether to only summarize rows that belong to
* visits of returning visitors or not. If this
* argument is true, then the SELECT expressions
* returned can only be used with the
* [queryVisitsByDimension](#queryVisitsByDimension) method.
* @return array An array of SQL SELECT expressions, for example,
* ```
* array(
* 'sum(case when log_visit.visit_total_actions between 0 and 2 then 1 else 0 end) as vta0',
* 'sum(case when log_visit.visit_total_actions > 2 then 1 else 0 end) as vta1'
* )
* ```
* @api
*/
public static function getSelectsFromRangedColumn($column, $ranges, $table, $selectColumnPrefix, $restrictToReturningVisitors = false)
Expand Down

0 comments on commit b43402d

Please sign in to comment.