KoogleApp/src/Koogle.Web/Components/Shared/PlayerStatisticsWidget.razor

177 lines
7.4 KiB
Plaintext

@using Koogle.Application.DTOs
@using Koogle.Application.Interfaces
@inject IPlayerStatisticsService StatisticsService
@inject ISnackbar Snackbar
<MudCard Elevation="2">
<MudCardHeader>
<CardHeaderContent>
<MudText Typo="Typo.h6">Kegelstatistik @DateTime.Now.Year</MudText>
</CardHeaderContent>
</MudCardHeader>
<MudCardContent>
@if (_isLoading)
{
<MudProgressCircular Indeterminate="true" Size="Size.Small" />
}
else if (_stats != null)
{
@if (_stats.TotalThrowsThisYear == 0)
{
<MudText Typo="Typo.body2" Color="Color.Secondary">
Noch keine Statistiken vorhanden. Spiele ein paar Runden!
</MudText>
}
else
{
<MudGrid Spacing="2">
<MudItem xs="6" sm="3">
<div class="d-flex flex-column align-center">
<MudIcon Icon="@Icons.Material.Filled.SportsScore" Size="Size.Medium" Color="Color.Primary" />
<MudText Typo="Typo.h5" Class="mt-1">@_stats.TotalGamesThisYear</MudText>
<MudText Typo="Typo.caption" Color="Color.Secondary">Spiele</MudText>
</div>
</MudItem>
<MudItem xs="6" sm="3">
<div class="d-flex flex-column align-center">
<MudIcon Icon="@Icons.Material.Filled.Gesture" Size="Size.Medium" Color="Color.Info" />
<MudText Typo="Typo.h5" Class="mt-1">@_stats.TotalThrowsThisYear</MudText>
<MudText Typo="Typo.caption" Color="Color.Secondary">Wuerfe</MudText>
</div>
</MudItem>
<MudItem xs="6" sm="3">
<div class="d-flex flex-column align-center">
<MudIcon Icon="@Icons.Material.Filled.Adjust" Size="Size.Medium" Color="Color.Success" />
<MudText Typo="Typo.h5" Class="mt-1">@_stats.TotalPinsThisYear</MudText>
<MudText Typo="Typo.caption" Color="Color.Secondary">Kegel</MudText>
</div>
</MudItem>
<MudItem xs="6" sm="3">
<div class="d-flex flex-column align-center">
<MudIcon Icon="@Icons.Material.Filled.TrendingUp" Size="Size.Medium" Color="Color.Warning" />
<MudText Typo="Typo.h5" Class="mt-1">@_stats.ClubAverageThisYear.ToString("F2")</MudText>
<MudText Typo="Typo.caption" Color="Color.Secondary">Durchschnitt</MudText>
</div>
</MudItem>
</MudGrid>
@if (_stats.TopPerformers.Count > 0)
{
<MudDivider Class="my-4" />
<MudText Typo="Typo.subtitle2" Class="mb-2">Top Kegler</MudText>
<MudList T="TopPerformerDto" Dense="true">
@{ var rank = 1; }
@foreach (var performer in _stats.TopPerformers.Take(5))
{
<MudListItem T="TopPerformerDto">
<div class="d-flex justify-space-between align-center" style="width: 100%">
<div class="d-flex align-center">
<MudAvatar Size="Size.Small" Color="@GetRankColor(rank)" Class="mr-2">@rank</MudAvatar>
<div>
<MudText Typo="Typo.body2">@performer.PersonName</MudText>
<MudText Typo="Typo.caption" Color="Color.Secondary">
@performer.TotalThrows Wuerfe, @performer.TotalPins Kegel
</MudText>
</div>
</div>
<MudChip T="string" Size="Size.Small" Color="Color.Success">
@performer.Average.ToString("F2")
</MudChip>
</div>
</MudListItem>
rank++;
}
</MudList>
}
@if (_stats.MonthlyTrend.Count > 0)
{
<MudDivider Class="my-4" />
<MudText Typo="Typo.subtitle2" Class="mb-2">Monatstrend</MudText>
<MudSimpleTable Dense="true" Hover="true">
<thead>
<tr>
<th>Monat</th>
<th style="text-align: right">Spiele</th>
<th style="text-align: right">Wuerfe</th>
<th style="text-align: right">Durchschnitt</th>
</tr>
</thead>
<tbody>
@foreach (var month in _stats.MonthlyTrend.TakeLast(6))
{
<tr>
<td>@GetMonthName(month.Month)</td>
<td style="text-align: right">@month.Games</td>
<td style="text-align: right">@month.Throws</td>
<td style="text-align: right">
<MudChip T="string" Size="Size.Small"
Color="@GetAverageColor(month.Average)"
Variant="Variant.Text">
@month.Average.ToString("F2")
</MudChip>
</td>
</tr>
}
</tbody>
</MudSimpleTable>
}
}
}
</MudCardContent>
</MudCard>
@code {
private StatisticsWidgetDto? _stats;
private bool _isLoading = true;
protected override async Task OnInitializedAsync()
{
try
{
_stats = await StatisticsService.GetDashboardStatisticsAsync();
}
catch (Exception ex)
{
Snackbar.Add($"Fehler beim Laden der Statistiken: {ex.Message}", Severity.Error);
}
finally
{
_isLoading = false;
}
}
private static Color GetRankColor(int rank) => rank switch
{
1 => Color.Warning, // Gold
2 => Color.Default, // Silver
3 => Color.Tertiary, // Bronze
_ => Color.Default
};
private static Color GetAverageColor(double average) => average switch
{
>= 7 => Color.Success,
>= 5 => Color.Warning,
_ => Color.Error
};
private static string GetMonthName(int month) => month switch
{
1 => "Jan",
2 => "Feb",
3 => "Mär",
4 => "Apr",
5 => "Mai",
6 => "Jun",
7 => "Jul",
8 => "Aug",
9 => "Sep",
10 => "Okt",
11 => "Nov",
12 => "Dez",
_ => month.ToString()
};
}