This commit is contained in:
1 parent
cdb4637c65
commit
f0c0479bcb
22 files changed
+1099
-76
No files matched your search
@@ -72,18 +72,19 @@ public class UntisDiffService
|
||||
|
||||
if (string.Equals(evt.Status, "CANCELLED", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
substitutions.Add(mapping.Kind == SubstitutionKind.Lesson
|
||||
? BuildCancelledLesson(evt.Date, mapping, evt.Uid)
|
||||
: BuildSupervisionNote(evt.Date, mapping, evt.Uid, "Laut WebUntis abgesagt."));
|
||||
if (mapping.Kind == SubstitutionKind.Lesson)
|
||||
substitutions.AddRange(BuildCancelledLessons(evt.Date, mapping, evt.Uid));
|
||||
else
|
||||
substitutions.Add(BuildSupervisionNote(evt.Date, mapping, evt.Uid, "Laut WebUntis abgesagt."));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mapping.Kind == SubstitutionKind.Lesson)
|
||||
{
|
||||
if (DeviationReason(evt, mapping) is { } reason)
|
||||
substitutions.Add(BuildChangedLesson(evt, mapping, reason));
|
||||
substitutions.AddRange(BuildChangedLessons(evt, mapping, reason));
|
||||
else
|
||||
externalIdsToDelete.Add(evt.Uid); // war ggf. vorher fälschlich als Vertretung erkannt
|
||||
externalIdsToDelete.AddRange(ExternalIdsForPeriods(evt.Uid, mapping)); // ggf. frühere Vertretung entfernen
|
||||
}
|
||||
else if (!regularDutyKeys.Contains((mapping.Weekday, mapping.AfterPeriod!.Value)))
|
||||
{
|
||||
@@ -143,11 +144,11 @@ public class UntisDiffService
|
||||
{
|
||||
// War evtl. an einem früheren Poll (noch) als fehlend gemeldet - jetzt
|
||||
// wieder im Feed vorhanden, die alte Meldung räumt sich damit selbst ab.
|
||||
externalIdsToDelete.Add(BuildMissingExternalId(date, mapping));
|
||||
externalIdsToDelete.AddRange(ExternalIdsForPeriods(BuildMissingExternalId(date, mapping), mapping));
|
||||
continue;
|
||||
}
|
||||
|
||||
substitutions.Add(BuildCancelledLesson(date, mapping, BuildMissingExternalId(date, mapping)));
|
||||
substitutions.AddRange(BuildCancelledLessons(date, mapping, BuildMissingExternalId(date, mapping)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,19 +193,32 @@ public class UntisDiffService
|
||||
private static string RemoveWhitespace(string value) =>
|
||||
new(value.Where(c => !char.IsWhiteSpace(c)).ToArray());
|
||||
|
||||
private static SubstitutionEntry BuildCancelledLesson(DateOnly date, UntisSlotMapping mapping, string externalId) => new()
|
||||
{
|
||||
Date = date, Kind = SubstitutionKind.Cancelled, PeriodNumber = mapping.PeriodNumber,
|
||||
Description = "Automatisch über WebUntis-Abgleich erkannt.", ExternalId = externalId,
|
||||
};
|
||||
private static IEnumerable<SubstitutionEntry> BuildCancelledLessons(DateOnly date, UntisSlotMapping mapping,
|
||||
string externalId) => Periods(mapping).Select((period, index) => new SubstitutionEntry
|
||||
{
|
||||
Date = date, Kind = SubstitutionKind.Cancelled, PeriodNumber = period,
|
||||
Description = "Automatisch über WebUntis-Abgleich erkannt.",
|
||||
ExternalId = PeriodExternalId(externalId, period, index),
|
||||
});
|
||||
|
||||
private static SubstitutionEntry BuildChangedLesson(UntisIcsEvent evt, UntisSlotMapping mapping, string reason) => new()
|
||||
{
|
||||
Date = evt.Date, Kind = SubstitutionKind.Lesson, PeriodNumber = mapping.PeriodNumber,
|
||||
GroupId = mapping.GroupId, GroupLabel = mapping.ClassToken,
|
||||
Description = $"WebUntis: {evt.Summary ?? "?"} · {evt.Location} (regulär: {mapping.Summary ?? "?"}) — {reason}",
|
||||
ExternalId = evt.Uid,
|
||||
};
|
||||
private static IEnumerable<SubstitutionEntry> BuildChangedLessons(UntisIcsEvent evt, UntisSlotMapping mapping,
|
||||
string reason) => Periods(mapping).Select((period, index) => new SubstitutionEntry
|
||||
{
|
||||
Date = evt.Date, Kind = SubstitutionKind.Lesson, PeriodNumber = period,
|
||||
GroupId = mapping.GroupId, GroupLabel = mapping.ClassToken,
|
||||
Description = $"WebUntis: {evt.Summary ?? "?"} · {evt.Location} (regulär: {mapping.Summary ?? "?"}) — {reason}",
|
||||
ExternalId = PeriodExternalId(evt.Uid, period, index),
|
||||
});
|
||||
|
||||
private static List<int> Periods(UntisSlotMapping mapping) => mapping.CoveredPeriods.Count > 0
|
||||
? mapping.CoveredPeriods.Distinct().Order().ToList()
|
||||
: mapping.PeriodNumber is { } period ? [period] : [];
|
||||
|
||||
private static IEnumerable<string> ExternalIdsForPeriods(string externalId, UntisSlotMapping mapping) =>
|
||||
Periods(mapping).Select((period, index) => PeriodExternalId(externalId, period, index));
|
||||
|
||||
private static string PeriodExternalId(string externalId, int period, int index) =>
|
||||
index == 0 ? externalId : $"{externalId}-period-{period}";
|
||||
|
||||
// Aufsichten haben keinen TimetableSlot im Hintergrund (siehe SubstitutionEntry.Kind-Doc) -
|
||||
// deshalb Kind=Supervision statt Cancelled, auch wenn der Termin verschwunden ist.
|
||||
|
||||
Reference in new issue
Block a user