feat: improve WebUntis sync and competency insights
CI / build-and-test (push) Canceled after 0s

This commit is contained in:
admin committed 2026-09-20 22:17:29 +02:00
1 parent cdb4637c65
commit f0c0479bcb
22 files changed
+1099 -76

No files matched your search

@@ -3,7 +3,8 @@ using LehrerApp.Core.Models;
namespace LehrerApp.Core.Services;
public sealed record CompetencyScore(
double AchievedPoints, double MaxPoints, int EvidenceCount, int ParticipantCount)
double AchievedPoints, double MaxPoints, int EvidenceCount, int ParticipantCount,
int ExamEvidenceCount = 0, int ParticipationEvidenceCount = 0)
{
public double Percent => MaxPoints <= 0 ? 0 : AchievedPoints / MaxPoints * 100.0;
}
@@ -18,6 +19,7 @@ public sealed class CompetencyAnalysisItem
public int TaughtUnitCount { get; init; }
public int PlannedExamCount { get; init; }
public int AssessedExamCount { get; init; }
public int ParticipationSessionCount { get; init; }
public CompetencyScore? GroupScore { get; init; }
public IReadOnlyDictionary<Guid, CompetencyScore> StudentScores { get; init; } =
new Dictionary<Guid, CompetencyScore>();
@@ -29,7 +31,10 @@ public sealed class CompetencyAnalysisService
IReadOnlyList<CompetencyDomain> catalog,
IReadOnlyList<Unit> units,
IReadOnlyList<Exam> exams,
IReadOnlyList<ExamResult> results)
IReadOnlyList<ExamResult> results,
IReadOnlyList<ParticipationSession>? participationSessions = null,
IReadOnlyList<ParticipationEntry>? participationEntries = null,
IReadOnlyList<ParticipationAspect>? participationAspects = null)
{
var builders = new List<ItemBuilder>();
var byId = new Dictionary<Guid, ItemBuilder>();
@@ -105,7 +110,36 @@ public sealed class CompetencyAnalysisService
if (task.MaxPoints <= 0) continue;
var achieved = Math.Clamp(result.Points[taskIndex], 0, task.MaxPoints);
foreach (var reference in NormalizeReferences(task.Competencies))
GetOrAdd(reference).AddScore(result.StudentId, achieved, task.MaxPoints);
GetOrAdd(reference).AddExamScore(result.StudentId, achieved, task.MaxPoints);
}
}
var entriesBySession = (participationEntries ?? [])
.GroupBy(x => x.SessionId)
.ToDictionary(x => x.Key, x => x.ToList());
var aspects = participationAspects ?? [];
foreach (var session in participationSessions ?? [])
{
var references = NormalizeReferences(session.Competencies).ToList();
foreach (var reference in references)
GetOrAdd(reference).ParticipationSessions++;
if (references.Count == 0 || !entriesBySession.TryGetValue(session.Id, out var entries))
continue;
foreach (var entry in entries)
{
var estimated = ParticipationCompetencyEstimate.Estimate(
entry.Ratings, aspects, entry.DayHighlight);
foreach (var reference in references)
{
var explicitRating = entry.CompetencyRatings
.FirstOrDefault(x => x.ItemId == reference.ItemId)?.Value;
var rating = explicitRating ?? estimated;
if (rating is not null)
GetOrAdd(reference).AddParticipationScore(entry.StudentId, rating.Value);
}
}
}
@@ -124,14 +158,23 @@ public sealed class CompetencyAnalysisService
public int TaughtUnits { get; set; }
public int PlannedExams { get; set; }
public int AssessedExams { get; set; }
public int ParticipationSessions { get; set; }
public void AddScore(Guid studentId, double achieved, double maximum)
public void AddExamScore(Guid studentId, double achieved, double maximum) =>
AddScore(studentId, achieved, maximum, isParticipation: false);
public void AddParticipationScore(Guid studentId, int rating) =>
AddScore(studentId, Math.Clamp(rating, -2, 2) + 2, 4, isParticipation: true);
private void AddScore(Guid studentId, double achieved, double maximum, bool isParticipation)
{
if (!_scores.TryGetValue(studentId, out var score))
_scores[studentId] = score = new MutableScore();
score.Achieved += achieved;
score.Maximum += maximum;
score.EvidenceCount++;
if (isParticipation) score.ParticipationEvidenceCount++;
else score.ExamEvidenceCount++;
}
public CompetencyAnalysisItem Build()
@@ -140,6 +183,8 @@ public sealed class CompetencyAnalysisService
var achieved = _scores.Values.Sum(x => x.Achieved);
var maximum = _scores.Values.Sum(x => x.Maximum);
var evidence = _scores.Values.Sum(x => x.EvidenceCount);
var examEvidence = _scores.Values.Sum(x => x.ExamEvidenceCount);
var participationEvidence = _scores.Values.Sum(x => x.ParticipationEvidenceCount);
return new CompetencyAnalysisItem
{
DomainName = domainName,
@@ -150,8 +195,10 @@ public sealed class CompetencyAnalysisService
TaughtUnitCount = TaughtUnits,
PlannedExamCount = PlannedExams,
AssessedExamCount = AssessedExams,
ParticipationSessionCount = ParticipationSessions,
GroupScore = maximum > 0
? new CompetencyScore(achieved, maximum, evidence, _scores.Count)
? new CompetencyScore(achieved, maximum, evidence, _scores.Count,
examEvidence, participationEvidence)
: null,
StudentScores = studentScores,
};
@@ -163,7 +210,10 @@ public sealed class CompetencyAnalysisService
public double Achieved { get; set; }
public double Maximum { get; set; }
public int EvidenceCount { get; set; }
public int ExamEvidenceCount { get; set; }
public int ParticipationEvidenceCount { get; set; }
public CompetencyScore ToScore(int participantCount) =>
new(Achieved, Maximum, EvidenceCount, participantCount);
new(Achieved, Maximum, EvidenceCount, participantCount,
ExamEvidenceCount, ParticipationEvidenceCount);
}
}