37 lines
1.4 KiB
C#
37 lines
1.4 KiB
C#
using LehrerApp.Core.Models;
|
|
|
|
namespace LehrerApp.Core.Services;
|
|
|
|
/// <summary>
|
|
/// Leitet aus den allgemeinen Mitarbeitsaspekten einen Kompetenzwert auf der gemeinsamen
|
|
/// Skala von -2 bis +2 ab. Explizite Kompetenzbewertungen werden vom Aufrufer bevorzugt.
|
|
/// </summary>
|
|
public static class ParticipationCompetencyEstimate
|
|
{
|
|
public static int? Estimate(IEnumerable<AspectRating> ratings,
|
|
IReadOnlyCollection<ParticipationAspect> aspects, DayHighlightKind? dayHighlight)
|
|
{
|
|
var aspectsByKey = aspects
|
|
.GroupBy(x => x.Key, StringComparer.OrdinalIgnoreCase)
|
|
.ToDictionary(x => x.Key, x => x.Last(), StringComparer.OrdinalIgnoreCase);
|
|
var normalized = ratings
|
|
.Where(x => aspectsByKey.ContainsKey(x.Key))
|
|
.Select(x =>
|
|
{
|
|
var aspect = aspectsByKey[x.Key];
|
|
return ParticipationRatingScale.Normalize(aspect.ValueType, x.Value, aspect.MaxPoints);
|
|
})
|
|
.ToList();
|
|
if (normalized.Count == 0) return null;
|
|
|
|
var adjustment = dayHighlight switch
|
|
{
|
|
DayHighlightKind.Standout => 1.0,
|
|
DayHighlightKind.Sleepy or DayHighlightKind.Rough => -1.0,
|
|
_ => 0.0,
|
|
};
|
|
return Math.Clamp((int)Math.Round(normalized.Average() + adjustment,
|
|
MidpointRounding.AwayFromZero), -2, 2);
|
|
}
|
|
}
|