예제 #1
0
        /// <summary>
        /// Initializes object using GTFS data feed.
        /// </summary>
        /// <param name="trips">Trips.</param>
        /// <param name="routesInfo">Routes Info.</param>
        public GtfsRoutes(Trips trips, RoutesInfo routesInfo)
        {
            foreach (var trip in trips)
            {
                List <Stops.Stop> stopsSequence = new List <Stops.Stop>();

                foreach (var stopTime in trip.Value.StopTimes)
                {
                    stopsSequence.Add(stopTime.Stop);
                }

                Route r = new Route(Count, trip.Value.RouteInfo, stopsSequence, trip.Value.Headsign);

                if (!list.Contains(r))
                {
                    list.Add(r);
                }
                else
                {
                    r = list.Find(x => x.Equals(r));
                }

                trip.Value.Route = r;

                r.Trips.Add(trip.Value);
            }
        }
예제 #2
0
 /// <summary>
 /// Merges two collections into one.
 /// </summary>
 /// <param name="other">The other collection that should be merged.</param>
 public void MergeCollections(RoutesInfo other)
 {
     foreach (var item in other)
     {
         var info = item.Value;
         info.ID = Count;                 // Reindex the item.
         string key;
         while (list.ContainsKey(key = DataFeed.RandomString()))
         {
             ;                                                                    // We can index the item using some random string, since this identificator is only used while initialization. Both data are already initialized.
         }
         list.Add(key, info);
     }
     other = null;
 }
예제 #3
0
        /// <summary>
        /// Initializes object using GTFS data feed.
        /// </summary>
        /// <param name="routesInfo">Routes Info.</param>
        /// <param name="services">Services.</param>
        /// <param name="trips">Trips.</param>
        public GtfsTrips(System.IO.StreamReader trips, Calendar services, RoutesInfo routesInfo)
        {
            // Get order of field names.
            string[] fieldNames          = trips.ReadLine().Split(',');
            Dictionary <string, int> dic = new Dictionary <string, int>();

            for (int i = 0; i < fieldNames.Length; i++)
            {
                dic.Add(fieldNames[i].Replace("\"", ""), i);
            }

            // These fields are required for our purpose.
            if (!dic.ContainsKey("route_id"))
            {
                throw new FormatException("Route ID field name missing.");
            }
            if (!dic.ContainsKey("service_id"))
            {
                throw new FormatException("Service ID field name missing.");
            }
            if (!dic.ContainsKey("trip_id"))
            {
                throw new FormatException("Trip ID field name missing.");
            }
            if (!dic.ContainsKey("trip_headsign"))
            {
                throw new FormatException("Trip headsign field name missing.");
            }

            while (!trips.EndOfStream)
            {
                IList <string> tokens = GtfsDataFeed.SplitGtfs(trips.ReadLine());

                // Since this application is optimized for Prague, we have to union stations of type Florenc, Florenc - B, Florenc - C. Otherwise they would become three separate stations.

                string headsign = tokens[dic["trip_headsign"]].Length > 4 && tokens[dic["trip_headsign"]][tokens[dic["trip_headsign"]].Length - 3] == '-' ? tokens[dic["trip_headsign"]].Substring(0, tokens[dic["trip_headsign"]].Length - 4) : tokens[dic["trip_headsign"]];

                // The same for Újezd LD and Újezd.

                headsign = headsign.Length > 4 && headsign.Substring(headsign.Length - 4, 4) == "  LD" ? headsign.Substring(0, headsign.Length - 4) : headsign;
                headsign = headsign.Length > 3 && headsign.Substring(headsign.Length - 3, 3) == " LD" ? headsign.Substring(0, headsign.Length - 3) : headsign;

                Trip trip = new Trip(Count, headsign, routesInfo[tokens[dic["route_id"]]], services[tokens[dic["service_id"]]]);

                list.Add(tokens[dic["trip_id"]], trip);
            }
            trips.Dispose();
        }
예제 #4
0
        /// <summary>
        /// Creates data feed that is required in GUI.
        /// </summary>
        /// <param name="path">Path to the folder that will be the feed saved to.</param>
        public void CreateBasicData(string path)
        {
            if (Directory.Exists(path))
            {
                Directory.Delete(path, true);
            }
            Directory.CreateDirectory(path);

            RoutesInfo.WriteBasic(new StreamWriter(path + "/routes_info.tfb"));
            Stops.WriteBasic(new StreamWriter(path + "/stops.tfb"));
            Stations.WriteBasic(new StreamWriter(path + "/stations.tfb"));

            Random random  = new Random();
            var    version = new string(Enumerable.Repeat("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 10).Select(s => s[random.Next(s.Length)]).ToArray());          // Create a new version stamp if not exists.

            using (var sw = new StreamWriter(path + "/.version"))
                sw.WriteLine(version);
        }
예제 #5
0
        /// <summary>
        /// Creates data feed that is required for the application.
        /// </summary>
        /// <param name="path">Path to the folder that will be the feed saved to.</param>
        public void CreateDataFeed(string path)
        {
            if (Directory.Exists(path))
            {
                Directory.Delete(path, true);
            }
            Directory.CreateDirectory(path);

            Trips.Write(new StreamWriter(path + "/trips.tfd"));       // This MUST come first because of trip reindexation (based on sorting).
            Stations.Write(new StreamWriter(path + "/stations.tfd")); // This MUST come first because of stations reindexation (based on sorting).

            Calendar.Write(new StreamWriter(path + "/calendar.tfd"));
            CalendarDates.Write(new StreamWriter(path + "/calendar_dates.tfd"));
            RoutesInfo.Write(new StreamWriter(path + "/routes_info.tfd"));
            Stops.Write(new StreamWriter(path + "/stops.tfd"));
            Footpaths.Write(new StreamWriter(path + "/footpaths.tfd"));
            StopTimes.Write(new StreamWriter(path + "/stop_times.tfd"));
            Routes.Write(new StreamWriter(path + "/routes.tfd"));

            using (var expiration = new StreamWriter(path + "/expires.tfd"))
                expiration.Write(ExpirationDate.ToString("yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture));
        }