mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 09:43:13 +08:00
Added split info about bots, non-bots and total visits to the visits stats
This commit is contained in:
@@ -8,15 +8,34 @@ use JsonSerializable;
|
||||
|
||||
final class VisitsStats implements JsonSerializable
|
||||
{
|
||||
public function __construct(private int $visitsCount, private int $orphanVisitsCount)
|
||||
{
|
||||
private readonly VisitsSummary $nonOrphanVisitsSummary;
|
||||
private readonly VisitsSummary $orphanVisitsSummary;
|
||||
|
||||
public function __construct(
|
||||
int $nonOrphanVisitsTotal,
|
||||
int $orphanVisitsTotal,
|
||||
?int $nonOrphanVisitsNonBots = null,
|
||||
?int $orphanVisitsNonBots = null,
|
||||
) {
|
||||
$this->nonOrphanVisitsSummary = VisitsSummary::fromTotalAndNonBots(
|
||||
$nonOrphanVisitsTotal,
|
||||
$nonOrphanVisitsNonBots ?? $nonOrphanVisitsTotal,
|
||||
);
|
||||
$this->orphanVisitsSummary = VisitsSummary::fromTotalAndNonBots(
|
||||
$orphanVisitsTotal,
|
||||
$orphanVisitsNonBots ?? $orphanVisitsTotal,
|
||||
);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
'visitsCount' => $this->visitsCount,
|
||||
'orphanVisitsCount' => $this->orphanVisitsCount,
|
||||
'nonOrphanVisits' => $this->nonOrphanVisitsSummary,
|
||||
'orphanVisits' => $this->orphanVisitsSummary,
|
||||
|
||||
// Deprecated
|
||||
'visitsCount' => $this->nonOrphanVisitsSummary->total,
|
||||
'orphanVisitsCount' => $this->orphanVisitsSummary->total,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
28
module/Core/src/Visit/Model/VisitsSummary.php
Normal file
28
module/Core/src/Visit/Model/VisitsSummary.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Core\Visit\Model;
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
final class VisitsSummary implements JsonSerializable
|
||||
{
|
||||
private function __construct(public readonly int $total, public readonly int $nonBots)
|
||||
{
|
||||
}
|
||||
|
||||
public static function fromTotalAndNonBots(int $total, int $nonBots): self
|
||||
{
|
||||
return new self($total, $nonBots);
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
'total' => $this->total,
|
||||
'nonBots' => $this->nonBots,
|
||||
'bots' => $this->total - $this->nonBots,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user