/// <summary> /// Initializes object. /// </summary> /// <param name="trip">Trip.</param> /// <param name="arrival">Arrival.</param> /// <param name="departure">Departure.</param> /// <param name="stop">Stop.</param> public StopTime(Trips.Trip trip, int arrival, int departure, Stops.Stop stop) { Trip = trip; ArrivalTime = arrival; DepartureTime = departure; Stop = stop; }
/// <summary> /// Gets a walking time between two stops. /// </summary> /// <param name="A">First stop.</param> /// <param name="B">Second stop.</param> /// <returns>Walking time in seconds.</returns> public static int GetWalkingTime(this Stops.Stop A, Stops.Stop B) { var deltaLatitudeDistance = Math.Abs(Math.Abs(A.Location.Item1) - Math.Abs(B.Location.Item1)) * OneDegreeLatitudeLength; // Meters. var deltaLongitudeDistance = Math.Abs(Math.Abs(A.Location.Item2) - Math.Abs(B.Location.Item2)) * OneDegreeLatitudeLength; // Meters. return((int)(Math.Sqrt(Math.Pow(deltaLatitudeDistance, 2) + Math.Pow(deltaLongitudeDistance, 2)) / GlobalData.AverageWalkingSpeed)); // Pythagorean theoream. }
/// <summary> /// Initializes object using GTFS data feed. /// </summary> /// <param name="stops">Stops.</param> /// <param name="stopTimes">Stop Times.</param> /// <param name="trips">Trip.</param> public GtfsStopTimes(System.IO.StreamReader stopTimes, Trips trips, Stops stops) { // Get order of field names. string[] fieldNames = stopTimes.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("arrival_time")) { throw new FormatException("Arrival time field name missing."); } if (!dic.ContainsKey("departure_time")) { throw new FormatException("Departure time field name missing."); } if (!dic.ContainsKey("trip_id")) { throw new FormatException("Trip ID field name missing."); } if (!dic.ContainsKey("stop_id")) { throw new FormatException("Stop ID field name missing."); } while (!stopTimes.EndOfStream) { IList <string> tokens = GtfsDataFeed.SplitGtfs(stopTimes.ReadLine()); Trips.Trip trip = null; try { trip = trips[tokens[dic["trip_id"]]]; } catch { DataFeed.LogError($"Preprocessor tried to parse a stop-time, but the trip with ID { tokens[dic["trip_id"]] } does not exist. Skipping this item to recover the parsing process."); continue; } if (trip.StopTimes.Count == 0) // Set departure time of the trip. { trip.DepartureTime = ConvertTimeToSecondsSinceMidnight(tokens[dic["departure_time"]]); } Stops.Stop stop = null; try { stop = stops[tokens[dic["stop_id"]]]; } catch { DataFeed.LogError($"Preprocessor tried to parse a stop-time to the trip { trip.ID }, line { trip.RouteInfo.ShortName } in direction to { trip.Headsign }, but the stop with ID { tokens[dic["stop_id"]] } does not exist. Skipping this item to recover the parsing process."); continue; } StopTime st = new StopTime(trip, ConvertTimeToSecondsSinceMidnight(tokens[dic["arrival_time"]]) - trip.DepartureTime, ConvertTimeToSecondsSinceMidnight(tokens[dic["departure_time"]]) - trip.DepartureTime, stop); st.Trip.StopTimes.Add(st); if (!st.Stop.ThroughgoingRoutes.Contains(st.Trip.RouteInfo)) { st.Stop.ThroughgoingRoutes.Add(st.Trip.RouteInfo); } list.Add(st); } stopTimes.Dispose(); }
/// <summary> /// Initializes object. /// </summary> /// <param name="duration">Duration in seconds.</param> /// <param name="first">First stop.</param> /// <param name="second">Second stop.</param> public Footpath(int duration, Stops.Stop first, Stops.Stop second) { Duration = duration; First = first; Second = second; }