private static void StopTimeTest(IGTFSDataSource source)
        {
            IGTFSFeed feed      = new LenientGTFSFeed(source);
            var       stopTimes = feed.StopTimes;

            var tripsByRouteService = feed.Trips.GroupBy(tp => (tp.RouteID, tp.ServiceID));
            var timesByTrip         = stopTimes.GroupBy(stm => stm.TripID).ToDictionary(stm => stm.Key, stm => new { start = stm.Min(x => x.DepartureTime), end = stm.Max(x => x.ArrivalTime) });

            DurationPattern ptn = DurationPattern.CreateWithInvariantCulture("H:mm:ss");

            foreach (var group in tripsByRouteService)
            {
                var rt  = feed.Routes[group.Key.RouteID];
                var cal = feed.Calendars[group.Key.ServiceID].Item1;

                string header = $"{rt.Type} {rt.ShortName} {rt.LongName} - {DayMasks.Get(cal.Mask)}";

                Duration min = Duration.MaxValue;
                Duration max = Duration.MinValue;

                foreach (var trip in group)
                {
                    var times = timesByTrip[trip.ID];
                    min = Duration.Min(times.start.Value, min);
                    max = Duration.Max(times.end.Value, max);
                }

                string timeStr = $"{ptn.Format(min)} - {ptn.Format(max)}";

                Console.WriteLine($"{header}: {timeStr}");
            }
        }
Beispiel #2
0
        public LenientGTFSFeed(IGTFSDataSource source)
        {
            DataSource = source;

            Agencies = new IDEntityCollection <Agency>(DataSource, "agency", AgencyFactory);

            DefaultAgencyID = Agencies.First().ID;

            Routes    = new IDEntityCollection <Route>(DataSource, "routes", RouteFactory);
            Calendars = new GTFSCalendarCollection(DataSource,
                                                   new IDEntityCollection <Calendar>(DataSource, "calendar", CalendarFactory),
                                                   new TwoKeyEntityCollection <CalendarDate, string, NodaTime.LocalDate>(DataSource, "calendar_dates", CalendarDateFactory)
                                                   );
            Stops          = new IDEntityCollection <Stop>(DataSource, "stops", StopFactory);
            Trips          = new IDEntityCollection <Trip>(DataSource, "trips", TripFactory);
            StopTimes      = new GTFSOrderedEntityCollection <StopTime>(DataSource, "stop_times", StopTimeFactory);
            FareAttributes = new IDEntityCollection <FareAttribute>(DataSource, "fare_attributes", FareAttributeFactory);
            ShapePoints    = new GTFSOrderedEntityCollection <ShapePoint>(DataSource, "shapes", ShapePointFactory);
            Frequencies    = new TwoKeyEntityCollection <Frequency, string, Duration>(DataSource, "frequencies", FrequencyFactory);
            Transfers      = new TwoKeyEntityCollection <Transfer, string, string>(DataSource, "transfers", TransferFactory);
            Pathways       = new IDEntityCollection <Pathway>(DataSource, "pathways", PathwayFactory);
            Levels         = new IDEntityCollection <Level>(DataSource, "levels", LevelFactory);
            Translations   = new GTFSGenericCollection <Translation>(DataSource, "translations", TranslationFactory);
            Attributions   = new GTFSGenericCollection <Attribution>(DataSource, "attributions", AttributionFactory);
            FeedInfo       = null;

            foreach (FeedInfo info in DataSource.GetObjects("feed_info", FeedInfoFactory, new List <GTFSUnparsedEntity>()))
            {
                FeedInfo = info;
                break;
            }
        }
        public GTFSGenericCollection(IGTFSDataSource source, string tableName, GTFSEntityFactory <T> factory)
        {
            Backing  = new();
            Unparsed = new();

            foreach (T item in source.GetObjects(tableName, factory, Unparsed))
            {
                Backing.Add(item);
            }
        }
        public IDEntityCollection(IGTFSDataSource source, string tableName, GTFSEntityFactory <T> factory)
        {
            Dict     = new Dictionary <string, T>();
            Unparsed = new List <GTFSUnparsedEntity>();

            foreach (T item in source.GetObjects(tableName, factory, Unparsed))
            {
                Dict.Add(item.ID, item);
            }
        }
        public GTFSOrderedEntityCollection(IGTFSDataSource source, string tableName, GTFSEntityFactory <T> factory)
        {
            Backing = new Dictionary <string, AVLTreeDictionary <int, T> >();
            var backingGen = new DictionaryGenerator <string, AVLTreeDictionary <int, T> >(Backing,
                                                                                           new FuncGenerator <string, AVLTreeDictionary <int, T> >(x => new AVLTreeDictionary <int, T>()));

            Unparsed = new List <GTFSUnparsedEntity>();

            foreach (T item in source.GetObjects(tableName, factory, Unparsed))
            {
                backingGen[item.ID].Add(item.Index, item);
            }
        }