Files
WebAPP/app/Models/EventPlayerStat.php
Rhino f24f7f12a3 Erweiterte Spielerstatistiken: 7-Meter, Strafen, Spielzeit
Neue Metriken für Jugendhandball: 7m-Würfe/-Tore, Gelbe Karten,
2-Minuten-Strafen und Spielzeit. Migration, Model, Controller, Views
und Übersetzungen (6 Sprachen) vollständig implementiert.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 23:50:03 +01:00

106 lines
2.6 KiB
PHP

<?php
namespace App\Models;
use App\Enums\PlayerPosition;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class EventPlayerStat extends Model
{
protected $fillable = [
'event_id',
'player_id',
'is_goalkeeper',
'position',
'goalkeeper_saves',
'goalkeeper_shots',
'goals',
'shots',
'penalty_goals',
'penalty_shots',
'yellow_cards',
'two_minute_suspensions',
'playing_time_minutes',
'note',
];
protected $casts = [
'is_goalkeeper' => 'boolean',
'position' => PlayerPosition::class,
'goalkeeper_saves' => 'integer',
'goalkeeper_shots' => 'integer',
'goals' => 'integer',
'shots' => 'integer',
'penalty_goals' => 'integer',
'penalty_shots' => 'integer',
'yellow_cards' => 'integer',
'two_minute_suspensions' => 'integer',
'playing_time_minutes' => 'integer',
];
public function event(): BelongsTo
{
return $this->belongsTo(Event::class);
}
public function player(): BelongsTo
{
return $this->belongsTo(Player::class);
}
/**
* Fangquote in Prozent (nur für Torwart).
*/
public function saveRate(): ?float
{
if (! $this->is_goalkeeper || ! $this->goalkeeper_shots || $this->goalkeeper_shots === 0) {
return null;
}
return round(($this->goalkeeper_saves / $this->goalkeeper_shots) * 100, 1);
}
/**
* Trefferquote in Prozent.
*/
public function hitRate(): ?float
{
if (! $this->shots || $this->shots === 0) {
return null;
}
return round(($this->goals / $this->shots) * 100, 1);
}
/**
* 7-Meter-Quote in Prozent.
*/
public function penaltyRate(): ?float
{
if (! $this->penalty_shots || $this->penalty_shots === 0) {
return null;
}
return round(($this->penalty_goals / $this->penalty_shots) * 100, 1);
}
/**
* Prüft ob der Eintrag leer ist (keine relevanten Daten).
*/
public function isEmpty(): bool
{
return ! $this->is_goalkeeper
&& ! $this->goalkeeper_saves
&& ! $this->goalkeeper_shots
&& ! $this->goals
&& ! $this->shots
&& ! $this->penalty_goals
&& ! $this->penalty_shots
&& ! $this->yellow_cards
&& ! $this->two_minute_suspensions
&& ! $this->playing_time_minutes
&& ! $this->note;
}
}