using Avalonia.Controls; using Avalonia.Interactivity; using LehrerApp.Desktop.Services; using LehrerApp.Desktop.ViewModels.Groups; using Microsoft.Extensions.DependencyInjection; namespace LehrerApp.Desktop.Views.Groups; public partial class ExamEvaluationDialog : Window { public ExamEvaluationDialog() => InitializeComponent(); private async void OnExportClick(object? sender, RoutedEventArgs e) { if (DataContext is not ExamEvaluationDialogViewModel vm) return; var topLevel = TopLevel.GetTopLevel(this); if (topLevel is null) return; var export = ExportFile.Csv("Klausurauswertung exportieren", $"Auswertung_{vm.ExamTitle}.csv", vm.ExportCsv()); await App.Services.GetRequiredService().SaveAsync(topLevel.StorageProvider, export); } private async void OnExportPdfClick(object? sender, RoutedEventArgs e) { if (DataContext is not ExamEvaluationDialogViewModel vm) return; var topLevel = TopLevel.GetTopLevel(this); if (topLevel is null) return; var stats = new List { new("Bewertet", vm.GradedCount.ToString()), new("Abwesend", vm.AbsentCount.ToString()), new("Durchschnitt", vm.AverageDisplay), new("Median", vm.MedianDisplay), }; if (!string.IsNullOrEmpty(vm.BelowThresholdLabel1)) stats.Add(new(vm.BelowThresholdLabel1, vm.BelowThresholdDisplay1)); if (!string.IsNullOrEmpty(vm.BelowThresholdLabel2)) stats.Add(new(vm.BelowThresholdLabel2, vm.BelowThresholdDisplay2)); var data = new ExamStatisticsPrintData(vm.ExamTitle, vm.ExamDateLabel, vm.NiveauLabel, stats, vm.GradeDistribution.Select(g => new GradeDistributionPrintRow(g.Grade, g.Count, vm.GradedCount == 0 ? 0 : g.Count * 100.0 / vm.GradedCount)).ToList(), vm.TaskAnalysis.Select(t => new TaskAnalysisPrintRow(t.Label, t.AvgPercent, t.IsWeak)).ToList()); var pdf = App.Services.GetRequiredService().BuildExamStatisticsPdf(data); await App.Services.GetRequiredService().SaveAsync(topLevel.StorageProvider, ExportFile.Pdf("Klausurauswertung als PDF speichern", $"Auswertung_{vm.ExamTitle}", pdf)); } private void OnClose(object? sender, RoutedEventArgs e) => Close(); }