blob: c0732d9885af52edc442c859d8bf63102123a8b6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
<?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
* @package Piwik
*/
namespace Piwik\ArchiveProcessor;
use Piwik\Metrics;
use Piwik\ArchiveProcessor;
use Piwik\DataArray;
use Piwik\DataTable;
/**
* This class
* @package Piwik
* @subpackage ArchiveProcessor
*
* @api
*/
class Day extends ArchiveProcessor
{
/**
* Converts the given array to a datatable
* @param DataArray $array
* @return \Piwik\DataTable
*/
static public function getDataTableFromDataArray(DataArray $array)
{
$dataArray = $array->getDataArray();
$dataArrayTwoLevels = $array->getDataArrayWithTwoLevels();
$subtableByLabel = null;
if (!empty($dataArrayTwoLevels)) {
$subtableByLabel = array();
foreach ($dataArrayTwoLevels as $label => $subTable) {
$subtableByLabel[$label] = DataTable::makeFromIndexedArray($subTable);
}
}
return DataTable::makeFromIndexedArray($dataArray, $subtableByLabel);
}
/**
* Helper function that returns an array with common statistics for a given database field distinct values.
*
* The statistics returned are:
* - number of unique visitors
* - number of visits
* - number of actions
* - maximum number of action for a visit
* - sum of the visits' length in sec
* - count of bouncing visits (visits with one page view)
*
* For example if $dimension = 'config_os' it will return the statistics for every distinct Operating systems
* The returned array will have a row per distinct operating systems,
* and a column per stat (nb of visits, max actions, etc)
*
* 'label' Metrics::INDEX_NB_UNIQ_VISITORS Metrics::INDEX_NB_VISITS etc.
* Linux 27 66 ...
* Windows XP 12 ...
* Mac OS 15 36 ...
*
* @param string $dimension Table log_visit field name to be use to compute common stats
* @return DataArray
*/
public function getMetricsForDimension($dimension)
{
if (!is_array($dimension)) {
$dimension = array($dimension);
}
if (count($dimension) == 1) {
$dimension = array("label" => reset($dimension));
}
$query = $this->getLogAggregator()->queryVisitsByDimension($dimension);
$metrics = new DataArray();
while ($row = $query->fetch()) {
$metrics->sumMetricsVisits($row["label"], $row);
}
return $metrics;
}
protected function aggregateCoreVisitsMetrics()
{
$query = $this->getLogAggregator()->queryVisitsByDimension();
$data = $query->fetch();
$metrics = $this->convertMetricsIdToName($data);
$this->insertNumericRecords($metrics);
return $metrics;
}
protected function convertMetricsIdToName($data)
{
$metrics = array();
foreach ($data as $metricId => $value) {
$readableMetric = Metrics::$mappingFromIdToName[$metricId];
$metrics[$readableMetric] = $value;
}
return $metrics;
}
protected function compute()
{
/**
* This event is triggered when the archiver wants to compute a new archive. Use this event to archive your
* custom report data if needed.
*
* Example:
* ```
* public function archiveDay(ArchiveProcessor\Day $archiveProcessor)
* {
* $archiving = new Archiver($archiveProcessor);
* if ($archiving->shouldArchive()) {
* $archiving->archiveDay();
* }
* }
* ```
*/
Piwik_PostEvent('ArchiveProcessor.Day.compute', array(&$this));
}
}
|