Server
This commit is contained in:
@@ -1649,7 +1649,7 @@ final class Router
|
||||
|
||||
private function costPlans(string $projectKey): array
|
||||
{
|
||||
return $this->repository()->listCostPlans($projectKey);
|
||||
return array_map(fn (array $plan): array => $this->normalizeLegacyHashrateEntry($plan), $this->repository()->listCostPlans($projectKey));
|
||||
}
|
||||
|
||||
private function payouts(string $projectKey): array
|
||||
@@ -1770,7 +1770,7 @@ final class Router
|
||||
|
||||
private function purchasedMiners(string $projectKey): array
|
||||
{
|
||||
return $this->repository()->listPurchasedMiners($projectKey);
|
||||
return array_map(fn (array $miner): array => $this->normalizeLegacyHashrateEntry($miner), $this->repository()->listPurchasedMiners($projectKey));
|
||||
}
|
||||
|
||||
private function saveTarget(string $projectKey, array $input): array
|
||||
@@ -2392,6 +2392,48 @@ final class Router
|
||||
return $unit;
|
||||
}
|
||||
|
||||
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 requiredPositiveInt(mixed $value, string $field): int
|
||||
{
|
||||
if ($value === null || $value === '' || !is_numeric((string) $value)) {
|
||||
|
||||
Reference in New Issue
Block a user