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

This commit is contained in:
2026-05-02 02:03:42 +02:00
parent 58d0c18e25
commit 6cbf76918c
4 changed files with 195 additions and 50 deletions

View File

@@ -868,50 +868,58 @@ final class AnalyticsService
$dogePerDayPerMh = $dogePerDay / $currentHashrateMh;
$revenue = 0.0;
$cost = 0.0;
$hashrateDayTotal = 0.0;
for ($day = 0; $day < $days; $day++) {
$checkTs = $baseTs + ($day * 86400);
$activeHashrate = 0.0;
foreach ($costPlans as $plan) {
if (empty($plan['is_active']) || !$this->entryIsCovered($plan, $checkTs)) {
continue;
}
$activeHashrate += $this->normalizeHashrateMh($plan['mining_speed_value'] ?? null, $plan['mining_speed_unit'] ?? null);
$activeHashrate += $this->normalizeHashrateMh($plan['bonus_speed_value'] ?? null, $plan['bonus_speed_unit'] ?? null);
$runtimeMonths = (int) ($plan['runtime_months'] ?? 0);
if ($runtimeMonths > 0 && is_numeric($plan['total_cost_amount'] ?? null)) {
$runtimeDays = $runtimeMonths * 30.4375;
$dailyCost = $this->convertAmount((float) $plan['total_cost_amount'] / $runtimeDays, (string) ($plan['currency'] ?? ''), $currency, $latest);
if ($dailyCost !== null) {
$cost += $dailyCost;
}
}
foreach ($costPlans as $plan) {
if (empty($plan['is_active'])) {
continue;
}
foreach ($purchasedMiners as $miner) {
if ((array_key_exists('is_active', $miner) && empty($miner['is_active'])) || !$this->entryIsCovered($miner, $checkTs, 'purchased_at')) {
continue;
}
$activeHashrate += $this->normalizeHashrateMh($miner['mining_speed_value'] ?? null, $miner['mining_speed_unit'] ?? null);
$activeHashrate += $this->normalizeHashrateMh($miner['bonus_speed_value'] ?? null, $miner['bonus_speed_unit'] ?? null);
$runtimeMonths = (int) ($miner['runtime_months'] ?? 0);
if ($runtimeMonths > 0 && is_numeric($miner['total_cost_amount'] ?? null)) {
$runtimeDays = $runtimeMonths * 30.4375;
$dailyCost = $this->convertAmount((float) $miner['total_cost_amount'] / $runtimeDays, (string) ($miner['currency'] ?? ''), $currency, $latest);
if ($dailyCost !== null) {
$cost += $dailyCost;
}
}
$coveredDays = $this->entryCoveredDayCount($plan, $baseTs, $days);
if ($coveredDays <= 0) {
continue;
}
$revenue += $activeHashrate * $dogePerDayPerMh * $pricePerCoin;
$entryHashrateMh = $this->normalizeHashrateMh($plan['mining_speed_value'] ?? null, $plan['mining_speed_unit'] ?? null)
+ $this->normalizeHashrateMh($plan['bonus_speed_value'] ?? null, $plan['bonus_speed_unit'] ?? null);
$hashrateDayTotal += $entryHashrateMh * $coveredDays;
$runtimeMonths = (int) ($plan['runtime_months'] ?? 0);
if ($runtimeMonths > 0 && is_numeric($plan['total_cost_amount'] ?? null)) {
$runtimeDays = $runtimeMonths * 30.4375;
$dailyCost = $this->convertAmount((float) $plan['total_cost_amount'] / $runtimeDays, (string) ($plan['currency'] ?? ''), $currency, $latest);
if ($dailyCost !== null) {
$cost += $dailyCost * $coveredDays;
}
}
}
foreach ($purchasedMiners as $miner) {
if (array_key_exists('is_active', $miner) && empty($miner['is_active'])) {
continue;
}
$coveredDays = $this->entryCoveredDayCount($miner, $baseTs, $days, 'purchased_at');
if ($coveredDays <= 0) {
continue;
}
$entryHashrateMh = $this->normalizeHashrateMh($miner['mining_speed_value'] ?? null, $miner['mining_speed_unit'] ?? null)
+ $this->normalizeHashrateMh($miner['bonus_speed_value'] ?? null, $miner['bonus_speed_unit'] ?? null);
$hashrateDayTotal += $entryHashrateMh * $coveredDays;
$runtimeMonths = (int) ($miner['runtime_months'] ?? 0);
if ($runtimeMonths > 0 && is_numeric($miner['total_cost_amount'] ?? null)) {
$runtimeDays = $runtimeMonths * 30.4375;
$dailyCost = $this->convertAmount((float) $miner['total_cost_amount'] / $runtimeDays, (string) ($miner['currency'] ?? ''), $currency, $latest);
if ($dailyCost !== null) {
$cost += $dailyCost * $coveredDays;
}
}
}
$revenue = $hashrateDayTotal * $dogePerDayPerMh * $pricePerCoin;
return [
'days' => $days,
'revenue' => $revenue,
@@ -920,6 +928,38 @@ final class AnalyticsService
];
}
private function entryCoveredDayCount(array $entry, int $baseTs, int $days, string $startField = 'starts_at'): int
{
if ($days <= 0) {
return 0;
}
$runtimeMonths = (int) ($entry['runtime_months'] ?? 0);
$startTs = $this->utcTimestamp((string) ($entry[$startField] ?? ''));
if ($startTs <= 0) {
return $days;
}
$startIndex = max(0, (int) ceil(($startTs - $baseTs) / 86400));
if ($startIndex >= $days) {
return 0;
}
if (!empty($entry['auto_renew']) || $runtimeMonths <= 0) {
return $days - $startIndex;
}
$runtimeDays = $runtimeMonths * 30.4375;
$endTs = (int) round($startTs + ($runtimeDays * 86400));
$endIndex = (int) floor(($endTs - $baseTs) / 86400);
$endIndex = min($days - 1, $endIndex);
if ($endIndex < $startIndex) {
return 0;
}
return $endIndex - $startIndex + 1;
}
private function utcTimestamp(?string $value): int
{
$normalized = trim((string) $value);