Server
This commit is contained in:
@@ -67,10 +67,10 @@ final class AnalyticsService
|
||||
$fullLatestOnly = !empty($options['full_latest_only']);
|
||||
$baselineCoins = (float) ($settings['baseline_coins_total'] ?? 0.0);
|
||||
$baselineAt = (string) ($settings['baseline_measured_at'] ?? '');
|
||||
$costPlans = is_array($settings['cost_plans'] ?? null) ? $settings['cost_plans'] : [];
|
||||
$costPlans = $this->normalizeLegacyHashrateEntries(is_array($settings['cost_plans'] ?? null) ? $settings['cost_plans'] : []);
|
||||
$payouts = is_array($settings['payouts'] ?? null) ? $settings['payouts'] : [];
|
||||
$walletWithdrawals = is_array($settings['wallet_withdrawals'] ?? null) ? $settings['wallet_withdrawals'] : [];
|
||||
$purchasedMiners = is_array($settings['purchased_miners'] ?? null) ? $settings['purchased_miners'] : [];
|
||||
$purchasedMiners = $this->normalizeLegacyHashrateEntries(is_array($settings['purchased_miners'] ?? null) ? $settings['purchased_miners'] : []);
|
||||
$preferredPriceCurrencies = array_values(array_unique(array_filter([
|
||||
strtoupper(trim((string) ($settings['report_currency'] ?? ''))),
|
||||
'USD',
|
||||
@@ -319,7 +319,7 @@ final class AnalyticsService
|
||||
|
||||
$payouts = is_array($settings['payouts'] ?? null) ? $settings['payouts'] : [];
|
||||
$walletWithdrawals = is_array($settings['wallet_withdrawals'] ?? null) ? $settings['wallet_withdrawals'] : [];
|
||||
$purchasedMiners = is_array($settings['purchased_miners'] ?? null) ? $settings['purchased_miners'] : [];
|
||||
$purchasedMiners = $this->normalizeLegacyHashrateEntries(is_array($settings['purchased_miners'] ?? null) ? $settings['purchased_miners'] : []);
|
||||
$minerOffers = is_array($settings['miner_offers'] ?? null) ? $settings['miner_offers'] : [];
|
||||
$currentHashrateMh = $this->totalHashrateMh(array_merge(
|
||||
is_array($settings['cost_plans'] ?? null) ? $settings['cost_plans'] : [],
|
||||
@@ -1013,6 +1013,53 @@ final class AnalyticsService
|
||||
};
|
||||
}
|
||||
|
||||
private function normalizeLegacyHashrateEntries(array $entries): array
|
||||
{
|
||||
return array_map(fn (mixed $entry): mixed => is_array($entry) ? $this->normalizeLegacyHashrateEntry($entry) : $entry, $entries);
|
||||
}
|
||||
|
||||
private function normalizeLegacyHashrateEntry(array $entry): array
|
||||
{
|
||||
$label = trim((string) ($entry['label'] ?? ''));
|
||||
$speedValue = is_numeric($entry['mining_speed_value'] ?? null) ? (float) $entry['mining_speed_value'] : null;
|
||||
$speedUnit = trim((string) ($entry['mining_speed_unit'] ?? ''));
|
||||
$bonusValue = is_numeric($entry['bonus_speed_value'] ?? null) ? (float) $entry['bonus_speed_value'] : null;
|
||||
$bonusUnit = trim((string) ($entry['bonus_speed_unit'] ?? ''));
|
||||
$expectedKhValue = $this->legacyExpectedKhValueFromLabel($label);
|
||||
|
||||
if ($expectedKhValue === null) {
|
||||
return $entry;
|
||||
}
|
||||
|
||||
if ($speedUnit === 'MH/s' && $speedValue !== null && abs($speedValue - $expectedKhValue) < 0.0001) {
|
||||
$entry['mining_speed_unit'] = 'kH/s';
|
||||
}
|
||||
|
||||
$expectedBonus = round($expectedKhValue * 0.1, 4);
|
||||
if ($bonusUnit === 'MH/s' && $bonusValue !== null && abs($bonusValue - $expectedBonus) < 0.0001) {
|
||||
$entry['bonus_speed_unit'] = 'kH/s';
|
||||
}
|
||||
|
||||
return $entry;
|
||||
}
|
||||
|
||||
private function legacyExpectedKhValueFromLabel(string $label): ?float
|
||||
{
|
||||
if ($label === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (preg_match('/\b(\d+(?:[.,]\d+)?)\s*kH\/s\b/i', $label, $matches) === 1) {
|
||||
return (float) str_replace(',', '.', $matches[1]);
|
||||
}
|
||||
|
||||
if (preg_match('/\b(\d{2,4})\s*er\b/i', $label, $matches) === 1) {
|
||||
return (float) $matches[1];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function expandOfferVariants(array $offers, array $settings): array
|
||||
{
|
||||
$expanded = [];
|
||||
|
||||
Reference in New Issue
Block a user