private IEnumerable <TrainRun> GetTrainRuns <T>(IEnumerable <Halt <T> > halte, bool preferPrognosis) where T : Zug { if (halte.AnyItem()) { var halteGroups = halte .GroupBy(h => h.ZugID).ToArray(); foreach (var halteGroup in halteGroups) { var ordered = halteGroup .OrderBy(h => h.SortierZeit).ToArray(); var positions = GetTrainPositions( halte: ordered, preferPrognosis: preferPrognosis).ToArray(); var relevant = ordered.First(); var result = new TrainRun { Abfahrt = relevant.GetAbfahrt(), Bemerkungen = relevant.Zug.Bemerkungen, Positions = positions, Zuggattung = relevant.Zug.Zuggattung.Kurzname, ZugId = relevant.ZugID, Zugnummer = relevant.Zug.Zugnummer, }; yield return(result); } } }
public static ItinerarySegmentAttributes GetItinerarySegmentAttributes(this TrainRun trainRun) { var result = new ItinerarySegmentAttributes { trainNumber = trainRun.Zugnummer.ToString(), trainProduct = trainRun.Zuggattung, }; return(result); }
private IEnumerable <TrainPathStop> GetTrainPathStops(TrainRun trainRun) { var relevants = trainRun.Positions .Where(p => !locationShortnames.AnyItem() || locationShortnames.Contains(p.Betriebsstelle)).ToArray(); var itinerarySegmentAttributes = trainRun.GetItinerarySegmentAttributes(); foreach (var relevant in relevants) { var arrivalSpecified = relevant.Ankunft.HasValue && relevant != relevants.First(); var departureSpecified = relevant.Abfahrt.HasValue && relevant != relevants.Last(); var times = new Times { operationalArrivalTime = relevant.Ankunft ?? default, operationalArrivalTimeTextSpecified = arrivalSpecified, operationalDepartureTime = relevant.Abfahrt ?? default, operationalDepartureTimeTextSpecified = departureSpecified, }; var stoppingReasons = GetStoppingReasons(relevant).ToArray(); var arrivalTrack = arrivalSpecified ? relevant.Gleis?.ToString() : default; var departureTrack = departureSpecified ? relevant.Gleis?.ToString() : default; var result = new TrainPathStop { arrivalTrack = arrivalTrack, departureTrack = departureTrack, running = !relevant.VerkehrNicht, runningSpecified = true, stoppingReasons = stoppingReasons, stopPoint = relevant.GetStopPoint(), times = times, itinerarySegmentAttributes = itinerarySegmentAttributes, }; yield return(result); } }
private TrainRun GetTrainRun(IEnumerable <TrainPathMessage> messages) { var positions = GetPositions(messages).ToArray(); var relevantMessage = messages.First(); var result = new TrainRun { Abfahrt = positions.First().Abfahrt?.TimeOfDay, Positions = positions, Zuggattung = relevantMessage.Zuggattung, ZugId = relevantMessage.ZugId, Zugnummer = relevantMessage.Zugnummer, }; return(result); }