fix: convert avg_price from pence to pounds before linear regression calculation
This commit is contained in:
@@ -128,7 +128,7 @@ class NationalFuelPredictionService
|
||||
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) {
|
||||
$slope = $regression['slope'];
|
||||
@@ -260,8 +260,8 @@ class NationalFuelPredictionService
|
||||
return $this->disabledSignal('Insufficient brand data for comparison');
|
||||
}
|
||||
|
||||
$supermarketSlope = $this->linearRegression($supermarket->pluck('avg_price')->map(fn ($v) => (float) $v)->values()->all())['slope'];
|
||||
$majorSlope = $this->linearRegression($major->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 / 100)->values()->all())['slope'];
|
||||
|
||||
$divergence = round(abs($supermarketSlope - $majorSlope) * 7, 1);
|
||||
$supermarketChange = round($supermarketSlope * 7, 1);
|
||||
@@ -369,7 +369,7 @@ class NationalFuelPredictionService
|
||||
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) {
|
||||
$regionalRegression['slope'] >= self::SLOPE_THRESHOLD_PENCE => 'up',
|
||||
$regionalRegression['slope'] <= -self::SLOPE_THRESHOLD_PENCE => 'down',
|
||||
|
||||
Reference in New Issue
Block a user