private void LoadStopDemands(List <string[]> demandsData) { if (demandsData != null) { Console.WriteLine(this + "Loading Stop Demands..."); var watch = Stopwatch.StartNew(); foreach (var demandData in demandsData) { var route = Routes.Find(r => r.Id == int.Parse(demandData[0])); var stop = Stops.Find(s => s.Id == int.Parse(demandData[1])); var hour = int.Parse(demandData[2]); var demand = (int)Math.Round(Convert.ToDouble(double.Parse(demandData[3]))); if (stop != null && route != null) { DemandsDataObject.AddDemand(stop.Id, route.Id, hour, demand); } } watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; var seconds = elapsedMs * 0.001; Console.WriteLine(this.ToString() + "Stop demands were successfully loaded in " + seconds + " seconds."); } }
private void LoadStopsIntoTrips(List <string[]> tripsStopData) { if (tripsStopData != null) { Console.WriteLine(this + "Inserting Stop sequence into each Trip..."); var watch = Stopwatch.StartNew(); int prevTripId = 0; Trip tr = null; List <Stop> tripStops = new List <Stop>(); foreach (var tripStopData in tripsStopData) { var tripId = int.Parse(tripStopData[0]); if (prevTripId != tripId) { tr = Trips.Find(t => t.Id == tripId); tr.Stops = tripStops; tripStops = new List <Stop>(); } prevTripId = tripId; if (tr != null) { if (Trips.Contains(tr)) { var stopId = int.Parse(tripStopData[1]); Stop stop = Stops.Find(s => s.Id == stopId); tripStops.Add(stop); } } } watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; var seconds = elapsedMs * 0.001; Console.WriteLine(this + "Stops were successfully inserted into trips in " + seconds + " seconds."); } }