File size: 1,789 Bytes
78185c4 | 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 | <?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
declare(strict_types=1);
namespace Piwik\Plugins\BotTracking\Columns\Metrics;
use Piwik\Columns\Dimension;
use Piwik\DataTable\Row;
use Piwik\Metrics\Formatter;
use Piwik\Piwik;
use Piwik\Plugin\ProcessedMetric;
use Piwik\Plugins\BotTracking\Metrics;
class AvgServerTime extends ProcessedMetric
{
public function getName()
{
return Metrics::COLUMN_AVG_SERVER_TIME;
}
public function getTranslatedName()
{
return Piwik::translate('BotTracking_ColumnAvgServerTime');
}
public function getDocumentation()
{
return Piwik::translate('BotTracking_ColumnAvgServerTimeDocumentation');
}
public function compute(Row $row)
{
$rawSum = $this->getMetric($row, Metrics::COLUMN_SUM_SERVER_TIME);
$rawNb = $this->getMetric($row, Metrics::COLUMN_NB_SERVER_TIME);
$sum = is_numeric($rawSum) ? (int) $rawSum : 0;
$nb = is_numeric($rawNb) ? (int) $rawNb : 0;
if (empty($nb)) {
return false;
}
// Stored values are in milliseconds; divide by 1000 to return seconds.
return (float)($sum / $nb / 1000);
}
public function getDependentMetrics()
{
return [
Metrics::COLUMN_SUM_SERVER_TIME,
Metrics::COLUMN_NB_SERVER_TIME,
];
}
/**
* @param float|int $value
* @return string
*/
public function format($value, Formatter $formatter)
{
return $formatter->getPrettyTimeFromSeconds($value, true);
}
public function getSemanticType(): ?string
{
return Dimension::TYPE_DURATION_S;
}
}
|