Esempio n. 1
0
        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);
                }
            }
        }
Esempio n. 2
0
        public static ItinerarySegmentAttributes GetItinerarySegmentAttributes(this TrainRun trainRun)
        {
            var result = new ItinerarySegmentAttributes
            {
                trainNumber  = trainRun.Zugnummer.ToString(),
                trainProduct = trainRun.Zuggattung,
            };

            return(result);
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        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);
        }