-
Notifications
You must be signed in to change notification settings - Fork 11
/
Metrics.php
134 lines (117 loc) · 4.47 KB
/
Metrics.php
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
125
126
127
128
129
130
131
132
133
134
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*
*/
namespace Piwik\Plugins\Bandwidth;
use Piwik\Piwik;
use Piwik\Columns\Dimension;
use Piwik\Plugins\Bandwidth\Columns\Bandwidth as BandwidthColumn;
use Piwik\Plugins\Bandwidth\Columns\Metrics\AvgBandwidth;
use Piwik\Plugins\Bandwidth\Columns\Metrics\DownloadBandwidth;
use Piwik\Plugins\Bandwidth\Columns\Metrics\HitsWithBandwidth;
use Piwik\Plugins\Bandwidth\Columns\Metrics\MaxBandwidth;
use Piwik\Plugins\Bandwidth\Columns\Metrics\MinBandwidth;
use Piwik\Plugins\Bandwidth\Columns\Metrics\OverallBandwidth;
use Piwik\Plugins\Bandwidth\Columns\Metrics\PageviewBandwidth;
use Piwik\Plugins\Bandwidth\Columns\Metrics\SumBandwidth;
class Metrics
{
public const METRICS_PAGE_SUM_BANDWIDTH = 1090;
public const METRICS_PAGE_MIN_BANDWIDTH = 1091;
public const METRICS_PAGE_MAX_BANDWIDTH = 1092;
public const METRICS_NB_HITS_WITH_BANDWIDTH = 1093;
public const COLUMN_TOTAL_OVERALL_BANDWIDTH = 'nb_total_overall_bandwidth';
public const COLUMN_TOTAL_PAGEVIEW_BANDWIDTH = 'nb_total_pageview_bandwidth';
public const COLUMN_TOTAL_DOWNLOAD_BANDWIDTH = 'nb_total_download_bandwidth';
public static function getNumericRecordNameToColumnsMapping()
{
return [
Archiver::BANDWIDTH_TOTAL_RECORD => Metrics::COLUMN_TOTAL_OVERALL_BANDWIDTH,
Archiver::BANDWIDTH_PAGEVIEW_RECORD => Metrics::COLUMN_TOTAL_PAGEVIEW_BANDWIDTH,
Archiver::BANDWIDTH_DOWNLOAD_RECORD => Metrics::COLUMN_TOTAL_DOWNLOAD_BANDWIDTH,
];
}
/**
* @return \Piwik\Plugins\Bandwidth\Columns\Metrics\Base[]
*/
public static function getBandwidthMetrics()
{
return [
new HitsWithBandwidth(),
new MaxBandwidth(),
new MinBandwidth(),
new SumBandwidth(),
new AvgBandwidth(),
];
}
/**
* @return \Piwik\Plugin\Metric[]
*/
public static function getOverallMetrics()
{
return [
new DownloadBandwidth(),
new PageviewBandwidth(),
new OverallBandwidth(),
];
}
public static function getMetricTranslations()
{
$translations = [];
foreach (self::getBandwidthMetrics() as $metric) {
$translations[$metric->getName()] = $metric->getTranslatedName();
}
$translations[Metrics::COLUMN_TOTAL_OVERALL_BANDWIDTH] = Piwik::translate('Bandwidth_ColumnTotalOverallBandwidth');
$translations[Metrics::COLUMN_TOTAL_PAGEVIEW_BANDWIDTH] = Piwik::translate('Bandwidth_ColumnTotalPageviewBandwidth');
$translations[Metrics::COLUMN_TOTAL_DOWNLOAD_BANDWIDTH] = Piwik::translate('Bandwidth_ColumnTotalDownloadBandwidth');
return $translations;
}
public static function getMetricSemanticTypes(): array
{
$semanticTypes = [];
foreach (self::getBandwidthMetrics() as $metric) {
$semanticTypes[$metric->getName()] = $metric->getSemanticType();
}
$semanticTypes[Metrics::COLUMN_TOTAL_OVERALL_BANDWIDTH] = Dimension::TYPE_NUMBER;
$semanticTypes[Metrics::COLUMN_TOTAL_PAGEVIEW_BANDWIDTH] = Dimension::TYPE_NUMBER;
$semanticTypes[Metrics::COLUMN_TOTAL_DOWNLOAD_BANDWIDTH] = Dimension::TYPE_NUMBER;
return $semanticTypes;
}
public static function getActionMetrics()
{
$column = new BandwidthColumn();
$column = $column->getColumnName();
$metricsConfig = [];
$metricsConfig[self::METRICS_PAGE_SUM_BANDWIDTH] = [
'aggregation' => 'sum',
'query' => "sum(
case when $column is null
then 0
else $column
end
)",
];
$metricsConfig[self::METRICS_NB_HITS_WITH_BANDWIDTH] = [
'aggregation' => 'sum',
'query' => "sum(
case when $column is null
then 0
else 1
end
)",
];
$metricsConfig[self::METRICS_PAGE_MIN_BANDWIDTH] = [
'aggregation' => 'min',
'query' => "min($column)",
];
$metricsConfig[self::METRICS_PAGE_MAX_BANDWIDTH] = [
'aggregation' => 'max',
'query' => "max($column)",
];
return $metricsConfig;
}
}