-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: statistics typing DTO (#778)
- Loading branch information
1 parent
6114870
commit 75a60db
Showing
21 changed files
with
905 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\DTO\Statistics; | ||
|
||
use Illuminate\Support\Collection; | ||
|
||
final class AddressHoldingStatistics | ||
{ | ||
public int $greaterThanOne; | ||
|
||
public int $greaterThanOneThousand; | ||
|
||
public int $greaterThanTenThousand; | ||
|
||
public int $greaterThanOneHundredThousand; | ||
|
||
public int $greaterThanOneMillion; | ||
|
||
public function __construct(array $data) | ||
{ | ||
$grouped = (new Collection($data))->pluck('count', 'grouped'); | ||
|
||
$this->greaterThanOne = $grouped->get(1, 0); | ||
$this->greaterThanOneThousand = $grouped->get(1000, 0); | ||
$this->greaterThanTenThousand = $grouped->get(10000, 0); | ||
$this->greaterThanOneHundredThousand = $grouped->get(100000, 0); | ||
$this->greaterThanOneMillion = $grouped->get(1000000, 0); | ||
} | ||
|
||
public static function make(array $data): self | ||
{ | ||
return new self($data); | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return [ | ||
1 => $this->greaterThanOne, | ||
1000 => $this->greaterThanOneThousand, | ||
10000 => $this->greaterThanTenThousand, | ||
100000 => $this->greaterThanOneHundredThousand, | ||
1000000 => $this->greaterThanOneMillion, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\DTO\Statistics; | ||
|
||
use App\Models\Wallet; | ||
use App\ViewModels\WalletViewModel; | ||
|
||
final class DelegateStatistics | ||
{ | ||
public ?WalletViewModel $mostUniqueVoters = null; | ||
|
||
public ?WalletViewModel $leastUniqueVoters = null; | ||
|
||
public ?WalletViewModel $mostBlocksForged = null; | ||
|
||
public function __construct( | ||
?Wallet $mostUniqueVoters = null, | ||
?Wallet $leastUniqueVoters = null, | ||
?Wallet $mostBlocksForged = null, | ||
public ?WalletWithValue $oldestActiveDelegate = null, | ||
public ?WalletWithValue $newestActiveDelegate = null, | ||
) { | ||
if ($mostUniqueVoters !== null) { | ||
$this->mostUniqueVoters = new WalletViewModel($mostUniqueVoters); | ||
} | ||
|
||
if ($leastUniqueVoters !== null) { | ||
$this->leastUniqueVoters = new WalletViewModel($leastUniqueVoters); | ||
} | ||
|
||
if ($mostBlocksForged !== null) { | ||
$this->mostBlocksForged = new WalletViewModel($mostBlocksForged); | ||
} | ||
} | ||
|
||
public static function make( | ||
?Wallet $mostUniqueVoters = null, | ||
?Wallet $leastUniqueVoters = null, | ||
?Wallet $mostBlocksForged = null, | ||
?WalletWithValue $oldestActiveDelegate = null, | ||
?WalletWithValue $newestActiveDelegate = null, | ||
): self { | ||
return new self( | ||
$mostUniqueVoters, | ||
$leastUniqueVoters, | ||
$mostBlocksForged, | ||
$oldestActiveDelegate, | ||
$newestActiveDelegate, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\DTO\Statistics; | ||
|
||
final class LowHighValue | ||
{ | ||
public function __construct(public ?float $low = null, public ?float $high = null) | ||
{ | ||
// | ||
} | ||
|
||
public static function fromArray(?array $data): self | ||
{ | ||
if ($data === null) { | ||
return new self(); | ||
} | ||
|
||
return new self($data['low'], $data['high']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\DTO\Statistics; | ||
|
||
use App\Services\NumberFormatter; | ||
use ARKEcosystem\Foundation\UserInterface\Support\DateFormat; | ||
use Carbon\Carbon; | ||
|
||
final class MarketDataPriceStatistics | ||
{ | ||
public function __construct( | ||
public TimestampedValue $atl, | ||
public TimestampedValue $ath, | ||
public LowHighValue $daily, | ||
public LowHighValue $year, | ||
) { | ||
// | ||
} | ||
|
||
public static function make( | ||
TimestampedValue $atl, | ||
TimestampedValue $ath, | ||
LowHighValue $daily, | ||
LowHighValue $year, | ||
): self { | ||
return new self( | ||
$atl, | ||
$ath, | ||
$daily, | ||
$year, | ||
); | ||
} | ||
|
||
public function atlValue(): ?string | ||
{ | ||
if ($this->atl->value === null) { | ||
return null; | ||
} | ||
|
||
return $this->formatCurrency($this->atl->value); | ||
} | ||
|
||
public function atlDate(): ?string | ||
{ | ||
if ($this->atl->timestamp === null) { | ||
return null; | ||
} | ||
|
||
return Carbon::createFromTimestamp($this->atl->timestamp)->format(DateFormat::DATE); | ||
} | ||
|
||
public function athValue(): ?string | ||
{ | ||
if ($this->ath->value === null) { | ||
return null; | ||
} | ||
|
||
return $this->formatCurrency($this->ath->value); | ||
} | ||
|
||
public function athDate(): ?string | ||
{ | ||
if ($this->ath->timestamp === null) { | ||
return null; | ||
} | ||
|
||
return Carbon::createFromTimestamp($this->ath->timestamp)->format(DateFormat::DATE); | ||
} | ||
|
||
public function dailyLow(): ?string | ||
{ | ||
if ($this->daily->low === null) { | ||
return null; | ||
} | ||
|
||
return $this->formatCurrency($this->daily->low); | ||
} | ||
|
||
public function dailyHigh(): ?string | ||
{ | ||
if ($this->daily->high === null) { | ||
return null; | ||
} | ||
|
||
return $this->formatCurrency($this->daily->high); | ||
} | ||
|
||
public function yearLow(): ?string | ||
{ | ||
if ($this->year->low === null) { | ||
return null; | ||
} | ||
|
||
return $this->formatCurrency($this->year->low); | ||
} | ||
|
||
public function yearHigh(): ?string | ||
{ | ||
if ($this->year->high === null) { | ||
return null; | ||
} | ||
|
||
return $this->formatCurrency($this->year->high); | ||
} | ||
|
||
/** | ||
* @param string|int|float $value | ||
*/ | ||
private function formatCurrency($value): string | ||
{ | ||
return NumberFormatter::currencyWithDecimals($value, 'USD', 2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\DTO\Statistics; | ||
|
||
use App\Services\NumberFormatter; | ||
use ARKEcosystem\Foundation\UserInterface\Support\DateFormat; | ||
use Carbon\Carbon; | ||
|
||
final class MarketDataRecordStatistics | ||
{ | ||
public function __construct( | ||
public ?float $today, | ||
public TimestampedValue $atl, | ||
public TimestampedValue $ath, | ||
) { | ||
// | ||
} | ||
|
||
public static function make( | ||
?float $today, | ||
TimestampedValue $atl, | ||
TimestampedValue $ath, | ||
): self { | ||
return new self( | ||
$today, | ||
$atl, | ||
$ath, | ||
); | ||
} | ||
|
||
public function todayValueValue(): ?string | ||
{ | ||
if ($this->today === null) { | ||
return null; | ||
} | ||
|
||
return $this->formatCurrency($this->today); | ||
} | ||
|
||
public function atlValue(): ?string | ||
{ | ||
if ($this->atl->value === null) { | ||
return null; | ||
} | ||
|
||
return $this->formatCurrency($this->atl->value); | ||
} | ||
|
||
public function atlDate(): ?string | ||
{ | ||
if ($this->atl->timestamp === null) { | ||
return null; | ||
} | ||
|
||
return Carbon::createFromTimestamp($this->atl->timestamp)->format(DateFormat::DATE); | ||
} | ||
|
||
public function athValue(): ?string | ||
{ | ||
if ($this->ath->value === null) { | ||
return null; | ||
} | ||
|
||
return $this->formatCurrency($this->ath->value); | ||
} | ||
|
||
public function athDate(): ?string | ||
{ | ||
if ($this->ath->timestamp === null) { | ||
return null; | ||
} | ||
|
||
return Carbon::createFromTimestamp($this->ath->timestamp)->format(DateFormat::DATE); | ||
} | ||
|
||
/** | ||
* @param string|int|float $value | ||
*/ | ||
private function formatCurrency($value): string | ||
{ | ||
return NumberFormatter::currencyForViews($value, 'USD'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\DTO\Statistics; | ||
|
||
final class MarketDataStatistics | ||
{ | ||
public function __construct( | ||
public MarketDataPriceStatistics $prices, | ||
public MarketDataVolumeStatistics $volume, | ||
public MarketDataRecordStatistics $caps, | ||
) { | ||
// | ||
} | ||
|
||
public static function make( | ||
MarketDataPriceStatistics $prices, | ||
MarketDataVolumeStatistics $volume, | ||
MarketDataRecordStatistics $caps, | ||
): self { | ||
return new self( | ||
$prices, | ||
$volume, | ||
$caps, | ||
); | ||
} | ||
} |
Oops, something went wrong.