PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.3.0
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.3.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 5 years ago API.php 5 years ago AggregatedMetric.php 5 years ago ArchivedMetric.php 5 years ago Archiver.php 5 years ago Categories.php 5 years ago ComponentFactory.php 5 years ago ComputedMetric.php 5 years ago ConsoleCommand.php 5 years ago Controller.php 5 years ago ControllerAdmin.php 5 years ago Dependency.php 5 years ago LogTablesProvider.php 5 years ago Manager.php 5 years ago Menu.php 5 years ago MetadataLoader.php 5 years ago Metric.php 5 years ago PluginException.php 5 years ago ProcessedMetric.php 5 years ago ReleaseChannels.php 5 years ago Report.php 5 years ago ReportsProvider.php 5 years ago RequestProcessors.php 5 years ago Segment.php 5 years ago SettingsProvider.php 5 years ago Tasks.php 5 years ago ThemeStyles.php 5 years ago ViewDataTable.php 5 years ago Visualization.php 5 years ago WidgetsProvider.php 5 years ago
ArchivedMetric.php
221 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 = number_format($value / 1000, 2);
151 if ($val > 60) {
152 $val = round($val);
153 }
154 return $formatter->getPrettyTimeFromSeconds($val, $displayAsSentence = true);
155 case Dimension::TYPE_PERCENT:
156 return $formatter->getPrettyPercentFromQuotient($value);
157 case Dimension::TYPE_BYTE:
158 return $formatter->getPrettySizeFromBytes($value);
159 }
160
161 return $value;
162 }
163
164 public function getType()
165 {
166 return $this->type;
167 }
168
169 public function getTranslatedName()
170 {
171 if (!empty($this->translatedName)) {
172 return Piwik::translate($this->translatedName);
173 }
174
175 return $this->translatedName;
176 }
177
178 public function getDependentMetrics()
179 {
180 return array($this->getName());
181 }
182
183 public function getDocumentation()
184 {
185 return $this->documentation;
186 }
187
188 public function getDbTableName()
189 {
190 return $this->dbTable;
191 }
192
193 public function getQuery()
194 {
195 if ($this->query) {
196 return $this->query;
197 }
198
199 $column = $this->dbTable . '.' . $this->dimension->getColumnName();
200
201 if ($this->dimension->getSqlSegment()) {
202 $column = str_replace($this->dimension->getDbTableName(), $this->dbTable, $this->dimension->getSqlSegment());
203 }
204
205 if (!empty($this->aggregation)) {
206 return sprintf($this->aggregation, $column);
207 }
208
209 return $column;
210 }
211
212 public function beforeFormat($report, DataTable $table)
213 {
214 $this->idSite = DataTableFactory::getSiteIdFromMetadata($table);
215 if (empty($this->idSite)) {
216 $this->idSite = Common::getRequestVar('idSite', 0, 'int');
217 }
218 return !empty($this->idSite); // skip formatting if there is no site to get currency info from
219 }
220 }
221