private static void RunExample() { // create the reader. var reader = new GTFSReader<GTFSFeed>(strict:false); // execute the reader. GTFSFeed feed = reader.Read(new GTFSDirectorySource(new DirectoryInfo("feeds/lirr"))); Console.WriteLine(feed); feed = reader.Read(new GTFSDirectorySource(new DirectoryInfo("feeds/subway"))); Console.WriteLine(feed); Console.Read(); }
public void ParseCalendarDates() { // create the reader. var reader = new GTFSReader <GTFSFeed>(); reader.DateTimeReader = (dateString) => { var year = int.Parse(dateString.Substring(0, 4)); var month = int.Parse(dateString.Substring(4, 2)); var day = int.Parse(dateString.Substring(6, 2)); return(new System.DateTime(year, month, day)); }; // build the source var source = this.BuildSource(); // execute the reader. var feed = reader.Read(source, source.First(x => x.Name.Equals("calendar_dates"))); // test result. Assert.IsNotNull(feed.CalendarDates); var calendarDates = new List <CalendarDate>(feed.CalendarDates); // @ 1: service_id,date,exception_type // @ 2: FULLW,20070604,2 int idx = 0; Assert.AreEqual("FULLW", calendarDates[idx].ServiceId); Assert.AreEqual(new System.DateTime(2007, 06, 04), calendarDates[idx].Date); Assert.AreEqual(ExceptionType.Removed, calendarDates[idx].ExceptionType); }
public void TestTripAB1() { // create the reader. var reader = new GTFSReader<GTFSFeed>(); var source = GTFSAssert.BuildSource(); // execute the reader. var feed = reader.Read(source); // find stops. var finder = new StopAtShapesFinder(); var stopAtShapes = finder.Find(feed, "AB1"); // validate/test. Assert.IsNotNull(stopAtShapes); Assert.AreEqual(2, stopAtShapes.Count); Assert.AreEqual("BEATTY_AIRPORT", stopAtShapes[0].StopId); Assert.AreEqual(1, stopAtShapes[0].ShapePointSequence); Assert.AreEqual(0, stopAtShapes[0].StopOffset); Assert.AreEqual("AB1", stopAtShapes[0].TripId); Assert.AreEqual("BULLFROG", stopAtShapes[1].StopId); Assert.AreEqual(4, stopAtShapes[1].ShapePointSequence); Assert.AreEqual(0, stopAtShapes[1].StopOffset); Assert.AreEqual("AB1", stopAtShapes[1].TripId); }
public void ParseShapes() { // create the reader. GTFSReader <GTFSFeed> reader = new GTFSReader <GTFSFeed>(); // build the source var source = this.BuildSource(); // execute the reader. var feed = reader.Read(source, source.First(x => x.Name.Equals("shapes"))); // test result. Assert.IsNotNull(feed.Shapes); var shapes = feed.Shapes.ToList(); Assert.AreEqual(44, shapes.Count); // @ 1: shape_id,shape_pt_lat,shape_pt_lon,shape_pt_sequence,shape_dist_traveled // @ 2: shape_1,37.754211,-122.197868,1, int idx = 0; Assert.AreEqual("shape_1", shapes[idx].Id); Assert.AreEqual(37.754211, shapes[idx].Latitude); Assert.AreEqual(-122.197868, shapes[idx].Longitude); Assert.AreEqual(1, shapes[idx].Sequence); Assert.AreEqual(null, shapes[idx].DistanceTravelled); // @ 10: shape_3,37.73645,-122.19706,1, idx = 8; Assert.AreEqual("shape_3", shapes[idx].Id); Assert.AreEqual(37.73645, shapes[idx].Latitude); Assert.AreEqual(-122.19706, shapes[idx].Longitude); Assert.AreEqual(1, shapes[idx].Sequence); Assert.AreEqual(null, shapes[idx].DistanceTravelled); }
public void TestTripAB1() { // create the reader. var reader = new GTFSReader <GTFSFeed>(); var source = GTFSAssert.BuildSource(); // execute the reader. var feed = reader.Read(source); // find stops. var finder = new StopAtShapesFinder(); var stopAtShapes = finder.Find(feed, "AB1"); // validate/test. Assert.IsNotNull(stopAtShapes); Assert.AreEqual(2, stopAtShapes.Count); Assert.AreEqual("BEATTY_AIRPORT", stopAtShapes[0].StopId); Assert.AreEqual(1, stopAtShapes[0].ShapePointSequence); Assert.AreEqual(0, stopAtShapes[0].StopOffset); Assert.AreEqual("AB1", stopAtShapes[0].TripId); Assert.AreEqual("BULLFROG", stopAtShapes[1].StopId); Assert.AreEqual(4, stopAtShapes[1].ShapePointSequence); Assert.AreEqual(0, stopAtShapes[1].StopOffset); Assert.AreEqual("AB1", stopAtShapes[1].TripId); }
public void ParseCalendarDates() { // create the reader. GTFSReader <GTFSFeed> reader = new GTFSReader <GTFSFeed>(); // build the source var source = this.BuildSource(); // execute the reader. var feed = reader.Read(source, source.First(x => x.Name.Equals("calendar_dates"))); // test result. Assert.IsNotNull(feed.CalendarDates); var calendarDates = new List <CalendarDate>(feed.CalendarDates); Assert.AreEqual(1, calendarDates.Count); // @ 1: service_id,date,exception_type // @ 2: FULLW,20070604,2 int idx = 0; Assert.AreEqual("FULLW", calendarDates[idx].ServiceId); Assert.AreEqual(new System.DateTime(2007, 06, 04), calendarDates[idx].Date); Assert.AreEqual(ExceptionType.Removed, calendarDates[idx].ExceptionType); }
/// <summary> /// Loads a GTFS data set. /// </summary> /// <param name="path">The path of the directory containing the feed or the path to the zip file.</param> public static GTFSStorage Load(string path) { GTFSReader <GTFSFeed> reader = new GTFSReader <GTFSFeed>(); GTFSFeed feed = reader.Read(path); return(new GTFSStorage(feed)); }
/// <summary> /// Parses this command into a processor given the arguments for this switch. Consumes the previous processors and returns how many it consumes. /// </summary> public override int Parse(List <Processor> previous, out Processor processor) { if (this.Arguments.Length != 1) { throw new ArgumentException("Exactly one argument is expected."); } var directory = new DirectoryInfo(this.Arguments[0]); if (!directory.Exists) { throw new FileNotFoundException("Directory not found.", directory.FullName); } // create the reader. var reader = new GTFSReader <GTFSFeed>(false); // build the get GTFS function. Func <global::GTFS.GTFSFeed> getGTFS = () => { return(reader.Read(new GTFSDirectorySource(directory))); }; processor = new IDP.Processors.GTFS.ProcessorGTFSSource(getGTFS); return(0); }
public void TestSerializeDeserialize() { var transitDb = new TransitDb(); var reader = new GTFSReader <GTFSFeed>(); var feed = reader.Read(GTFS.sample_feed.SampleFeed.BuildSource()); transitDb.LoadFrom(feed); Assert.AreEqual(13, transitDb.TripsCount); Assert.AreEqual(9, transitDb.StopsCount); Assert.AreEqual(22, transitDb.ConnectionsCount); using (var stream = new MemoryStream()) { var size = transitDb.Serialize(stream); stream.Seek(0, SeekOrigin.Begin); transitDb = TransitDb.Deserialize(stream); Assert.AreEqual(13, transitDb.TripsCount); Assert.AreEqual(9, transitDb.StopsCount); Assert.AreEqual(22, transitDb.ConnectionsCount); } }
public void NotDisposingDirectorySourceKeepsSourceFilesOpen() { var directoryInfo = new DirectoryInfo(Path.Combine(AssemblyLocation.FullName, "folder-feed")); try { var gtfsDirectorySource = new GTFSDirectorySource(directoryInfo); var reader = new GTFSReader <GTFSFeed>(); reader.Read(gtfsDirectorySource); } catch (GTFSExceptionBase) { // ignore our exceptions } var agencyFile = Path.Combine(directoryInfo.FullName, "agency.txt"); Assert.Throws <IOException>( () => { using (File.OpenWrite(agencyFile)) { // do nothing } }, "The process cannot access the file '{0}' because it is being used by another process.", agencyFile); }
/// <summary> /// Returns the feed produced by this reader. /// </summary> /// <returns></returns> public override IGTFSFeed GetFeed() { // create the reader. var reader = new GTFSReader <GTFSFeed>(false); // execute the reader. return(reader.Read(new GTFSDirectorySource(new DirectoryInfo(_path)))); }
private static void TestGtfs() { // create the reader. var reader = new GTFSReader <GTFSFeed>(strict: false); // execute the reader. var feed = reader.Read(new GTFSDirectorySource(new DirectoryInfo(Paths.GOOD_FEED_PATH))); }
private static void TestGtfs() { // create the reader. var reader = new GTFSReader<GTFSFeed>(strict: false); // execute the reader. var feed = reader.Read(new GTFSDirectorySource(new DirectoryInfo(Paths.GOOD_FEED_PATH))); }
/// <summary> /// Reads a fead from the given directory. /// </summary> public static GTFSFeed Read(this GTFSReader <GTFSFeed> reader, DirectoryInfo directory) { var feed = new GTFSFeed(); using (var source = new GTFSDirectorySource(directory)) { return(reader.Read(feed, source)); } }
public void ParseStopTimes() { // create the reader. GTFSReader <GTFSFeed> reader = new GTFSReader <GTFSFeed>(false); // build the source var source = this.BuildSource(); // execute the reader. var feed = reader.Read(source, source.First(x => x.Name.Equals("stop_times"))); // test result. Assert.IsNotNull(feed.StopTimes); var stopTimes = feed.StopTimes.ToList(); Assert.AreEqual(28, stopTimes.Count); // @ 1: trip_id,arrival_time,departure_time,stop_id,stop_sequence,stop_headsign,pickup_type,drop_off_time,shape_dist_traveled // @ SORTED: AAMV1,8:00:00,8:00:00,BEATTY_AIRPORT,1 int idx = 0; Assert.AreEqual("AAMV1", stopTimes[idx].TripId); Assert.AreEqual(new TimeOfDay() { Hours = 8 }, stopTimes[idx].ArrivalTime); Assert.AreEqual(new TimeOfDay() { Hours = 8 }, stopTimes[idx].DepartureTime); Assert.AreEqual("BEATTY_AIRPORT", stopTimes[idx].StopId); Assert.AreEqual(1, stopTimes[idx].StopSequence); Assert.AreEqual(null, stopTimes[idx].StopHeadsign); Assert.AreEqual(null, stopTimes[idx].PickupType); Assert.AreEqual(null, stopTimes[idx].DropOffType); Assert.AreEqual(null, stopTimes[idx].ShapeDistTravelled); // @ SORTED: STBA,6:20:00,6:20:00,BEATTY_AIRPORT,2,,,, idx = 27; Assert.AreEqual("STBA", stopTimes[idx].TripId); Assert.AreEqual(new TimeOfDay() { Hours = 6, Minutes = 20 }, stopTimes[idx].ArrivalTime); Assert.AreEqual(new TimeOfDay() { Hours = 6, Minutes = 20 }, stopTimes[idx].DepartureTime); Assert.AreEqual("BEATTY_AIRPORT", stopTimes[idx].StopId); Assert.AreEqual(2, stopTimes[idx].StopSequence); Assert.AreEqual(string.Empty, stopTimes[idx].StopHeadsign); Assert.AreEqual(null, stopTimes[idx].PickupType); Assert.AreEqual(null, stopTimes[idx].DropOffType); Assert.AreEqual(string.Empty, stopTimes[idx].ShapeDistTravelled); }
/// <summary> /// Builds a test feed. /// </summary> /// <returns></returns> protected virtual IGTFSFeed BuildTestFeed() { // create the reader. var reader = new GTFSReader <GTFSFeed>(); // build the source var source = this.BuildSource(); // execute the reader. return(reader.Read(source)); }
public void TestValidFeed() { // create the reader. var reader = new GTFSReader <GTFSFeed>(); var source = GTFSAssert.BuildSource(); // execute the reader. var feed = reader.Read(source); // validate. Assert.IsTrue(GTFSFeedValidation.Validate(feed)); }
public void ParseCalendars() { // create the reader. var reader = new GTFSReader <GTFSFeed>(); reader.DateTimeReader = (dateString) => { var year = int.Parse(dateString.Substring(0, 4)); var month = int.Parse(dateString.Substring(4, 2)); var day = int.Parse(dateString.Substring(6, 2)); return(new System.DateTime(year, month, day)); }; // build the source var source = this.BuildSource(); // execute the reader. var feed = reader.Read(source, source.First(x => x.Name.Equals("calendar"))); // test result. Assert.IsNotNull(feed.Calendars); var calendars = feed.Calendars.ToList(); Assert.AreEqual(2, calendars.Count); // @ 1: service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date // @ 2: FULLW,1,1,1,1,1,1,1,20070101,20101231 int idx = 0; Assert.AreEqual("FULLW", calendars[idx].ServiceId); Assert.AreEqual(true, calendars[idx].Monday); Assert.AreEqual(true, calendars[idx].Tuesday); Assert.AreEqual(true, calendars[idx].Wednesday); Assert.AreEqual(true, calendars[idx].Thursday); Assert.AreEqual(true, calendars[idx].Friday); Assert.AreEqual(true, calendars[idx].Saturday); Assert.AreEqual(true, calendars[idx].Sunday); Assert.AreEqual(new DateTime(2007, 01, 01), calendars[idx].StartDate); Assert.AreEqual(new DateTime(2010, 12, 31), calendars[idx].EndDate); // @3: WE,0,0,0,0,0,1,1,20070101,20101231 idx = 1; Assert.AreEqual("WE", calendars[idx].ServiceId); Assert.AreEqual(false, calendars[idx].Monday); Assert.AreEqual(false, calendars[idx].Tuesday); Assert.AreEqual(false, calendars[idx].Wednesday); Assert.AreEqual(false, calendars[idx].Thursday); Assert.AreEqual(false, calendars[idx].Friday); Assert.AreEqual(true, calendars[idx].Saturday); Assert.AreEqual(true, calendars[idx].Sunday); Assert.AreEqual(new DateTime(2007, 01, 01), calendars[idx].StartDate); Assert.AreEqual(new DateTime(2010, 12, 31), calendars[idx].EndDate); }
public void TestLoadFromSampleFeed() { var transitDb = new TransitDb(); var reader = new GTFSReader <GTFSFeed>(); var feed = reader.Read(sample_feed.SampleFeed.BuildSource()); transitDb.LoadFrom(feed); Assert.AreEqual(13, transitDb.TripsCount); Assert.AreEqual(9, transitDb.StopsCount); Assert.AreEqual(22, transitDb.ConnectionsCount); }
public void ParseFareRules() { // create the reader. GTFSReader <GTFSFeed> reader = new GTFSReader <GTFSFeed>(); // build the source var source = this.BuildSource(); // execute the reader. var feed = reader.Read(source, source.First(x => x.Name.Equals("fare_rules"))); // test result. Assert.IsNotNull(feed.FareRules); var fareRules = feed.FareRules.ToList(); Assert.AreEqual(4, fareRules.Count); // fare_id,route_id,origin_id,destination_id,contains_id //p,AB,,, int idx = 0; Assert.AreEqual("AB", fareRules[idx].RouteId); Assert.AreEqual("p", fareRules[idx].FareId); Assert.AreEqual(string.Empty, fareRules[idx].OriginId); Assert.AreEqual(string.Empty, fareRules[idx].DestinationId); Assert.AreEqual(string.Empty, fareRules[idx].ContainsId); //p,STBA,,, idx = 1; Assert.AreEqual("STBA", fareRules[idx].RouteId); Assert.AreEqual("p", fareRules[idx].FareId); Assert.AreEqual(string.Empty, fareRules[idx].OriginId); Assert.AreEqual(string.Empty, fareRules[idx].DestinationId); Assert.AreEqual(string.Empty, fareRules[idx].ContainsId); //p,BFC,,, idx = 2; Assert.AreEqual("BFC", fareRules[idx].RouteId); Assert.AreEqual("p", fareRules[idx].FareId); Assert.AreEqual(string.Empty, fareRules[idx].OriginId); Assert.AreEqual(string.Empty, fareRules[idx].DestinationId); Assert.AreEqual(string.Empty, fareRules[idx].ContainsId); //a,AAMV,,, idx = 3; Assert.AreEqual("AAMV", fareRules[idx].RouteId); Assert.AreEqual("a", fareRules[idx].FareId); Assert.AreEqual(string.Empty, fareRules[idx].OriginId); Assert.AreEqual(string.Empty, fareRules[idx].DestinationId); Assert.AreEqual(string.Empty, fareRules[idx].ContainsId); }
// public static bool PrintStopLists = true; // this one doesn't do anything atm static void Main(string[] args) { var reader = new GTFSReader <GTFSFeed>(); GTFSFeed feed = reader.Read("gtfs/" + GTFSFilename); TimepointStrategy strat = TimepointFinder.GetTimepointStrategy(feed); var dateRange = CalendarTester.GetFeedDateRange(feed); var allUsedServices = from trips in feed.Trips group trips by trips.ServiceId into narrowTrips let servId = narrowTrips.First().ServiceId select new { Key = servId, Value = CalendarTester.GetDescription(feed, servId, dateRange) }; Dictionary <string, string> serviceDescriptions = allUsedServices.ToDictionary(x => x.Key, x => x.Value); foreach (Route route in feed.Routes) { // What direction(s) does the route run? IEnumerable <DirectionType?> dirs = from trips in feed.Trips where trips.RouteId == route.Id group trips by trips.Direction into narrowTrips select narrowTrips.First().Direction; // What service(s) does the route run on? IEnumerable <string> services = from trips in feed.Trips where trips.RouteId == route.Id group trips by trips.ServiceId into narrowTrips select narrowTrips.First().ServiceId; if (PrintSchedules) { using StreamWriter output = new StreamWriter($"output/schedules/{route.Id}.md"); output.WriteLine("# " + (route.ShortName ?? "") + ((route.ShortName != null && route.LongName != null) ? " - " : "") + (route.LongName ?? "")); foreach (DirectionType?dir in dirs) { output.WriteLine("## " + dir switch { DirectionType.OneDirection => "Main Direction", DirectionType.OppositeDirection => "Opposite Direction", _ => "No Direction" });
public void ParseFeedWithStopTimesFileMissing() { var reader = new GTFSReader <GTFSFeed>(); var source = new List <IGTFSSourceFile> { new GTFSSourceFileStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("GTFS.Test.sample_feed.agency.txt"), "agency"), new GTFSSourceFileStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("GTFS.Test.sample_feed.stops.txt"), "stops"), new GTFSSourceFileStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("GTFS.Test.sample_feed.routes.txt"), "routes"), new GTFSSourceFileStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("GTFS.Test.sample_feed.trips.txt"), "trips"), new GTFSSourceFileStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("GTFS.Test.sample_feed.calendar.txt"), "calendar") }; Assert.Throws <GTFSRequiredFileMissingException>(() => { reader.Read(source); }, GTFSRequiredFileMissingException.MessageFormat, "stop_times"); }
/// <summary> /// Tests building a transitdb. /// </summary> public static Func <TransitDb> GetTestBuildTransitDb(string gtfsFolder) { var reader = new GTFSReader <GTFSFeed>(false); return(() => { var feed = reader.Read(new GTFSDirectorySource(gtfsFolder)); var transitDb = new TransitDb(); transitDb.LoadFrom(feed); transitDb.SortConnections(DefaultSorting.DepartureTime, null); transitDb.SortStops(); return transitDb; }); }
public void TestMissingAgency() { // create the reader. var reader = new GTFSReader <GTFSFeed>(); var source = GTFSAssert.BuildSource(); // execute the reader. var feed = reader.Read(source); // remove. feed.Agencies.Remove("DTA"); // validate. Assert.IsFalse(GTFSFeedValidation.Validate(feed)); }
public void TestMissingStopTime() { // create the reader. var reader = new GTFSReader <GTFSFeed>(); var source = GTFSAssert.BuildSource(); // execute the reader. var feed = reader.Read(source); // remove. (feed.StopTimes.Get() as List <StopTime>)[2].StopSequence = 1024; // validate. Assert.IsFalse(GTFSFeedValidation.Validate(feed)); }
public void TestMissingRoute() { // create the reader. var reader = new GTFSReader<GTFSFeed>(); var source = GTFSAssert.BuildSource(); // execute the reader. var feed = reader.Read(source); // remove. feed.Routes.Remove("AB"); // validate. Assert.IsFalse(GTFSFeedValidation.Validate(feed)); }
public void TestNullAgency() { // create the reader. var reader = new GTFSReader <GTFSFeed>(); var source = GTFSAssert.BuildSource(); // execute the reader. var feed = reader.Read(source); // remove agency link. Assert.IsTrue(feed.Routes.Any()); feed.Routes.First().AgencyId = null; // validate. Assert.IsTrue(GTFSFeedValidation.Validate(feed)); }
public void ParseAgenciesWithoutAgencyId() { const string Agency = "agency"; var reader = new GTFSReader <GTFSFeed>(); var source = new List <IGTFSSourceFile> { new GTFSSourceFileStream(_executingAssembly.GetManifestResourceStream("GTFS.Test.other_feed.agencies_no_id.txt"), Agency) }; Assert.Throws <GTFSRequiredFieldMissingException>(() => { reader.Read(source, source.First(x => x.Name.Equals(Agency))); }, GTFSRequiredFieldMissingException.MessageFormat, "agency_id", Agency); }
public void ParseFeedWithCalendarReplacedByCalendarDatesFile() { var reader = new GTFSReader <GTFSFeed>(); var source = new List <IGTFSSourceFile> { new GTFSSourceFileStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("GTFS.Test.sample_feed.agency.txt"), "agency"), new GTFSSourceFileStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("GTFS.Test.sample_feed.stops.txt"), "stops"), new GTFSSourceFileStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("GTFS.Test.sample_feed.routes.txt"), "routes"), new GTFSSourceFileStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("GTFS.Test.sample_feed.trips.txt"), "trips"), new GTFSSourceFileStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("GTFS.Test.sample_feed.stop_times.txt"), "stop_times"), new GTFSSourceFileStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("GTFS.Test.sample_feed.calendar_dates.txt"), "calendar_dates") }; var feed = reader.Read(source); Assert.IsNotNull(feed); }
public void ParseAgenciesWithAgencyId() { var reader = new GTFSReader <GTFSFeed>(); var source = new List <IGTFSSourceFile> { new GTFSSourceFileStream(_executingAssembly.GetManifestResourceStream("GTFS.Test.other_feed.agencies_with_id.txt"), "agency") }; var feed = reader.Read(source, source.First(x => x.Name.Equals("agency"))); var agencies = feed.Agencies; Assert.IsNotNull(agencies); Assert.IsNotNull(agencies.SingleOrDefault(x => x.Id == "DTA")); Assert.IsNotNull(agencies.SingleOrDefault(x => x.Id == "OTA")); }
public void TestUnknownAgency() { // create the reader. var reader = new GTFSReader <GTFSFeed>(); var source = GTFSAssert.BuildSource(); // execute the reader. var feed = reader.Read(source); // change to an unknown agency. const string UnknownAgency = "unknown agency"; Assert.IsTrue(feed.Agencies.All(x => x.Id != UnknownAgency)); Assert.IsTrue(feed.Routes.Any()); feed.Routes.First().AgencyId = UnknownAgency; // validate. Assert.IsFalse(GTFSFeedValidation.Validate(feed)); }
public void TestFilterNoStops() { // create the reader. var reader = new GTFSReader<GTFSFeed>(); var source = GTFSAssert.BuildSource(); // execute the reader. var feed = reader.Read(source); // create the filter. var filter = new GTFSFeedStopsFilter((x) => { return true; }); // execute filter. var filtered = filter.Filter(feed); Assert.IsTrue(GTFSFeedValidation.Validate(filtered)); GTFSAssert.AreEqual(feed, filtered); }
public void ParseTransfers() { // create the reader. var reader = new GTFSReader <GTFSFeed>(); // build the source var source = this.BuildSource(); // execute the reader. var feed = reader.Read(source, source.First(x => x.Name.Equals("transfers"))); // test result. Assert.IsNotNull(feed.Transfers); var tranfers = feed.Transfers.ToList(); Assert.AreEqual(3, tranfers.Count); //from_stop_id,to_stop_id,transfer_type,min_transfer_time //BULLFROG,STAGECOACH,2,300 int idx = 0; Assert.AreEqual("BULLFROG", tranfers[idx].FromStopId); Assert.AreEqual("STAGECOACH", tranfers[idx].ToStopId); Assert.AreEqual(TransferType.MinimumTime, tranfers[idx].TransferType); Assert.AreEqual("300", tranfers[idx].MinimumTransferTime); //BULLFROG,BEATTY_AIRPORT,3, idx = 1; Assert.AreEqual("BULLFROG", tranfers[idx].FromStopId); Assert.AreEqual("BEATTY_AIRPORT", tranfers[idx].ToStopId); Assert.AreEqual(TransferType.NotPossible, tranfers[idx].TransferType); Assert.AreEqual(string.Empty, tranfers[idx].MinimumTransferTime); //EMSI,AMV,1, idx = 2; Assert.AreEqual("EMSI", tranfers[idx].FromStopId); Assert.AreEqual("AMV", tranfers[idx].ToStopId); Assert.AreEqual(TransferType.TimedTransfer, tranfers[idx].TransferType); Assert.AreEqual(string.Empty, tranfers[idx].MinimumTransferTime); }
public void TestFilterNoStops() { // create the reader. var reader = new GTFSReader <GTFSFeed>(); var source = GTFSAssert.BuildSource(); // execute the reader. var feed = reader.Read(source); // create the filter. var filter = new GTFSFeedStopsFilter((x) => { return(true); }); // execute filter. var filtered = filter.Filter(feed); Assert.IsTrue(GTFSFeedValidation.Validate(filtered)); GTFSAssert.AreEqual(feed, filtered); }
public void ParseTrips() { // create the reader. GTFSReader <GTFSFeed> reader = new GTFSReader <GTFSFeed>(false); // build the source var source = this.BuildSource(); // execute the reader. var feed = reader.Read(source, source.First(x => x.Name.Equals("trips"))); // test result. Assert.IsNotNull(feed.Trips); var trips = feed.Trips.ToList(); Assert.AreEqual(11, trips.Count); // @ 1: route_id,service_id,trip_id,trip_headsign,direction_id,block_id,shape_id // @ 2: AB,FULLW,AB1,to Bullfrog,0,1,shape_1 int idx = 0; Assert.AreEqual("AB", trips[idx].RouteId); Assert.AreEqual("FULLW", trips[idx].ServiceId); Assert.AreEqual("AB1", trips[idx].Id); Assert.AreEqual("to Bullfrog", trips[idx].Headsign); Assert.AreEqual(DirectionType.OneDirection, trips[idx].Direction); Assert.AreEqual("1", trips[idx].BlockId); Assert.AreEqual("shape_1", trips[idx].ShapeId); // @ 10: BFC,FULLW,BFC1,to Furnace Creek Resort,0,1,shape_6 idx = 5; Assert.AreEqual("BFC", trips[idx].RouteId); Assert.AreEqual("FULLW", trips[idx].ServiceId); Assert.AreEqual("BFC1", trips[idx].Id); Assert.AreEqual("to Furnace Creek Resort", trips[idx].Headsign); Assert.AreEqual(DirectionType.OneDirection, trips[idx].Direction); Assert.AreEqual("1", trips[idx].BlockId); Assert.AreEqual("shape_6", trips[idx].ShapeId); }
public void ParseCalendarDates() { // create the reader. GTFSReader<GTFSFeed> reader = new GTFSReader<GTFSFeed>(); // build the source var source = this.BuildSource(); // execute the reader. var feed = reader.Read(source, source.First(x => x.Name.Equals("calendar_dates"))); // test result. Assert.IsNotNull(feed.CalendarDates); var calendarDates = new List<CalendarDate>(feed.CalendarDates); Assert.AreEqual(1, calendarDates.Count); // @ 1: service_id,date,exception_type // @ 2: FULLW,20070604,2 int idx = 0; Assert.AreEqual("FULLW", calendarDates[idx].ServiceId); Assert.AreEqual(new System.DateTime(2007, 06, 04), calendarDates[idx].Date); Assert.AreEqual(ExceptionType.Removed, calendarDates[idx].ExceptionType); }
public void ParseAgencies() { // create the reader. GTFSReader<GTFSFeed> reader = new GTFSReader<GTFSFeed>(); // build the source var source = this.BuildSource(); // execute the reader. var feed = reader.Read(source, source.First(x => x.Name.Equals("agency"))); // test result. Assert.IsNotNull(feed.Agencies); var agencies = new List<Agency>(feed.Agencies); Assert.AreEqual(1, agencies.Count); Assert.AreEqual(null, agencies[0].FareURL); Assert.AreEqual("DTA", agencies[0].Id); Assert.AreEqual(null, agencies[0].LanguageCode); Assert.AreEqual("Demo Transit Authority", agencies[0].Name); Assert.AreEqual(null, agencies[0].Phone); Assert.AreEqual("America/Los_Angeles", agencies[0].Timezone); Assert.AreEqual("http://google.com", agencies[0].URL); }
public void ParseFrequencies() { // create the reader. GTFSReader<GTFSFeed> reader = new GTFSReader<GTFSFeed>(false); // build the source var source = this.BuildSource(); // execute the reader. var feed = reader.Read(source, source.First(x => x.Name.Equals("frequencies"))); // test result. Assert.IsNotNull(feed.Frequencies); var frequencies = feed.Frequencies.ToList(); Assert.AreEqual(11, frequencies.Count); // @ 1: trip_id,start_time,end_time,headway_secs // @ 2: STBA,6:00:00,22:00:00,1800 // @ 1: route_id,service_id,trip_id,trip_headsign,direction_id,block_id,shape_id // @ 2: AB,FULLW,AB1,to Bullfrog,0,1,shape_1 int idx = 0; Assert.AreEqual("STBA", frequencies[idx].TripId); Assert.AreEqual("6:00:00", frequencies[idx].StartTime); Assert.AreEqual("22:00:00", frequencies[idx].EndTime); Assert.AreEqual("1800", frequencies[idx].HeadwaySecs); Assert.AreEqual(null, frequencies[idx].ExactTimes); // @ 10: CITY2,16:00:00,18:59:59,600 idx = 8; Assert.AreEqual("CITY2", frequencies[idx].TripId); Assert.AreEqual("16:00:00", frequencies[idx].StartTime); Assert.AreEqual("18:59:59", frequencies[idx].EndTime); Assert.AreEqual("600", frequencies[idx].HeadwaySecs); Assert.AreEqual(null, frequencies[idx].ExactTimes); }
public void ParseFareRules() { // create the reader. GTFSReader<GTFSFeed> reader = new GTFSReader<GTFSFeed>(); // build the source var source = this.BuildSource(); // execute the reader. var feed = reader.Read(source, source.First(x => x.Name.Equals("fare_rules"))); // test result. Assert.IsNotNull(feed.FareRules); var fareRules = feed.FareRules.ToList(); Assert.AreEqual(4, fareRules.Count); // fare_id,route_id,origin_id,destination_id,contains_id //p,AB,,, int idx = 0; Assert.AreEqual("AB", fareRules[idx].RouteId); Assert.AreEqual("p", fareRules[idx].FareId); Assert.AreEqual(string.Empty, fareRules[idx].OriginId); Assert.AreEqual(string.Empty, fareRules[idx].DestinationId); Assert.AreEqual(string.Empty, fareRules[idx].ContainsId); //p,STBA,,, idx = 1; Assert.AreEqual("STBA", fareRules[idx].RouteId); Assert.AreEqual("p", fareRules[idx].FareId); Assert.AreEqual(string.Empty, fareRules[idx].OriginId); Assert.AreEqual(string.Empty, fareRules[idx].DestinationId); Assert.AreEqual(string.Empty, fareRules[idx].ContainsId); //p,BFC,,, idx = 2; Assert.AreEqual("BFC", fareRules[idx].RouteId); Assert.AreEqual("p", fareRules[idx].FareId); Assert.AreEqual(string.Empty, fareRules[idx].OriginId); Assert.AreEqual(string.Empty, fareRules[idx].DestinationId); Assert.AreEqual(string.Empty, fareRules[idx].ContainsId); //a,AAMV,,, idx = 3; Assert.AreEqual("AAMV", fareRules[idx].RouteId); Assert.AreEqual("a", fareRules[idx].FareId); Assert.AreEqual(string.Empty, fareRules[idx].OriginId); Assert.AreEqual(string.Empty, fareRules[idx].DestinationId); Assert.AreEqual(string.Empty, fareRules[idx].ContainsId); }
public void ParseFareAttributes() { // create the reader. GTFSReader<GTFSFeed> reader = new GTFSReader<GTFSFeed>(); // build the source var source = this.BuildSource(); // execute the reader. var feed = reader.Read(source, source.First(x => x.Name.Equals("fare_attributes"))); // test result. Assert.IsNotNull(feed.FareAttributes); var fareAttributes = feed.FareAttributes.ToList(); Assert.AreEqual(2, fareAttributes.Count); //fare_id,price,currency_type,payment_method,transfers,transfer_duration //p,1.25,USD,0,0, int idx = 0; Assert.AreEqual("p", fareAttributes[idx].FareId); Assert.AreEqual("1.25", fareAttributes[idx].Price); Assert.AreEqual("USD", fareAttributes[idx].CurrencyType); Assert.AreEqual(PaymentMethodType.OnBoard, fareAttributes[idx].PaymentMethod); Assert.AreEqual(0, fareAttributes[idx].Transfers); Assert.AreEqual(string.Empty, fareAttributes[idx].TransferDuration); //a,5.25,USD,0,0, idx = 1; Assert.AreEqual("a", fareAttributes[idx].FareId); Assert.AreEqual("5.25", fareAttributes[idx].Price); Assert.AreEqual("USD", fareAttributes[idx].CurrencyType); Assert.AreEqual(PaymentMethodType.OnBoard, fareAttributes[idx].PaymentMethod); Assert.AreEqual(0, fareAttributes[idx].Transfers); Assert.AreEqual(string.Empty, fareAttributes[idx].TransferDuration); }
public void ParseStops() { // create the reader. GTFSReader<GTFSFeed> reader = new GTFSReader<GTFSFeed>(); // build the source var source = this.BuildSource(); // execute the reader. var feed = reader.Read(source, source.First(x => x.Name.Equals("stops"))); // test result. Assert.IsNotNull(feed.Stops); var stops = feed.Stops.ToList(); Assert.AreEqual(9, stops.Count); // @ 1: stop_id,stop_name,stop_desc,stop_lat,stop_lon,zone_id,stop_url // @ 2: FUR_CREEK_RES,Furnace Creek Resort (Demo),,36.425288,-117.133162,, int idx = 0; Assert.AreEqual("FUR_CREEK_RES", stops[idx].Id); Assert.AreEqual("Furnace Creek Resort (Demo)", stops[idx].Name); Assert.AreEqual(string.Empty, stops[idx].Description); Assert.AreEqual(36.425288, stops[idx].Latitude); Assert.AreEqual(-117.133162, stops[idx].Longitude); Assert.AreEqual(string.Empty, stops[idx].Url); // @ 10: AMV,Amargosa Valley (Demo),,36.641496,-116.40094,, idx = 8; Assert.AreEqual("AMV", stops[idx].Id); Assert.AreEqual("Amargosa Valley (Demo)", stops[idx].Name); Assert.AreEqual(string.Empty, stops[idx].Description); Assert.AreEqual(36.641496, stops[idx].Latitude); Assert.AreEqual(-116.40094, stops[idx].Longitude); Assert.AreEqual(string.Empty, stops[idx].Url); }
public void TestMissingStopTime() { // create the reader. var reader = new GTFSReader<GTFSFeed>(); var source = GTFSAssert.BuildSource(); // execute the reader. var feed = reader.Read(source); // remove. (feed.StopTimes.Get() as List<StopTime>)[2].StopSequence = 1024; // validate. Assert.IsFalse(GTFSFeedValidation.Validate(feed)); }
public void TestValidFeed() { // create the reader. var reader = new GTFSReader<GTFSFeed>(); var source = GTFSAssert.BuildSource(); // execute the reader. var feed = reader.Read(source); // validate. Assert.IsTrue(GTFSFeedValidation.Validate(feed)); }
public void ParseTransfers() { // create the reader. var reader = new GTFSReader<GTFSFeed>(); // build the source var source = this.BuildSource(); // execute the reader. var feed = reader.Read(source, source.First(x => x.Name.Equals("transfers"))); // test result. Assert.IsNotNull(feed.Transfers); var tranfers = feed.Transfers.ToList(); Assert.AreEqual(3, tranfers.Count); //from_stop_id,to_stop_id,transfer_type,min_transfer_time //BULLFROG,STAGECOACH,2,300 int idx = 0; Assert.AreEqual("BULLFROG", tranfers[idx].FromStopId); Assert.AreEqual("STAGECOACH", tranfers[idx].ToStopId); Assert.AreEqual(TransferType.MinimumTime, tranfers[idx].TransferType); Assert.AreEqual("300", tranfers[idx].MinimumTransferTime); //BULLFROG,BEATTY_AIRPORT,3, idx = 1; Assert.AreEqual("BULLFROG", tranfers[idx].FromStopId); Assert.AreEqual("BEATTY_AIRPORT", tranfers[idx].ToStopId); Assert.AreEqual(TransferType.NotPossible, tranfers[idx].TransferType); Assert.AreEqual(string.Empty, tranfers[idx].MinimumTransferTime); //EMSI,AMV,1, idx = 2; Assert.AreEqual("EMSI", tranfers[idx].FromStopId); Assert.AreEqual("AMV", tranfers[idx].ToStopId); Assert.AreEqual(TransferType.TimedTransfer, tranfers[idx].TransferType); Assert.AreEqual(string.Empty, tranfers[idx].MinimumTransferTime); }
public void TestFilterOneStop() { // create the reader. var reader = new GTFSReader<GTFSFeed>(); var source = GTFSAssert.BuildSource(); // execute the reader. var feed = reader.Read(source); // create list of object id's that should remain after filtering. var expectedTripIds = new string[] { "AB1", "AB2", "BFC1", "BFC2" }; var expectedStopIds = new string[] { "BULLFROG", "BEATTY_AIRPORT", "FUR_CREEK_RES" }; var expectedRouteIds = new string[] { "AB", "BFC" }; var expectedShapeIds = new string[] { "shape_1", "shape_2", "shape_6", "shape_7" }; // create the filter. var filter = new GTFSFeedStopsFilter((x) => { return x.Id == "BULLFROG"; }); // execute filter. var filtered = filter.Filter(feed); Assert.IsTrue(GTFSFeedValidation.Validate(filtered)); // test for trips/stops. foreach (var stop in filtered.Stops) { Assert.Contains(stop.Id, expectedStopIds); } foreach(var trip in filtered.Trips) { Assert.Contains(trip.Id, expectedTripIds); } foreach (var route in filtered.Routes) { Assert.Contains(route.Id, expectedRouteIds); } foreach (var shape in filtered.Shapes) { Assert.Contains(shape.Id, expectedShapeIds); } // create the filter. var stopIds = new HashSet<string>(); stopIds.Add("BULLFROG"); filter = new GTFSFeedStopsFilter(stopIds); // execute filter. filtered = filter.Filter(feed); Assert.IsTrue(GTFSFeedValidation.Validate(filtered)); // test for trips/stops. foreach (var stop in filtered.Stops) { Assert.Contains(stop.Id, expectedStopIds); } foreach (var trip in filtered.Trips) { Assert.Contains(trip.Id, expectedTripIds); } foreach (var route in filtered.Routes) { Assert.Contains(route.Id, expectedRouteIds); } foreach (var shape in filtered.Shapes) { Assert.Contains(shape.Id, expectedShapeIds); } }
public void ParseRoutes() { // create the reader. GTFSReader<GTFSFeed> reader = new GTFSReader<GTFSFeed>(); // build the source var source = this.BuildSource(); // execute the reader. var feed = reader.Read(source, source.First(x => x.Name.Equals("routes"))); // test result. Assert.IsNotNull(feed.Routes); var routes = feed.Routes.ToList(); Assert.AreEqual(5, routes.Count); //route_id,agency_id,route_short_name,route_long_name,route_desc,route_type,route_url,route_color,route_text_color //AB,DTA,10,Airport - Bullfrog,,3,,, int idx = 0; Assert.AreEqual("AB", routes[idx].Id); Assert.AreEqual("DTA", routes[idx].AgencyId); Assert.AreEqual("10", routes[idx].ShortName); Assert.AreEqual("Airport - Bullfrog", routes[idx].LongName); Assert.AreEqual(string.Empty, routes[idx].Description); Assert.AreEqual(RouteTypeExtended.BusService, routes[idx].Type); Assert.AreEqual(-3932017, routes[idx].Color); Assert.AreEqual(null, routes[idx].TextColor); //BFC,DTA,20,Bullfrog - Furnace Creek Resort,,3,,, idx = 1; Assert.AreEqual("BFC", routes[idx].Id); Assert.AreEqual("DTA", routes[idx].AgencyId); Assert.AreEqual("20", routes[idx].ShortName); Assert.AreEqual("Bullfrog - Furnace Creek Resort", routes[idx].LongName); Assert.AreEqual(string.Empty, routes[idx].Description); Assert.AreEqual(RouteTypeExtended.BusService, routes[idx].Type); Assert.AreEqual(-1, routes[idx].Color); Assert.AreEqual(null, routes[idx].TextColor); //STBA,DTA,30,Stagecoach - Airport Shuttle,,3,,, idx = 2; Assert.AreEqual("STBA", routes[idx].Id); Assert.AreEqual("DTA", routes[idx].AgencyId); Assert.AreEqual("30", routes[idx].ShortName); Assert.AreEqual("Stagecoach - Airport Shuttle", routes[idx].LongName); Assert.AreEqual(string.Empty, routes[idx].Description); Assert.AreEqual(RouteTypeExtended.BusService, routes[idx].Type); Assert.AreEqual(null, routes[idx].Color); Assert.AreEqual(null, routes[idx].TextColor); //CITY,DTA,40,City,,3,,, idx = 3; Assert.AreEqual("CITY", routes[idx].Id); Assert.AreEqual("DTA", routes[idx].AgencyId); Assert.AreEqual("40", routes[idx].ShortName); Assert.AreEqual("City", routes[idx].LongName); Assert.AreEqual(string.Empty, routes[idx].Description); Assert.AreEqual(RouteTypeExtended.BusService, routes[idx].Type); Assert.AreEqual(null, routes[idx].Color); Assert.AreEqual(null, routes[idx].TextColor); //AAMV,DTA,50,Airport - Amargosa Valley,,3,,, idx = 4; Assert.AreEqual("AAMV", routes[idx].Id); Assert.AreEqual("DTA", routes[idx].AgencyId); Assert.AreEqual("50", routes[idx].ShortName); Assert.AreEqual("Airport - Amargosa Valley", routes[idx].LongName); Assert.AreEqual(string.Empty, routes[idx].Description); Assert.AreEqual(RouteTypeExtended.BusService, routes[idx].Type); Assert.AreEqual(null, routes[idx].Color); Assert.AreEqual(null, routes[idx].TextColor); }
public void ParseShapes() { // create the reader. GTFSReader<GTFSFeed> reader = new GTFSReader<GTFSFeed>(); // build the source var source = this.BuildSource(); // execute the reader. var feed = reader.Read(source, source.First(x => x.Name.Equals("shapes"))); // test result. Assert.IsNotNull(feed.Shapes); var shapes = feed.Shapes.ToList(); Assert.AreEqual(44, shapes.Count); // @ 1: shape_id,shape_pt_lat,shape_pt_lon,shape_pt_sequence,shape_dist_traveled // @ 2: shape_1,37.754211,-122.197868,1, int idx = 0; Assert.AreEqual("shape_1", shapes[idx].Id); Assert.AreEqual(37.754211, shapes[idx].Latitude); Assert.AreEqual(-122.197868, shapes[idx].Longitude); Assert.AreEqual(1, shapes[idx].Sequence); Assert.AreEqual(null, shapes[idx].DistanceTravelled); // @ 10: shape_3,37.73645,-122.19706,1, idx = 8; Assert.AreEqual("shape_3", shapes[idx].Id); Assert.AreEqual(37.73645, shapes[idx].Latitude); Assert.AreEqual(-122.19706, shapes[idx].Longitude); Assert.AreEqual(1, shapes[idx].Sequence); Assert.AreEqual(null, shapes[idx].DistanceTravelled); }
/// <summary> /// Builds a test feed. /// </summary> /// <returns></returns> protected virtual IGTFSFeed BuildTestFeed() { // create the reader. var reader = new GTFSReader<GTFSFeed>(); // build the source var source = this.BuildSource(); // execute the reader. return reader.Read(source); }
public void ParseStopTimes() { // create the reader. GTFSReader<GTFSFeed> reader = new GTFSReader<GTFSFeed>(false); // build the source var source = this.BuildSource(); // execute the reader. var feed = reader.Read(source, source.First(x => x.Name.Equals("stop_times"))); // test result. Assert.IsNotNull(feed.StopTimes); var stopTimes = feed.StopTimes.ToList(); Assert.AreEqual(28, stopTimes.Count); // @ 1: trip_id,arrival_time,departure_time,stop_id,stop_sequence,stop_headsign,pickup_type,drop_off_time,shape_dist_traveled // @ SORTED: AAMV1,8:00:00,8:00:00,BEATTY_AIRPORT,1 int idx = 0; Assert.AreEqual("AAMV1", stopTimes[idx].TripId); Assert.AreEqual(new TimeOfDay() { Hours = 8 }, stopTimes[idx].ArrivalTime); Assert.AreEqual(new TimeOfDay() { Hours = 8 }, stopTimes[idx].DepartureTime); Assert.AreEqual("BEATTY_AIRPORT", stopTimes[idx].StopId); Assert.AreEqual(1, stopTimes[idx].StopSequence); Assert.AreEqual(null, stopTimes[idx].StopHeadsign); Assert.AreEqual(null, stopTimes[idx].PickupType); Assert.AreEqual(null, stopTimes[idx].DropOffType); Assert.AreEqual(null, stopTimes[idx].ShapeDistTravelled); // @ SORTED: STBA,6:20:00,6:20:00,BEATTY_AIRPORT,2,,,, idx = 27; Assert.AreEqual("STBA", stopTimes[idx].TripId); Assert.AreEqual(new TimeOfDay() { Hours = 6, Minutes = 20 }, stopTimes[idx].ArrivalTime); Assert.AreEqual(new TimeOfDay() { Hours = 6, Minutes = 20 }, stopTimes[idx].DepartureTime); Assert.AreEqual("BEATTY_AIRPORT", stopTimes[idx].StopId); Assert.AreEqual(2, stopTimes[idx].StopSequence); Assert.AreEqual(string.Empty, stopTimes[idx].StopHeadsign); Assert.AreEqual(null, stopTimes[idx].PickupType); Assert.AreEqual(null, stopTimes[idx].DropOffType); Assert.AreEqual(string.Empty, stopTimes[idx].ShapeDistTravelled); }
/// <summary> /// Loads a new instance. /// </summary> /// <param name="apiConfiguration"></param> /// <param name="instanceConfiguration"></param> /// <returns></returns> private static bool LoadInstance(ApiConfiguration apiConfiguration, InstanceConfiguration instanceConfiguration) { try { // get graph configuration. var graph = instanceConfiguration.Graph; var type = instanceConfiguration.Type; var format = instanceConfiguration.Format; var vehicleName = instanceConfiguration.Vehicle; try { // create routing instance. OsmSharp.Logging.Log.TraceEvent("Bootstrapper", OsmSharp.Logging.TraceEventType.Information, string.Format("Creating {0} instance...", instanceConfiguration.Name)); Router router = null; RouterDataSource<Edge> data = null; var graphFile = new FileInfo(graph); switch (type) { case "raw": switch (format) { case "osm-xml": using(var graphStream = graphFile.OpenRead()) { data = OsmSharp.Routing.Osm.Streams.GraphOsmStreamTarget.Preprocess( new XmlOsmStreamSource(graphStream), new OsmRoutingInterpreter()); router = Router.CreateFrom(data, new OsmRoutingInterpreter()); } break; case "osm-pbf": using (var graphStream = graphFile.OpenRead()) { data = OsmSharp.Routing.Osm.Streams.GraphOsmStreamTarget.Preprocess( new PBFOsmStreamSource(graphStream), new OsmRoutingInterpreter()); router = Router.CreateFrom(data, new OsmRoutingInterpreter()); } break; default: throw new Exception(string.Format("Invalid format {0} for type {1}.", format, type)); } break; case "contracted": // check for GTFS-feeds and give warning if they are there. if(instanceConfiguration.Feeds != null && instanceConfiguration.Feeds.Count > 0) { // ... oeps a feed and a contracted network are not supported for now. OsmSharp.Logging.Log.TraceEvent("ApiBootstrapper", OsmSharp.Logging.TraceEventType.Warning, "NotSupported: GTFS and contracted graphs cannot (yet) be combined."); } switch(format) { case "osm-xml": if (string.IsNullOrWhiteSpace(vehicleName)) { // invalid configuration. throw new Exception("Invalid configuration, a vehicle type is required when building contracted graphs on-the-fly."); } using (var graphStream = graphFile.OpenRead()) { var graphSource = new XmlOsmStreamSource(graphStream); router = Router.CreateCHFrom(graphSource, new OsmRoutingInterpreter(), Vehicle.GetByUniqueName(vehicleName)); } break; case "osm-pbf": if (string.IsNullOrWhiteSpace(vehicleName)) { // invalid configuration. throw new Exception("Invalid configuration, a vehicle type is required when building contracted graphs on-the-fly."); } using (var graphStream = graphFile.OpenRead()) { var graphSource = new PBFOsmStreamSource(graphStream); router = Router.CreateCHFrom(graphSource, new OsmRoutingInterpreter(), Vehicle.GetByUniqueName(vehicleName)); } break; case "flat": var mobileRoutingSerializer = new CHEdgeSerializer(); // keep this stream open, it is used while routing! var mobileGraphInstance = mobileRoutingSerializer.Deserialize(graphFile.OpenRead()); router = Router.CreateCHFrom(mobileGraphInstance, new CHRouter(), new OsmRoutingInterpreter()); break; default: throw new Exception(string.Format("Invalid format {0} for type {1}.", format, type)); } break; case "simple": switch (format) { case "flat": using (var graphStream = graphFile.OpenRead()) { var routingSerializer = new RoutingDataSourceSerializer(); data = routingSerializer.Deserialize(graphStream); router = Router.CreateFrom(data, new Dykstra(), new OsmRoutingInterpreter()); } break; default: throw new Exception(string.Format("Invalid format {0} for type {1}.", format, type)); } break; } if(instanceConfiguration.Feeds != null && instanceConfiguration.Feeds.Count > 0) { // transit-data use the transit-api. if(instanceConfiguration.Feeds.Count > 1) { // for now only one feed at a time is supported. OsmSharp.Logging.Log.TraceEvent("ApiBootstrapper", OsmSharp.Logging.TraceEventType.Warning, "NotSupported: Only one GTFS-feed at a time is supported."); } var feed = instanceConfiguration.Feeds[0]; var reader = new GTFSReader<GTFSFeed>(false); var gtfsFeed = reader.Read<GTFSFeed>(new GTFSDirectorySource(feed.Path)); var connectionsDb = new GTFSConnectionsDb(gtfsFeed); var multimodalConnectionsDb = new MultimodalConnectionsDb(data, connectionsDb, new OsmRoutingInterpreter(), Vehicle.Pedestrian); lock (_sync) { OsmSharp.Service.Routing.ApiBootstrapper.AddOrUpdate(instanceConfiguration.Name, new MultimodalApi(multimodalConnectionsDb)); } } else { // no transit-data just use the regular routing api implementation. lock (_sync) { OsmSharp.Service.Routing.ApiBootstrapper.AddOrUpdate(instanceConfiguration.Name, router); } } OsmSharp.Logging.Log.TraceEvent("Bootstrapper", OsmSharp.Logging.TraceEventType.Information, string.Format("Instance {0} created successfully!", instanceConfiguration.Name)); } catch(Exception ex) { OsmSharp.Logging.Log.TraceEvent("Bootstrapper", OsmSharp.Logging.TraceEventType.Error, string.Format("Exception occured while creating instance {0}:{1}", instanceConfiguration.Name, ex.ToInvariantString())); throw; } return true; } catch { return false; } }
public void ParseTrips() { // create the reader. GTFSReader<GTFSFeed> reader = new GTFSReader<GTFSFeed>(false); // build the source var source = this.BuildSource(); // execute the reader. var feed = reader.Read(source, source.First(x => x.Name.Equals("trips"))); // test result. Assert.IsNotNull(feed.Trips); var trips = feed.Trips.ToList(); Assert.AreEqual(11, trips.Count); // @ 1: route_id,service_id,trip_id,trip_headsign,direction_id,block_id,shape_id // @ 2: AB,FULLW,AB1,to Bullfrog,0,1,shape_1 int idx = 0; Assert.AreEqual("AB", trips[idx].RouteId); Assert.AreEqual("FULLW", trips[idx].ServiceId); Assert.AreEqual("AB1", trips[idx].Id); Assert.AreEqual("to Bullfrog", trips[idx].Headsign); Assert.AreEqual(DirectionType.OneDirection, trips[idx].Direction); Assert.AreEqual("1", trips[idx].BlockId); Assert.AreEqual("shape_1", trips[idx].ShapeId); // @ 10: BFC,FULLW,BFC1,to Furnace Creek Resort,0,1,shape_6 idx = 5; Assert.AreEqual("BFC", trips[idx].RouteId); Assert.AreEqual("FULLW", trips[idx].ServiceId); Assert.AreEqual("BFC1", trips[idx].Id); Assert.AreEqual("to Furnace Creek Resort", trips[idx].Headsign); Assert.AreEqual(DirectionType.OneDirection, trips[idx].Direction); Assert.AreEqual("1", trips[idx].BlockId); Assert.AreEqual("shape_6", trips[idx].ShapeId); }
public void ParseCalendars() { // create the reader. GTFSReader<GTFSFeed> reader = new GTFSReader<GTFSFeed>(); // build the source var source = this.BuildSource(); // execute the reader. var feed = reader.Read(source, source.First(x => x.Name.Equals("calendar"))); // test result. Assert.IsNotNull(feed.Calendars); var calendars = feed.Calendars.ToList(); Assert.AreEqual(2, calendars.Count); // @ 1: service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date // @ 2: FULLW,1,1,1,1,1,1,1,20070101,20101231 int idx = 0; Assert.AreEqual("FULLW", calendars[idx].ServiceId); Assert.AreEqual(true, calendars[idx].Monday); Assert.AreEqual(true, calendars[idx].Tuesday); Assert.AreEqual(true, calendars[idx].Wednesday); Assert.AreEqual(true, calendars[idx].Thursday); Assert.AreEqual(true, calendars[idx].Friday); Assert.AreEqual(true, calendars[idx].Saturday); Assert.AreEqual(true, calendars[idx].Sunday); Assert.AreEqual(new DateTime(2007, 01, 01), calendars[idx].StartDate); Assert.AreEqual(new DateTime(2010, 12, 31), calendars[idx].EndDate); // @3: WE,0,0,0,0,0,1,1,20070101,20101231 idx = 1; Assert.AreEqual("WE", calendars[idx].ServiceId); Assert.AreEqual(false, calendars[idx].Monday); Assert.AreEqual(false, calendars[idx].Tuesday); Assert.AreEqual(false, calendars[idx].Wednesday); Assert.AreEqual(false, calendars[idx].Thursday); Assert.AreEqual(false, calendars[idx].Friday); Assert.AreEqual(true, calendars[idx].Saturday); Assert.AreEqual(true, calendars[idx].Sunday); Assert.AreEqual(new DateTime(2007, 01, 01), calendars[idx].StartDate); Assert.AreEqual(new DateTime(2010, 12, 31), calendars[idx].EndDate); }
/// <summary> /// Returns the feed produced by this reader. /// </summary> /// <returns></returns> public override IGTFSFeed GetFeed() { // create the reader. var reader = new GTFSReader<GTFSFeed>(false); // execute the reader. return reader.Read(new GTFSDirectorySource(new DirectoryInfo(_path))); }
public void ParseCalendarDates() { // create the reader. var reader = new GTFSReader<GTFSFeed>(); reader.DateTimeReader = (dateString) => { var year = int.Parse(dateString.Substring(0, 4)); var month = int.Parse(dateString.Substring(4, 2)); var day = int.Parse(dateString.Substring(6, 2)); return new System.DateTime(year, month, day); }; // build the source var source = this.BuildSource(); // execute the reader. var feed = reader.Read(source, source.First(x => x.Name.Equals("calendar_dates"))); // test result. Assert.IsNotNull(feed.CalendarDates); var calendarDates = new List<CalendarDate>(feed.CalendarDates); // @ 1: service_id,date,exception_type // @ 2: FULLW,20070604,2 int idx = 0; Assert.AreEqual("FULLW", calendarDates[idx].ServiceId); Assert.AreEqual(new System.DateTime(2007, 06, 04), calendarDates[idx].Date); Assert.AreEqual(ExceptionType.Removed, calendarDates[idx].ExceptionType); }