Klausurvarianten, Bonuspunkte und Wiederholungen ergänzen
This commit is contained in:
1 parent
54ad7f7419
commit
431d023c1a
22 files changed
+522
-40
No files matched your search
@@ -13,6 +13,7 @@ namespace LehrerApp.Desktop.ViewModels.Groups;
|
||||
public partial class ExamDialogViewModel : ObservableObject
|
||||
{
|
||||
private readonly IExamRepository _exams;
|
||||
private readonly IExamResultRepository? _results;
|
||||
private readonly ICompetencyDomainRepository _competencyDomains;
|
||||
private readonly IGradingKeyTemplateRepository _gradingKeyTemplates;
|
||||
private readonly GradingService _grading;
|
||||
@@ -41,13 +42,21 @@ public partial class ExamDialogViewModel : ObservableObject
|
||||
[ObservableProperty] private string _newTemplateName = "";
|
||||
[ObservableProperty] private string _gradingKeyValidation = "";
|
||||
[ObservableProperty] private string _selectedNiveauName = "–";
|
||||
[ObservableProperty] private Exam? _selectedOriginalExam;
|
||||
[ObservableProperty] private string _repeatRuleName = "Bessere zählt";
|
||||
[ObservableProperty] private string _repeatError = "";
|
||||
[ObservableProperty] private string _taskPointsError = "";
|
||||
|
||||
public bool IsDifferentiated { get; }
|
||||
public string[] NiveauOptions => NiveauDisplay.Options;
|
||||
public string[] RepeatRuleOptions => ["Bessere zählt", "Wiederholung zählt", "Erste Arbeit zählt"];
|
||||
public bool HasSelectedOriginalExam => SelectedOriginalExam is not null;
|
||||
public ObservableCollection<Exam> AvailableOriginalExams { get; } = [];
|
||||
|
||||
public bool TotalPointsWarning => TotalPoints <= 0;
|
||||
public string TotalPointsDisplay =>
|
||||
$"{TotalPoints.ToString("0.##", CultureInfo.InvariantCulture)} Punkte gesamt";
|
||||
public string TotalPointsDisplay => Tasks.Any(t => t.VariantName != "Beide")
|
||||
? $"A: {TotalPoints:0.##} · B: {Tasks.Where(t => !t.IsBonus && t.VariantName != "A").Sum(t => t.MaxPoints):0.##} Punkte (ohne Bonus)"
|
||||
: $"{TotalPoints.ToString("0.##", CultureInfo.InvariantCulture)} Punkte gesamt (ohne Bonus)";
|
||||
|
||||
public ObservableCollection<ExamTaskEditItem> Tasks { get; } = [];
|
||||
public ObservableCollection<GradingKeyEntryEditItem> GradingKeyEntries { get; } = [];
|
||||
@@ -65,9 +74,10 @@ public partial class ExamDialogViewModel : ObservableObject
|
||||
IGradingKeyTemplateRepository gradingKeyTemplates, GradingService grading,
|
||||
Guid groupId, Guid? subjectId, int gradeLevel, GradingSystem gradingSystem,
|
||||
string defaultSubjectName, bool isDifferentiated, Exam? editingExam, Exam? duplicateSource,
|
||||
Guid competencyCatalogVersionId = default)
|
||||
Guid competencyCatalogVersionId = default, IExamResultRepository? results = null)
|
||||
{
|
||||
_exams = exams; _competencyDomains = competencyDomains;
|
||||
_results = results;
|
||||
_gradingKeyTemplates = gradingKeyTemplates; _grading = grading;
|
||||
_groupId = groupId; _subjectId = subjectId; _gradeLevel = gradeLevel;
|
||||
_competencyCatalogVersionId = competencyCatalogVersionId;
|
||||
@@ -76,6 +86,12 @@ public partial class ExamDialogViewModel : ObservableObject
|
||||
_duplicateSource = duplicateSource;
|
||||
_subjectName = defaultSubjectName;
|
||||
IsDifferentiated = isDifferentiated;
|
||||
var groupExams = _exams.GetByGroup(groupId);
|
||||
foreach (var exam in groupExams
|
||||
.Where(e => e.Id != editingExam?.Id && e.RepeatOfExamId is null)
|
||||
.Where(e => !groupExams.Any(r => r.RepeatOfExamId == e.Id && r.Id != editingExam?.Id))
|
||||
.OrderByDescending(e => e.Date))
|
||||
AvailableOriginalExams.Add(exam);
|
||||
|
||||
HasCompetencyCatalog = subjectId.HasValue
|
||||
&& _competencyDomains.GetBySubjectAndGrade(subjectId.Value, gradeLevel, competencyCatalogVersionId).Count > 0;
|
||||
@@ -97,8 +113,18 @@ public partial class ExamDialogViewModel : ObservableObject
|
||||
// Beim Duplizieren bewusst kein Niveau übernehmen — meist wird dupliziert, um
|
||||
// gerade eine andere Niveau-Variante (E/G/Förder) derselben Klausur anzulegen.
|
||||
SelectedNiveauName = isDuplicate ? "–" : NiveauDisplay.ToName(source.Niveau);
|
||||
if (!isDuplicate)
|
||||
{
|
||||
SelectedOriginalExam = AvailableOriginalExams.FirstOrDefault(e => e.Id == source.RepeatOfExamId);
|
||||
RepeatRuleName = source.RepeatGradeRule switch
|
||||
{
|
||||
RepeatGradeRule.Repeat => "Wiederholung zählt",
|
||||
RepeatGradeRule.Original => "Erste Arbeit zählt",
|
||||
_ => "Bessere zählt",
|
||||
};
|
||||
}
|
||||
foreach (var t in source.Tasks.OrderBy(t => t.Nr))
|
||||
AddTaskInternal(t.Title, t.MaxPoints, t.Weight, [.. t.Competencies]);
|
||||
AddTaskInternal(t.Title, t.MaxPoints, t.Weight, [.. t.Competencies], t.Variant, t.IsBonus);
|
||||
UseWeighting = Tasks.Any(t => Math.Abs(t.Weight - 1.0) > 0.0001);
|
||||
foreach (var e in source.GradingKey.OrderByDescending(e => e.MinPercent))
|
||||
AddGradingKeyRowInternal(e.Grade, e.MinPercent);
|
||||
@@ -119,6 +145,9 @@ public partial class ExamDialogViewModel : ObservableObject
|
||||
{
|
||||
foreach (var t in Tasks) t.ShowWeight = value;
|
||||
}
|
||||
partial void OnSelectedOriginalExamChanged(Exam? value) => OnPropertyChanged(nameof(HasSelectedOriginalExam));
|
||||
|
||||
[RelayCommand] private void ClearOriginalExam() => SelectedOriginalExam = null;
|
||||
|
||||
partial void OnDateTextChanged(string value) => UpdateWeekLoadHint();
|
||||
|
||||
@@ -148,11 +177,14 @@ public partial class ExamDialogViewModel : ObservableObject
|
||||
RecomputeTotals();
|
||||
}
|
||||
|
||||
private void AddTaskInternal(string? title, double maxPoints, double weight, List<CompetencyReference> competencies)
|
||||
private void AddTaskInternal(string? title, double maxPoints, double weight, List<CompetencyReference> competencies,
|
||||
ExamVariant? variant = null, bool isBonus = false)
|
||||
{
|
||||
var item = new ExamTaskEditItem(title, maxPoints, weight, competencies,
|
||||
BuildCompetencyTagGroups(competencies))
|
||||
{
|
||||
VariantName = variant?.ToString() ?? "Beide",
|
||||
IsBonus = isBonus,
|
||||
OnChanged = RecomputeTotals,
|
||||
OnRemove = RemoveTask,
|
||||
OnMoveUp = MoveTaskUp,
|
||||
@@ -201,7 +233,7 @@ public partial class ExamDialogViewModel : ObservableObject
|
||||
|
||||
private void RecomputeTotals()
|
||||
{
|
||||
TotalPoints = Tasks.Sum(t => t.MaxPoints);
|
||||
TotalPoints = Tasks.Where(t => !t.IsBonus && t.VariantName != "B").Sum(t => t.MaxPoints);
|
||||
OnPropertyChanged(nameof(TotalPointsWarning));
|
||||
OnPropertyChanged(nameof(TotalPointsDisplay));
|
||||
RecomputeGradingKeyAbsolutes();
|
||||
@@ -214,6 +246,9 @@ public partial class ExamDialogViewModel : ObservableObject
|
||||
foreach (var e in GradingKeyEntries)
|
||||
e.AbsolutePointsDisplay = TotalPoints <= 0
|
||||
? "–"
|
||||
: Tasks.Any(t => t.VariantName != "Beide")
|
||||
? $"A ab {e.MinPercent / 100.0 * TotalPoints:0.##} / " +
|
||||
$"B ab {e.MinPercent / 100.0 * Tasks.Where(t => !t.IsBonus && t.VariantName != "A").Sum(t => t.MaxPoints):0.##} Punkten"
|
||||
: $"ab {(e.MinPercent / 100.0 * TotalPoints).ToString("0.##", CultureInfo.InvariantCulture)} " +
|
||||
$"von {TotalPoints.ToString("0.##", CultureInfo.InvariantCulture)} Punkten";
|
||||
}
|
||||
@@ -288,6 +323,7 @@ public partial class ExamDialogViewModel : ObservableObject
|
||||
private void Save()
|
||||
{
|
||||
TitleError = ""; DateTextError = ""; ReturnedAtTextError = ""; GradingKeyValidation = "";
|
||||
RepeatError = ""; TaskPointsError = "";
|
||||
var valid = true;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Title)) { TitleError = "Titel erforderlich."; valid = false; }
|
||||
@@ -313,6 +349,17 @@ public partial class ExamDialogViewModel : ObservableObject
|
||||
var gradingKey = BuildGradingKeyEntries();
|
||||
var gradingKeyError = _grading.ValidateGradingKey(gradingKey);
|
||||
if (gradingKeyError is not null) { GradingKeyValidation = gradingKeyError; valid = false; }
|
||||
if (SelectedOriginalExam is not null && SelectedOriginalExam.Date >= date)
|
||||
{
|
||||
RepeatError = "Die erste Arbeit muss vor der Wiederholung liegen.";
|
||||
valid = false;
|
||||
}
|
||||
if (Tasks.Any(t => t.VariantName != "Beide") &&
|
||||
(TotalPoints <= 0 || Tasks.Where(t => !t.IsBonus && t.VariantName != "A").Sum(t => t.MaxPoints) <= 0))
|
||||
{
|
||||
TaskPointsError = "Fassung A und B brauchen jeweils Grundpunkte.";
|
||||
valid = false;
|
||||
}
|
||||
|
||||
if (!valid) return;
|
||||
|
||||
@@ -325,12 +372,31 @@ public partial class ExamDialogViewModel : ObservableObject
|
||||
Result.Niveau = NiveauDisplay.FromName(SelectedNiveauName);
|
||||
Result.Tasks = Tasks.Select(t => t.ToModel()).ToList();
|
||||
Result.GradingKey = gradingKey;
|
||||
Result.RepeatOfExamId = SelectedOriginalExam?.Id;
|
||||
Result.RepeatGradeRule = RepeatRuleName switch
|
||||
{
|
||||
"Wiederholung zählt" => RepeatGradeRule.Repeat,
|
||||
"Erste Arbeit zählt" => RepeatGradeRule.Original,
|
||||
_ => RepeatGradeRule.Better,
|
||||
};
|
||||
// Parallelkurse (gleiche Arbeit, mehrere Kurse): beim Duplizieren verknüpfen, damit die
|
||||
// Klausuren-Hauptseite zwischen ihnen umschalten kann. Der Anker ist die Id der zuerst
|
||||
// angelegten Klausur der Kette — schon verknüpfte Quellen geben ihren Anker weiter.
|
||||
if (_duplicateSource is not null)
|
||||
Result.SharedExamGroupId = _duplicateSource.SharedExamGroupId ?? _duplicateSource.Id;
|
||||
_exams.Save(Result);
|
||||
if (_editingExam is not null && _results is not null)
|
||||
{
|
||||
var tasks = Result.Tasks.OrderBy(t => t.Nr).ToList();
|
||||
var existingResults = _results.GetByExam(Result.Id);
|
||||
foreach (var result in existingResults.Where(r => !r.Absent))
|
||||
{
|
||||
result.TotalPoints = ExamScoringService.Achieved(tasks, result.Points, result.Variant);
|
||||
result.Grade = _grading.CalculateGrade(result.TotalPoints,
|
||||
ExamScoringService.Maximum(tasks, result.Variant), gradingKey);
|
||||
}
|
||||
_results.SaveMany(existingResults);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,6 +427,9 @@ public partial class ExamTaskEditItem : ObservableObject
|
||||
[ObservableProperty] private double _weight = 1.0;
|
||||
[ObservableProperty] private bool _isCompetencyPanelOpen;
|
||||
[ObservableProperty] private bool _showWeight;
|
||||
[ObservableProperty] private string _variantName = "Beide";
|
||||
[ObservableProperty] private bool _isBonus;
|
||||
public string[] VariantOptions => ["Beide", "A", "B"];
|
||||
|
||||
public List<CompetencyReference> Competencies { get; }
|
||||
public ObservableCollection<CompetencyTagGroup> CompetencyTagGroups { get; } = [];
|
||||
@@ -409,6 +478,8 @@ public partial class ExamTaskEditItem : ObservableObject
|
||||
[RelayCommand] private void MoveDown() => OnMoveDown?.Invoke(this);
|
||||
|
||||
partial void OnMaxPointsChanged(double value) => OnChanged?.Invoke();
|
||||
partial void OnVariantNameChanged(string value) => OnChanged?.Invoke();
|
||||
partial void OnIsBonusChanged(bool value) => OnChanged?.Invoke();
|
||||
|
||||
public ExamTask ToModel() => new()
|
||||
{
|
||||
@@ -416,6 +487,8 @@ public partial class ExamTaskEditItem : ObservableObject
|
||||
Title = string.IsNullOrWhiteSpace(Title) ? null : Title.Trim(),
|
||||
MaxPoints = MaxPoints,
|
||||
Weight = Weight,
|
||||
Variant = VariantName switch { "A" => ExamVariant.A, "B" => ExamVariant.B, _ => null },
|
||||
IsBonus = IsBonus,
|
||||
Competencies = Competencies,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user