feat(admin): add Filament resources for the forecasting stack
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>
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\WeeklyForecasts\Pages;
|
||||
|
||||
use App\Filament\Resources\WeeklyForecasts\WeeklyForecastResource;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListWeeklyForecasts extends ListRecords
|
||||
{
|
||||
protected static string $resource = WeeklyForecastResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\WeeklyForecasts\Pages;
|
||||
|
||||
use App\Filament\Resources\WeeklyForecasts\WeeklyForecastResource;
|
||||
use Filament\Resources\Pages\ViewRecord;
|
||||
|
||||
class ViewWeeklyForecast extends ViewRecord
|
||||
{
|
||||
protected static string $resource = WeeklyForecastResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\WeeklyForecasts\Schemas;
|
||||
|
||||
use App\Models\WeeklyForecast;
|
||||
use Filament\Infolists\Components\IconEntry;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class WeeklyForecastInfolist
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Section::make('Forecast')->columns(3)->schema([
|
||||
TextEntry::make('forecast_for')->date('d M Y'),
|
||||
TextEntry::make('direction')
|
||||
->badge()
|
||||
->color(fn (string $state) => match ($state) {
|
||||
'rising' => 'warning',
|
||||
'falling' => 'success',
|
||||
default => 'gray',
|
||||
}),
|
||||
TextEntry::make('magnitude_pence')
|
||||
->label('Magnitude')
|
||||
->state(fn (WeeklyForecast $record): string => self::formatMagnitude($record->magnitude_pence)),
|
||||
TextEntry::make('ridge_confidence')
|
||||
->label('Confidence')
|
||||
->state(fn (WeeklyForecast $record): string => $record->ridge_confidence.'%')
|
||||
->color(fn (WeeklyForecast $record) => $record->ridge_confidence < 40 ? 'warning' : null),
|
||||
IconEntry::make('flagged_duty_change')
|
||||
->label('Duty change adjacent')
|
||||
->boolean()
|
||||
->trueColor('warning'),
|
||||
TextEntry::make('generated_at')->dateTime('d M Y H:i'),
|
||||
]),
|
||||
Section::make('Reasoning')->schema([
|
||||
TextEntry::make('reasoning')
|
||||
->columnSpanFull()
|
||||
->placeholder('No reasoning recorded.'),
|
||||
]),
|
||||
Section::make('Model')
|
||||
->description('Calibration table from the matching backtest determines the displayed confidence.')
|
||||
->schema([
|
||||
TextEntry::make('model_version')->columnSpanFull(),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
protected static function formatMagnitude(?int $magnitudePence): string
|
||||
{
|
||||
if ($magnitudePence === null) {
|
||||
return '—';
|
||||
}
|
||||
|
||||
$pence = round($magnitudePence / 100, 1);
|
||||
$sign = $pence > 0 ? '+' : '';
|
||||
|
||||
return $sign.$pence.'p';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?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';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\WeeklyForecasts;
|
||||
|
||||
use App\Filament\NavigationGroup;
|
||||
use App\Filament\Resources\WeeklyForecasts\Pages\ListWeeklyForecasts;
|
||||
use App\Filament\Resources\WeeklyForecasts\Pages\ViewWeeklyForecast;
|
||||
use App\Filament\Resources\WeeklyForecasts\Schemas\WeeklyForecastInfolist;
|
||||
use App\Filament\Resources\WeeklyForecasts\Tables\WeeklyForecastsTable;
|
||||
use App\Models\WeeklyForecast;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WeeklyForecastResource extends Resource
|
||||
{
|
||||
protected static ?string $model = WeeklyForecast::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedChartBar;
|
||||
|
||||
protected static string|\UnitEnum|null $navigationGroup = NavigationGroup::Forecasting;
|
||||
|
||||
protected static ?string $navigationLabel = 'Weekly Forecasts';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
public static function infolist(Schema $schema): Schema
|
||||
{
|
||||
return WeeklyForecastInfolist::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return WeeklyForecastsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function canCreate(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function canEdit(Model $record): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function canDelete(Model $record): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListWeeklyForecasts::route('/'),
|
||||
'view' => ViewWeeklyForecast::route('/{record}'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user