Adds three resources under a new "Forecasting" navigation group: a full-CRUD WatchedEventResource for the Layer 5 volatility detector, plus read-only WeeklyForecastResource and BacktestResource so the ridge model output and its calibration can be inspected without SQL. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
88 lines
3.2 KiB
PHP
88 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\WeeklyForecasts\Tables;
|
|
|
|
use App\Models\WeeklyForecast;
|
|
use Filament\Actions\ViewAction;
|
|
use Filament\Tables\Columns\IconColumn;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Filters\Filter;
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
class WeeklyForecastsTable
|
|
{
|
|
public static function configure(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('forecast_for')
|
|
->label('Forecast for')
|
|
->date('d M Y')
|
|
->sortable(),
|
|
TextColumn::make('direction')
|
|
->badge()
|
|
->color(fn (string $state) => match ($state) {
|
|
'rising' => 'warning',
|
|
'falling' => 'success',
|
|
default => 'gray',
|
|
}),
|
|
TextColumn::make('magnitude_pence')
|
|
->label('Magnitude')
|
|
->state(fn (WeeklyForecast $record): string => self::formatMagnitude($record->magnitude_pence))
|
|
->sortable(),
|
|
TextColumn::make('ridge_confidence')
|
|
->label('Confidence')
|
|
->state(fn (WeeklyForecast $record): string => $record->ridge_confidence.'%')
|
|
->color(fn (WeeklyForecast $record) => $record->ridge_confidence < 40 ? 'warning' : null)
|
|
->sortable(),
|
|
IconColumn::make('flagged_duty_change')
|
|
->label('Duty change')
|
|
->boolean()
|
|
->trueColor('warning'),
|
|
TextColumn::make('model_version')
|
|
->searchable()
|
|
->limit(32)
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
TextColumn::make('generated_at')
|
|
->dateTime('d M Y H:i')
|
|
->sortable()
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
])
|
|
->defaultSort('forecast_for', 'desc')
|
|
->filters([
|
|
SelectFilter::make('direction')
|
|
->multiple()
|
|
->options([
|
|
'rising' => 'Rising',
|
|
'falling' => 'Falling',
|
|
'flat' => 'Flat',
|
|
]),
|
|
Filter::make('high_confidence')
|
|
->label('High confidence')
|
|
->toggle()
|
|
->query(fn (Builder $query) => $query->where('ridge_confidence', '>=', 70)),
|
|
Filter::make('flagged_duty_change')
|
|
->label('Duty-change-adjacent')
|
|
->toggle()
|
|
->query(fn (Builder $query) => $query->where('flagged_duty_change', true)),
|
|
])
|
|
->recordActions([
|
|
ViewAction::make(),
|
|
]);
|
|
}
|
|
|
|
protected static function formatMagnitude(?int $magnitudePence): string
|
|
{
|
|
if ($magnitudePence === null) {
|
|
return '—';
|
|
}
|
|
|
|
$pence = round($magnitudePence / 100, 1);
|
|
$sign = $pence > 0 ? '+' : '';
|
|
|
|
return $sign.$pence.'p';
|
|
}
|
|
}
|