private void TryToHelpJinx() { foreach (var game in Games) { var studentLots = game.Lots.OrderBy(x => x.Priority).ToList(); // Student ist Ober-Pechvogel, wenn er gar nichts erhalten hat => zuerst 1 Kurs // gar nichts: Keinen Platz und auch kein Los auf der Warteliste // alte Formulierung // var isJinx = !game.Seats.Any() && studentLots.All(x => x.IsValid && x.Subscription.OnWaitingList); var nSeats = game.Seats.Count; var nLots = studentLots.Count; var nWaitingLots = studentLots.Count(x => x.Subscription.OnWaitingList); var validLots = studentLots.Count(x => x.IsValid); var nWaitingValidLots = studentLots.Count(x => x.IsValid && x.Subscription.OnWaitingList); AddMessage(game.UserId, $"Plätze: {nSeats}, Lose {nLots}, auf Warteliste {nWaitingLots}, valide {validLots}, valide und Warteliste {nWaitingValidLots}"); bool isJinx = nSeats == 0 && nLots == nWaitingLots; if (isJinx) { AddMessage(game.UserId, $"Bisher keinen Platz erhalten"); // Suche einen Kurs, der noch freie Plätze hat und in dem er noch nicht drin ist var availableCourses = LotPots.Where(x => !x.Course.Occurrence.Subscriptions.Any(s => s.UserId.Equals(game.UserId)) && x.SeatsAvailable > 0).OrderByDescending(x => x.SeatsAvailable).ToList(); AddMessage(null, null, $"Es sind {availableCourses.Count} LVs noch frei"); var availableCourse = availableCourses.FirstOrDefault(); if (availableCourse == null) { game.Message = "Im gesamten Wahlverfahren stehen keine freien Plätze mehr zur Verfügung."; } else { if (game.AcceptDefault) { // eine neue Eintragung var subscription = new OccurrenceSubscription(); subscription.TimeStamp = DateTime.Now; subscription.UserId = game.UserId; subscription.OnWaitingList = false; subscription.Priority = 0; subscription.Occurrence = availableCourse.Course.Occurrence; // Die Subscription hinzufügen availableCourse.Course.Occurrence.Subscriptions.Add(subscription); // Die Bookinglist aktualisieren availableCourse.BookingList.Bookings.Add(new Booking.Data.Booking { Student = game.Student, Subscription = subscription }); var lot = new DrawingLot(); lot.IsTouched = true; lot.IsValid = true; lot.AddMessage("Platz über Pechvogelregel erhaltem"); lot.Subscription = subscription; lot.Course = availableCourse.Course; game.Lots.Add(lot); availableCourse.Lots.Add(lot); AddMessage(lot.Course, lot.Subscription, "Platz über Pechvogelregel erhaltem"); /* * var lotPot = LotPots.SingleOrDefault(x => x.Course.Id == availableCourse.Course.Id); * lotPot.Lots.Add(lot); */ } else { AddMessage(game.UserId, "Will nichts anderes. Es hätte noch einen Platz in einer anderen Lehrveranstaltung gegeben."); game.Message = "Es hätte noch einen Platz in einer anderen Lehrveranstaltung gegeben."; } } } } }
private int TryToFillUp() { var nSuccess = 0; foreach (var game in Games) { var studentLots = game.Lots.OrderBy(x => x.Priority).ToList(); // Hat Student alle Wünsche erfüllt bekommen var isJinx = (studentLots.Count(x => !x.Subscription.OnWaitingList) + game.Seats.Count) < game.CoursesWanted; if (isJinx) { // Suche einen Kurs, der noch freie Plätze hat und in dem er noch nicht drin ist var availableCourse = LotPots.Where(x => !x.Course.Occurrence.Subscriptions.Any(s => s.UserId.Equals(game.UserId)) && x.SeatsAvailable > 0).OrderByDescending(x => x.SeatsAvailable).FirstOrDefault(); if (availableCourse == null) { game.Message = "Im gesamten Wahlverfahren stehen keine freien Plätze mehr zur Verfügung."; } else { if (game.AcceptDefault) { // eine neue Eintragung var subscription = new OccurrenceSubscription(); subscription.TimeStamp = DateTime.Now; subscription.UserId = game.UserId; subscription.OnWaitingList = false; subscription.Priority = 0; subscription.Occurrence = availableCourse.Course.Occurrence; // Die Subscription hinzufügen availableCourse.Course.Occurrence.Subscriptions.Add(subscription); // Die Bookinglist aktualisieren availableCourse.BookingList.Bookings.Add(new Booking.Data.Booking { Student = game.Student, Subscription = subscription }); // Ein neues Los var lot = new DrawingLot(); lot.IsTouched = true; lot.IsValid = true; lot.AddMessage("Platz durch Auffüllen erhalten"); lot.Subscription = subscription; lot.Course = availableCourse.Course; game.Lots.Add(lot); availableCourse.Lots.Add(lot); /* * var lotPot = LotPots.SingleOrDefault(x => x.Course.Id == availableCourse.Course.Id); * lotPot.Lots.Add(lot); */ AddMessage(lot.Course, lot.Subscription, "Platz durch Auffüllen erhalten"); nSuccess++; } else { AddMessage(game.UserId, "Will nichts anderes. Es hätte noch einen Platz in einer anderen Lehrveranstaltung gegeben."); game.Message = "Es hätte noch einen Platz in einer anderen Lehrveranstaltung gegeben."; } } } } return(nSuccess); }
private void TryToHelpJinx() { foreach (var game in Games) { var studentLots = game.Lots.OrderBy(x => x.Priority).ToList(); // Student ist Ober-Pechvogel, wenn er gar nichts erhalten hat => zuerst 1 Kurs // gar nichts: Keinen Platz und auch kein Los auf der Warteliste var isJinx = !game.Seats.Any() && studentLots.All(x => x.IsValid && x.Subscription.OnWaitingList); if (isJinx) { // Suche einen Kurs, der noch freie Plätze hat und in dem er noch nicht drin ist var availableCourse = LotPots.Where(x => !x.Course.Occurrence.Subscriptions.Any(s => s.UserId.Equals(game.UserId)) && x.RemainingSeats > 0).OrderByDescending(x => x.RemainingSeats).FirstOrDefault(); if (availableCourse == null) { game.Message = "Im gesamten Wahlverfahren stehen keine freien Plätze mehr zur Verfügung."; } else { if (game.AcceptDefault) { // eine neue Eintragung var subscription = new OccurrenceSubscription(); subscription.TimeStamp = DateTime.Now; subscription.UserId = game.UserId; subscription.OnWaitingList = false; subscription.Priority = 0; subscription.Occurrence = availableCourse.Course.Occurrence; // Die Subscription hinzufügen availableCourse.Course.Occurrence.Subscriptions.Add(subscription); // Die Bookinglist aktualisieren availableCourse.BookingList.Bookings.Add(new Booking.Data.Booking { Student = game.Student, Subscription = subscription }); var lot = new DrawingLot(); lot.IsTouched = true; lot.IsValid = true; lot.Message = "Mindestens mal eine Lehrveranstaltung für den Pechvogel"; lot.Subscription = subscription; lot.Course = availableCourse.Course; game.Lots.Add(lot); availableCourse.Lots.Add(lot); /* * var lotPot = LotPots.SingleOrDefault(x => x.Course.Id == availableCourse.Course.Id); * lotPot.Lots.Add(lot); */ } else { game.Message = "Es hätte noch einen Platz in einer anderen Lehrveranstaltung gegeben."; } } } } }