fix: convert avg_price from pence to pounds before linear regression calculation
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.3) (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled

This commit is contained in:
Ovidiu U
2026-04-07 14:51:14 +01:00
parent 6da626347b
commit 0b26c4c257

View File

@@ -128,7 +128,7 @@ class NationalFuelPredictionService
continue; continue;
} }
$regression = $this->linearRegression($rows->pluck('avg_price')->map(fn ($v) => (float) $v)->values()->all()); $regression = $this->linearRegression($rows->pluck('avg_price')->map(fn ($v) => (float) $v / 100)->values()->all());
if ($regression['r_squared'] >= self::R_SQUARED_THRESHOLD) { if ($regression['r_squared'] >= self::R_SQUARED_THRESHOLD) {
$slope = $regression['slope']; $slope = $regression['slope'];
@@ -260,8 +260,8 @@ class NationalFuelPredictionService
return $this->disabledSignal('Insufficient brand data for comparison'); return $this->disabledSignal('Insufficient brand data for comparison');
} }
$supermarketSlope = $this->linearRegression($supermarket->pluck('avg_price')->map(fn ($v) => (float) $v)->values()->all())['slope']; $supermarketSlope = $this->linearRegression($supermarket->pluck('avg_price')->map(fn ($v) => (float) $v / 100)->values()->all())['slope'];
$majorSlope = $this->linearRegression($major->pluck('avg_price')->map(fn ($v) => (float) $v)->values()->all())['slope']; $majorSlope = $this->linearRegression($major->pluck('avg_price')->map(fn ($v) => (float) $v / 100)->values()->all())['slope'];
$divergence = round(abs($supermarketSlope - $majorSlope) * 7, 1); $divergence = round(abs($supermarketSlope - $majorSlope) * 7, 1);
$supermarketChange = round($supermarketSlope * 7, 1); $supermarketChange = round($supermarketSlope * 7, 1);
@@ -369,7 +369,7 @@ class NationalFuelPredictionService
return $this->disabledSignal('Insufficient regional data'); return $this->disabledSignal('Insufficient regional data');
} }
$regionalRegression = $this->linearRegression($rows->pluck('avg_price')->map(fn ($v) => (float) $v)->values()->all()); $regionalRegression = $this->linearRegression($rows->pluck('avg_price')->map(fn ($v) => (float) $v / 100)->values()->all());
$direction = match (true) { $direction = match (true) {
$regionalRegression['slope'] >= self::SLOPE_THRESHOLD_PENCE => 'up', $regionalRegression['slope'] >= self::SLOPE_THRESHOLD_PENCE => 'up',
$regionalRegression['slope'] <= -self::SLOPE_THRESHOLD_PENCE => 'down', $regionalRegression['slope'] <= -self::SLOPE_THRESHOLD_PENCE => 'down',