/// <summary> /// Gets all stop times for the given trips. /// </summary> /// <returns></returns> public IEnumerable <StopTime> GetForTrips(IEnumerable <string> tripIds) { if (tripIds.Count() == 0) { return(new List <StopTime>()); } var results = new List <StopTime>(); var groups = tripIds.SplitIntoGroupsByGroupIdx(); foreach (var group in groups) { var sql = new StringBuilder("SELECT trip_id, arrival_time, departure_time, stop_id, stop_sequence, stop_headsign, pickup_type, drop_off_type, shape_dist_traveled, passenger_boarding, passenger_alighting, through_passengers, total_passengers, continuous_pickup, continuous_drop_off FROM stop_time WHERE FEED_ID = :feed_id AND trip_id = :trip_id0"); var parameters = new List <NpgsqlParameter>(); parameters.Add(new NpgsqlParameter("feed_id", DbType.Int64)); parameters[0].Value = _id; int i = 0; foreach (var tripId in group.Value) { if (i > 0) { sql.Append($" OR trip_id = :trip_id{i}"); } parameters.Add(new NpgsqlParameter($"trip_id{i}", DbType.String)); parameters[1 + i].Value = tripId; i++; } sql.Append(" ORDER BY trip_id ASC, stop_sequence ASC;"); var result = new PostgreSQLEnumerable <StopTime>(_connection, sql.ToString(), parameters.ToArray(), (x) => { return(new StopTime() { TripId = x.GetString(0), ArrivalTime = TimeOfDay.FromTotalSeconds(x.GetInt32(1)), DepartureTime = TimeOfDay.FromTotalSeconds(x.GetInt32(2)), StopId = x.GetString(3), StopSequence = (uint)x.GetInt32(4), StopHeadsign = x.IsDBNull(5) ? null : x.GetString(5), PickupType = x.IsDBNull(6) ? null : (PickupType?)x.GetInt64(6), DropOffType = x.IsDBNull(7) ? null : (DropOffType?)x.GetInt64(7), ShapeDistTravelled = x.IsDBNull(8) ? null : x.GetString(8), PassengerBoarding = x.IsDBNull(9) ? null : (int?)x.GetInt32(9), PassengerAlighting = x.IsDBNull(10) ? null : (int?)x.GetInt32(10), ThroughPassengers = x.IsDBNull(11) ? null : (int?)x.GetInt32(11), TotalPassengers = x.IsDBNull(12) ? null : (int?)x.GetInt32(12), ContinuousPickup = x.IsDBNull(13) ? null : (ContinuousPickup?)x.GetInt64(13), ContinuousDropOff = x.IsDBNull(14) ? null : (ContinuousDropOff?)x.GetInt64(14) }); }); results.AddRange(result); } return(results); }
/// <summary> /// Returns the entities for the given id's. /// </summary> /// <param name="entityIds"></param> /// <returns></returns> public IEnumerable <Shape> Get(List <string> entityIds) { if (entityIds.Count() == 0) { return(new List <Shape>()); } var results = new List <Shape>(); var groups = entityIds.SplitIntoGroupsByGroupIdx(); foreach (var group in groups) { var sql = new StringBuilder("SELECT id, shape_pt_lat, shape_pt_lon, shape_pt_sequence, shape_dist_traveled FROM shape WHERE FEED_ID = :feed_id AND id = :id0"); var parameters = new List <NpgsqlParameter>(); parameters.Add(new NpgsqlParameter("feed_id", DbType.Int64)); parameters[0].Value = _id; int i = 0; foreach (var entityId in group.Value) { if (i > 0) { sql.Append($" OR id = :id{i}"); } parameters.Add(new NpgsqlParameter($"id{i}", DbType.String)); parameters[1 + i].Value = entityId; i++; } sql.Append(" ORDER BY id, shape_pt_sequence"); var result = new PostgreSQLEnumerable <Shape>(_connection, sql.ToString(), parameters.ToArray(), (x) => { return(new Shape() { Id = x.GetString(0), Latitude = x.GetDouble(1), Longitude = x.GetDouble(2), Sequence = (uint)x.GetInt64(3), DistanceTravelled = x.IsDBNull(4) ? null : (double?)x.GetDouble(4) }); }); results.AddRange(result); } return(results); }