*/ use HasFactory; protected $fillable = ['day', 'component', 'samples', 'operational', 'degraded', 'down', 'unknown']; protected function casts(): array { return ['day' => 'date']; } /** * The share of samples in which the component answered, as a percentage. * * Degraded counts as up: the service was reachable and doing its job less * well, and folding it into downtime would report a slow morning as an * outage. It still colours the bar — see the view. */ public function uptimePercent(): ?float { $measured = $this->samples - $this->unknown; if ($measured <= 0) { return null; } return round(($this->operational + $this->degraded) / $measured * 100, 3); } /** The worst thing seen that day — what the bar is coloured by. */ public function worst(): string { return match (true) { $this->down > 0 => 'down', $this->degraded > 0 => 'degraded', $this->operational > 0 => 'operational', default => 'unknown', }; } }