refactor: extract 6 prediction signals into Signal classes
The 803-line NationalFuelPredictionService had six private compute*Signal methods, a private linearRegression helper, and a private disabledSignal shape factory all crammed together. Each signal is now an independently testable class. - App\Services\Prediction\Signals\Signal — interface - App\Services\Prediction\Signals\SignalContext — input value object (FuelType + optional lat/lng + hasCoordinates() helper) - App\Services\Prediction\Signals\AbstractSignal — shared disabledSignal() and linearRegression() helpers - TrendSignal, DayOfWeekSignal, BrandBehaviourSignal, StickinessSignal, RegionalMomentumSignal, OilSignal — one class each, extending AbstractSignal NationalFuelPredictionService receives the 6 signal classes via constructor injection and orchestrates them. The lat/lng null-guard for regional momentum now lives inside RegionalMomentumSignal::compute() so the coordinator no longer branches on coordinate presence. Aggregation, weekly summary, and reasoning helpers stay in the service for now — they are coupled to the public predict() output shape and are candidates for a follow-up extraction once a stable API is locked in. Service: 803 → 414 lines. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
24
app/Services/Prediction/Signals/Signal.php
Normal file
24
app/Services/Prediction/Signals/Signal.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Prediction\Signals;
|
||||
|
||||
interface Signal
|
||||
{
|
||||
/**
|
||||
* Evaluate the signal against the given context.
|
||||
*
|
||||
* Returns the canonical signal payload. Implementations may add extra
|
||||
* keys beyond the base shape (e.g. trend adds slope + r_squared).
|
||||
*
|
||||
* @return array{
|
||||
* score: float,
|
||||
* confidence: float,
|
||||
* direction: string,
|
||||
* detail: string,
|
||||
* data_points: int,
|
||||
* enabled: bool,
|
||||
* ...
|
||||
* }
|
||||
*/
|
||||
public function compute(SignalContext $context): array;
|
||||
}
|
||||
Reference in New Issue
Block a user