示例#1
0
文件: Trip.cs 项目: amseet/Orion
        public static Cardinal GetDirection(Lattice lattice, int Cell1ID, int Cell2ID)
        {
            var Cell1 = lattice.GetCell(Cell1ID);
            var Cell2 = lattice.GetCell(Cell2ID);

            return(GetDirection(lattice, Cell1, Cell2));
        }
示例#2
0
        public RegionData FindRegion(double lat, double lng)
        {
            Cell cell = Lattice.GetCell(lat, lng);

            if (cell != null && PrimaryLookup.TryGetValue(cell.ID, out int ObjectID))
            {
                return(DataLookup[ObjectID]);
            }
            return(null);
        }
示例#3
0
        public static List <Trip.Attr> GetTrips(Lattice lattice, DateTime from, DateTime to, DayOfWeek day, bool Save = true)
        {
            Stopwatch  stopwatch = new Stopwatch();
            SqlContext context   = new SqlContext();

            #region DataRetrival
            Console.WriteLine(">Data Retrival<");
            stopwatch.Restart();
            var Rows = context.TripData.AsNoTracking()
                       .Where(t => t.Trip_Day == day.ToString() &&
                              t.Trip_Date >= from &&
                              t.Trip_Date < to)
                       .Select(t => new {
                t.Pickup_Latitude,
                t.Pickup_Longitude,
                t.Dropoff_Latitude,
                t.Dropoff_Longitude,
                t.Pickup_Datetime,
                t.Passenger_Count
            });
            Console.WriteLine("Row Count: {0}", Rows.Count());
            Console.WriteLine("Execution Time: {0} Seconds\n", (float)stopwatch.ElapsedMilliseconds / 1000);
            #endregion

            #region DataProcessing
            Console.WriteLine(">Populating Trip List<");
            stopwatch.Restart();
            List <Trip.Attr> Trips = new List <Trip.Attr>(Rows.Count());
            Rows.ForEachAsync(trip => {
                Cell pCell = lattice.GetCell(trip.Pickup_Latitude, trip.Pickup_Longitude);
                Cell dCell = lattice.GetCell(trip.Dropoff_Latitude, trip.Dropoff_Longitude);
                if (pCell != null && dCell != null)
                {
                    Trips.Add(new Trip.Attr()
                    {
                        Pickup         = new GeoLocation(trip.Pickup_Latitude, trip.Pickup_Longitude),
                        Dropoff        = new GeoLocation(trip.Dropoff_Latitude, trip.Dropoff_Longitude),
                        PickupZone     = pCell.ID,
                        DropoffZone    = dCell.ID,
                        PassengerCount = trip.Passenger_Count,
                        Date           = trip.Pickup_Datetime.Date,
                        Hour           = trip.Pickup_Datetime.Hour,
                        Minute         = trip.Pickup_Datetime.Minute,
                        //Direction = Trip.GetDirection(lattice, pCell, dCell)
                    });
                }
            }).Wait();
            Console.WriteLine("Time Elapsed: {0} Seconds\n", (float)stopwatch.ElapsedMilliseconds / 1000);
            #endregion

            #region SavingData
            //if (Save)
            //{
            //    Console.WriteLine(">Saving Trip Data<");
            //    stopwatch.Restart();
            //    Binarizer.Binarize(Trips, string.Format(@".\{0}Trips-2015.dat", dayOfWeek.ToString()));
            //    Console.WriteLine("Time Elapsed: {0} Seconds\n", (float)stopwatch.ElapsedMilliseconds / 1000);
            //}
            #endregion

            return(Trips);
        }