asdsd
All checks were successful
Deploy / deploy-staging (push) Successful in 31s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-08-20 21:59:02 +02:00
parent 11f75ae788
commit 75a6568d7a
2 changed files with 84 additions and 30 deletions

View File

@@ -417,14 +417,14 @@ final class AnalyticsService
$latestWalletSnapshotTs = is_array($latestWalletSnapshot)
? $this->utcTimestamp((string) ($latestWalletSnapshot['measured_at'] ?? ''))
: 0;
$latestLedgerActivityTs = $this->latestWalletLedgerActivityTimestamp($payouts, $walletWithdrawals, $purchasedMiners);
$useWalletSnapshot = is_array($latestWalletSnapshot)
&& $latestWalletSnapshotTs > 0
&& $latestWalletSnapshotTs >= $latestLedgerActivityTs;
$useWalletSnapshot = is_array($latestWalletSnapshot) && $latestWalletSnapshotTs > 0;
if ($useWalletSnapshot) {
$snapshotBalances = $this->walletSnapshotBalances($latestWalletSnapshot);
if ($snapshotBalances !== []) {
$walletBalances = $snapshotBalances;
$walletBalances = $this->mergeWalletBalances(
$snapshotBalances,
$this->walletBalances($payouts, $walletWithdrawals, $purchasedMiners, 0, $latestWalletSnapshotTs)
);
}
}
$latestAsset = strtoupper(trim((string) ($latest['coin_currency'] ?? $settings['crypto_currency'] ?? 'DOGE')));
@@ -437,18 +437,14 @@ final class AnalyticsService
$walletBalanceCurrentAssetDirect > 0
? $walletBalanceCurrentAssetDirect
: (
$useWalletSnapshot
? $this->walletSnapshotValue($latestWalletSnapshot, $latestAsset, $latest)
: $this->walletBalanceValue($walletBalances, $latestAsset, $latest)
$this->walletBalanceValue($walletBalances, $latestAsset, $latest)
)
)
: null;
$holdingsCurrentAsset = ($walletBalanceCurrentAssetEquivalent !== null ? $walletBalanceCurrentAssetEquivalent : 0.0) + $adjustedVisibleCoins;
$walletValue = $latestCurrency !== ''
? (
$useWalletSnapshot
? $this->walletSnapshotValue($latestWalletSnapshot, $latestCurrency, $latest)
: $this->walletBalanceValue($walletBalances, $latestCurrency, $latest)
$this->walletBalanceValue($walletBalances, $latestCurrency, $latest)
)
: null;
$effectivePricePerCoin = is_numeric($latest['effective_price_per_coin'] ?? null) ? (float) $latest['effective_price_per_coin'] : null;
@@ -1585,7 +1581,7 @@ final class AnalyticsService
return $endIndex - $startIndex + 1;
}
private function walletBalances(array $payouts, array $walletWithdrawals, array $purchasedMiners, int $measurementTs): array
private function walletBalances(array $payouts, array $walletWithdrawals, array $purchasedMiners, int $measurementTs, int $afterTs = 0): array
{
$balances = [];
@@ -1594,6 +1590,9 @@ final class AnalyticsService
if ($measurementTs > 0 && $payoutTs > $measurementTs) {
continue;
}
if ($afterTs > 0 && $payoutTs <= $afterTs) {
continue;
}
$currency = strtoupper(trim((string) ($payout['payout_currency'] ?? '')));
$amount = is_numeric($payout['coins_amount'] ?? null) ? (float) $payout['coins_amount'] : null;
@@ -1609,6 +1608,9 @@ final class AnalyticsService
if ($measurementTs > 0 && $purchaseTs > $measurementTs) {
continue;
}
if ($afterTs > 0 && $purchaseTs <= $afterTs) {
continue;
}
if ($this->entryFundingSource($miner) !== 'reinvest') {
continue;
}
@@ -1627,6 +1629,9 @@ final class AnalyticsService
if ($measurementTs > 0 && $withdrawalTs > $measurementTs) {
continue;
}
if ($afterTs > 0 && $withdrawalTs <= $afterTs) {
continue;
}
$currency = strtoupper(trim((string) ($withdrawal['withdrawal_currency'] ?? '')));
$amount = is_numeric($withdrawal['coins_amount'] ?? null) ? (float) $withdrawal['coins_amount'] : null;
@@ -1641,6 +1646,22 @@ final class AnalyticsService
return array_map(fn (float $value): float => round($value, 8), $balances);
}
private function mergeWalletBalances(array $baseBalances, array $deltaBalances): array
{
$merged = $baseBalances;
foreach ($deltaBalances as $currency => $amount) {
$normalizedCurrency = strtoupper(trim((string) $currency));
if ($normalizedCurrency === '' || !is_numeric($amount)) {
continue;
}
$merged[$normalizedCurrency] = round((float) ($merged[$normalizedCurrency] ?? 0.0) + (float) $amount, 8);
}
ksort($merged);
return $merged;
}
private function latestWalletSnapshot(array $walletSnapshots): ?array
{
foreach ($walletSnapshots as $snapshot) {