Add shared export infrastructure

This commit is contained in:
2026-08-18 21:21:56 +02:00
parent 41bf2c0756
commit 26461bd2f2
13 changed files with 336 additions and 63 deletions
@@ -3,9 +3,9 @@ using CommunityToolkit.Mvvm.Input;
using LehrerApp.Core.Interfaces;
using LehrerApp.Core.Models;
using LehrerApp.Core.Services;
using LehrerApp.Desktop.Services;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Text;
namespace LehrerApp.Desktop.ViewModels.Groups;
@@ -195,27 +195,27 @@ public partial class ExamEvaluationDialogViewModel : ObservableObject
public string ExportCsv()
{
var sb = new StringBuilder();
sb.AppendLine($"Klausur;{_exam.Title}");
sb.AppendLine($"Datum;{_exam.Date:dd.MM.yyyy}");
sb.AppendLine();
sb.AppendLine("Notenspiegel");
sb.AppendLine("Note;Anzahl;Anteil");
var csv = new CsvBuilder()
.AddRow("Klausur", _exam.Title)
.AddRow("Datum", _exam.Date.ToString("dd.MM.yyyy", CultureInfo.InvariantCulture))
.AddBlankRow()
.AddRow("Notenspiegel")
.AddRow("Note", "Anzahl", "Anteil");
foreach (var g in GradeDistribution)
sb.AppendLine($"{g.Grade};{g.Count};{Percent(g.Count, GradedCount)}");
sb.AppendLine();
sb.AppendLine($"Durchschnitt;{AverageDisplay}");
sb.AppendLine($"Median;{MedianDisplay}");
if (!string.IsNullOrEmpty(BelowThresholdLabel1)) sb.AppendLine($"{BelowThresholdLabel1};{BelowThresholdDisplay1}");
if (!string.IsNullOrEmpty(BelowThresholdLabel2)) sb.AppendLine($"{BelowThresholdLabel2};{BelowThresholdDisplay2}");
sb.AppendLine($"Bewertet;{GradedCount}");
sb.AppendLine($"Abwesend;{AbsentCount}");
sb.AppendLine();
sb.AppendLine("Aufgabenanalyse");
sb.AppendLine("Aufgabe;Ø Erfüllungsgrad;Auffällig schwach");
csv.AddRow(g.Grade, g.Count, Percent(g.Count, GradedCount));
csv.AddBlankRow()
.AddRow("Durchschnitt", AverageDisplay)
.AddRow("Median", MedianDisplay);
if (!string.IsNullOrEmpty(BelowThresholdLabel1)) csv.AddRow(BelowThresholdLabel1, BelowThresholdDisplay1);
if (!string.IsNullOrEmpty(BelowThresholdLabel2)) csv.AddRow(BelowThresholdLabel2, BelowThresholdDisplay2);
csv.AddRow("Bewertet", GradedCount)
.AddRow("Abwesend", AbsentCount)
.AddBlankRow()
.AddRow("Aufgabenanalyse")
.AddRow("Aufgabe", "Ø Erfüllungsgrad", "Auffällig schwach");
foreach (var t in TaskAnalysis)
sb.AppendLine($"{t.Label};{t.AvgPercentDisplay};{(t.IsWeak ? "ja" : "")}");
return sb.ToString();
csv.AddRow(t.Label, t.AvgPercentDisplay, t.IsWeak ? "ja" : "");
return csv.ToString();
}
}
@@ -3,9 +3,9 @@ using CommunityToolkit.Mvvm.Input;
using LehrerApp.Core.Interfaces;
using LehrerApp.Core.Models;
using LehrerApp.Core.Services;
using LehrerApp.Desktop.Services;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Text;
namespace LehrerApp.Desktop.ViewModels.Groups;
@@ -197,12 +197,13 @@ public partial class ReportGradeDialogViewModel : ObservableObject
public string ExportCsv()
{
var sb = new StringBuilder();
sb.AppendLine($"Zeugnisnoten;{_groupLabel};{SelectedPeriod.Label}");
sb.AppendLine("Schüler;Berechnet;Übersteuert;Begründung;Endnote;Gesperrt");
var csv = new CsvBuilder()
.AddRow("Zeugnisnoten", _groupLabel, SelectedPeriod.Label)
.AddRow("Schüler", "Berechnet", "Übersteuert", "Begründung", "Endnote", "Gesperrt");
foreach (var r in Rows)
sb.AppendLine($"{r.Name};{r.CalculatedValue};{r.OverrideValue};{r.OverrideReason};{r.FinalDisplay};{(r.IsLocked ? "ja" : "")}");
return sb.ToString();
csv.AddRow(r.Name, r.CalculatedValue, r.OverrideValue, r.OverrideReason,
r.FinalDisplay, r.IsLocked ? "ja" : "");
return csv.ToString();
}
}