PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.13.3
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.13.3
5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / Plugin / ArchivedMetric.php
matomo / app / core / Plugin Last commit date
Dimension 3 years ago API.php 3 years ago AggregatedMetric.php 5 years ago ArchivedMetric.php 4 years ago Archiver.php 3 years ago Categories.php 5 years ago ComponentFactory.php 5 years ago ComputedMetric.php 4 years ago ConsoleCommand.php 5 years ago Controller.php 3 years ago ControllerAdmin.php 3 years ago Dependency.php 4 years ago LogTablesProvider.php 5 years ago Manager.php 4 years ago Menu.php 5 years ago MetadataLoader.php 4 years ago Metric.php 5 years ago PluginException.php 5 years ago ProcessedMetric.php 5 years ago ReleaseChannels.php 5 years ago Report.php 3 years ago ReportsProvider.php 3 years ago RequestProcessors.php 5 years ago Segment.php 3 years ago SettingsProvider.php 5 years ago Tasks.php 3 years ago ThemeStyles.php 5 years ago ViewDataTable.php 5 years ago Visualization.php 3 years ago WidgetsProvider.php 5 years ago
ArchivedMetric.php
218 lines
1 <?php
2 /**
3 * Matomo - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 */
8 namespace Piwik\Plugin;
9
10 use Piwik\Archive\DataTableFactory;
11 use Piwik\Columns\Dimension;
12 use Piwik\Common;
13 use Piwik\DataTable;
14 use Piwik\Metrics\Formatter;
15 use Piwik\Piwik;
16
17 class ArchivedMetric extends Metric
18 {
19 const AGGREGATION_COUNT = 'count(%s)';
20 const AGGREGATION_COUNT_PREFIX = 'nb_';
21 const AGGREGATION_SUM = 'sum(%s)';
22 const AGGREGATION_SUM_PREFIX = 'sum_';
23 const AGGREGATION_MAX = 'max(%s)';
24 const AGGREGATION_MAX_PREFIX = 'max_';
25 const AGGREGATION_MIN = 'min(%s)';
26 const AGGREGATION_MIN_PREFIX = 'min_';
27 const AGGREGATION_UNIQUE = 'count(distinct %s)';
28 const AGGREGATION_UNIQUE_PREFIX = 'nb_uniq_';
29 const AGGREGATION_COUNT_WITH_NUMERIC_VALUE = 'sum(if(%s > 0, 1, 0))';
30 const AGGREGATION_COUNT_WITH_NUMERIC_VALUE_PREFIX = 'nb_with_';
31
32 /**
33 * @var string
34 */
35 private $aggregation;
36
37 /**
38 * @var int
39 */
40 protected $idSite;
41
42 private $name = '';
43 private $type = '';
44 private $translatedName = '';
45 private $documentation = '';
46 private $dbTable = '';
47 private $category = '';
48 private $query = '';
49
50 /**
51 * @var Dimension
52 */
53 private $dimension;
54
55 public function __construct(Dimension $dimension, $aggregation = false)
56 {
57 if (!empty($aggregation) && strpos($aggregation, '%s') === false) {
58 throw new \Exception(sprintf('The given aggregation for %s.%s needs to include a %%s for the column name', $dimension->getDbTableName(), $dimension->getColumnName()));
59 }
60
61 $this->setDimension($dimension);
62 $this->setDbTable($dimension->getDbTableName());
63 $this->aggregation = $aggregation;
64 }
65
66 public function getAggregation()
67 {
68 return $this->aggregation;
69 }
70
71 public function setDimension($dimension)
72 {
73 $this->dimension = $dimension;
74 return $this;
75 }
76
77 public function getDimension()
78 {
79 return $this->dimension;
80 }
81
82 public function setCategory($category)
83 {
84 $this->category = $category;
85 return $this;
86 }
87
88 public function getCategoryId()
89 {
90 return $this->category;
91 }
92
93 public function setDbTable($dbTable)
94 {
95 $this->dbTable = $dbTable;
96 return $this;
97 }
98
99 public function setDocumentation($documentation)
100 {
101 $this->documentation = $documentation;
102 return $this;
103 }
104
105 public function setTranslatedName($name)
106 {
107 $this->translatedName = $name;
108 return $this;
109 }
110
111 public function setType($type)
112 {
113 $this->type = $type;
114 return $this;
115 }
116
117 public function setName($name)
118 {
119 $this->name = $name;
120 return $this;
121 }
122
123 public function setQuery($query)
124 {
125 $this->query = $query;
126 return $this;
127 }
128
129 public function getName()
130 {
131 return $this->name;
132 }
133
134 public function format($value, Formatter $formatter)
135 {
136 switch ($this->type) {
137 case Dimension::TYPE_BOOL:
138 return $formatter->getPrettyNumber($value);
139 case Dimension::TYPE_ENUM:
140 return $formatter->getPrettyNumber($value);
141 case Dimension::TYPE_MONEY:
142 return $formatter->getPrettyMoney($value, $this->idSite);
143 case Dimension::TYPE_FLOAT:
144 return $formatter->getPrettyNumber((float) $value, $precision = 2);
145 case Dimension::TYPE_NUMBER:
146 return $formatter->getPrettyNumber($value);
147 case Dimension::TYPE_DURATION_S:
148 return $formatter->getPrettyTimeFromSeconds($value, $displayAsSentence = true);
149 case Dimension::TYPE_DURATION_MS:
150 $val = round(($value / 1000), ($value / 1000) > 60 ? 0 : 2);
151 return $formatter->getPrettyTimeFromSeconds($val, $displayAsSentence = true);
152 case Dimension::TYPE_PERCENT:
153 return $formatter->getPrettyPercentFromQuotient($value);
154 case Dimension::TYPE_BYTE:
155 return $formatter->getPrettySizeFromBytes($value);
156 }
157
158 return $value;
159 }
160
161 public function getType()
162 {
163 return $this->type;
164 }
165
166 public function getTranslatedName()
167 {
168 if (!empty($this->translatedName)) {
169 return Piwik::translate($this->translatedName);
170 }
171
172 return $this->translatedName;
173 }
174
175 public function getDependentMetrics()
176 {
177 return array($this->getName());
178 }
179
180 public function getDocumentation()
181 {
182 return $this->documentation;
183 }
184
185 public function getDbTableName()
186 {
187 return $this->dbTable;
188 }
189
190 public function getQuery()
191 {
192 if ($this->query) {
193 return $this->query;
194 }
195
196 $column = $this->dbTable . '.' . $this->dimension->getColumnName();
197
198 if ($this->dimension->getSqlSegment()) {
199 $column = str_replace($this->dimension->getDbTableName(), $this->dbTable, $this->dimension->getSqlSegment());
200 }
201
202 if (!empty($this->aggregation)) {
203 return sprintf($this->aggregation, $column);
204 }
205
206 return $column;
207 }
208
209 public function beforeFormat($report, DataTable $table)
210 {
211 $this->idSite = DataTableFactory::getSiteIdFromMetadata($table);
212 if (empty($this->idSite)) {
213 $this->idSite = Common::getRequestVar('idSite', 0, 'int');
214 }
215 return !empty($this->idSite); // skip formatting if there is no site to get currency info from
216 }
217 }
218