Exemplo n.º 1
0
        public async Task <IActionResult> PutTripDataModel([FromRoute] int id, [FromBody] TripDataModel tripDataModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tripDataModel.TripId)
            {
                return(BadRequest());
            }

            _context.Entry(tripDataModel).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TripDataModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(int id, [Bind("TripId,Pickup_Datetime,Dropoff_Datetime,Passenger_Count,Trip_Distance,Pickup_Longitude,Pickup_Latitude,Dropoff_Longitude,Dropoff_Latitude,Fare_Amount")] TripDataModel tripDataModel)
        {
            if (id != tripDataModel.TripId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tripDataModel);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TripDataModelExists(tripDataModel.TripId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tripDataModel));
        }
Exemplo n.º 3
0
        public string Get(int id, string type = "Itinero")
        {
            TripDataModel data = _context.TripData.Find(id);

            if (type.Equals("Google"))
            {
                return(getGoogleMapRoute(data));
            }

            return(getItineroRoute(data));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("TripId,Pickup_Datetime,Dropoff_Datetime,Passenger_Count,Trip_Distance,Pickup_Longitude,Pickup_Latitude,Dropoff_Longitude,Dropoff_Latitude,Fare_Amount")] TripDataModel tripDataModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tripDataModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tripDataModel));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> PostTripDataModel([FromBody] TripDataModel tripDataModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.TripData.Add(tripDataModel);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTripDataModel", new { id = tripDataModel.TripId }, tripDataModel));
        }
Exemplo n.º 6
0
        static void convert(string file)
        {
            var           watch = System.Diagnostics.Stopwatch.StartNew();
            TripDataModel td    = new TripDataModel();
            string        dest  = file.Replace(".csv", ".dat");

            //TODO
            //BianryFile.CsvToBinary<TripAttributes>(file,  dest, ',', td.ParseTokens);

            watch.Stop();
            var elapsedSec = watch.ElapsedMilliseconds / 1000f;

            Console.WriteLine("Execution time: " + elapsedSec.ToString() + "sec");
        }
Exemplo n.º 7
0
        public string getGoogleMapRoute(TripDataModel data)
        {
            var origin      = data.Pickup_Latitude.ToString() + ',' + data.Pickup_Longitude.ToString();
            var destination = data.Dropoff_Latitude.ToString() + ',' + data.Dropoff_Longitude.ToString();
            var key         = "AIzaSyCh0xL_-zPlZRpJtB5-W3O5zu9vJFNywb0";//"AIzaSyBJHn6rSjKhXQs8WpgSOnuAa3uaTzPsFIo";

            string url = String.Format("https://maps.googleapis.com/maps/api/directions/json?origin={0}&destination={1}&key={2}",
                                       origin, destination, key);

            using (var httpClient = new HttpClient())
            {
                var response = httpClient.GetAsync(url).Result;
                return(response.Content.ReadAsStringAsync().Result);
            }
        }
Exemplo n.º 8
0
        public void AddRouteDb(SqlContext sql, Router router, TripDataModel trip, Profile profile, bool withTraffic = false)
        {
            Result <Route> result = router.TryCalculate(profile, (float)trip.Pickup_Latitude, (float)trip.Pickup_Longitude,
                                                        (float)trip.Dropoff_Latitude, (float)trip.Dropoff_Longitude);

            if (!result.IsError)
            {
                Route route = result.Value;
                //sql.TripRoute.Add(new TripRouteModel() {
                //    TripData = trip,
                //    Trip_Distance = route.TotalDistance,
                //    Trip_Time = route.TotalTime
                //});
            }
        }
Exemplo n.º 9
0
        public string getItineroRoute(TripDataModel data)
        {
            try
            {
                var route = _router.Calculate(Vehicle.Car.Shortest(), (float)data.Pickup_Latitude, (float)data.Pickup_Longitude,
                                              (float)data.Dropoff_Latitude, (float)data.Dropoff_Longitude);
                return(route.ToJson());

                //if (Request.ContentType.Equals("application/vnd.geo+json"))
                //    return getRoute(data).ToGeoJson();
                //return getRoute(data).ToJson();
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
Exemplo n.º 10
0
        static void TestRouting()
        {
            var           watch = System.Diagnostics.Stopwatch.StartNew();
            var           index = 0;
            TripDataModel td    = new TripDataModel();

            using (var stream = new FileInfo(@"C:\Users\ahmad\Documents\Visual Studio 2015\Projects\TaxiDataSimulator\data\NewYork.routerdb").OpenRead())
            {
                var routerDb = RouterDb.Deserialize(stream);
                var router   = new Router(routerDb);
                foreach (var data in td.Rows)
                {
                    try
                    {
                        var route = router.Calculate(Vehicle.Car.Shortest(), (float)data.pickup_latitude, (float)data.pickup_longitude,
                                                     (float)data.dropoff_latitude, (float)data.dropoff_longitude);

                        if (index % 100 == 0)
                        {
                            Console.WriteLine(index);
                        }
                        if (index++ > 10000)
                        {
                            break;
                        }
                        //if (Request.ContentType.Equals("application/vnd.geo+json"))
                        //    return getRoute(data).ToGeoJson();
                        //return getRoute(data).ToJson();
                    }
                    catch (Exception e)
                    {
                    }
                }
            }

            watch.Stop();
            var elapsedSec = watch.ElapsedMilliseconds / 1000f;

            Console.WriteLine("Execution time: " + elapsedSec.ToString() + "sec");
        }
Exemplo n.º 11
0
        static TripDataModel import(string file)
        {
            Console.WriteLine("Import Start");
            TripDataModel td   = new TripDataModel();
            Task          task = Task.Run(() =>
            {
                FileStream fstream = new FileStream(file, FileMode.Open, FileAccess.Read);
                var watch          = System.Diagnostics.Stopwatch.StartNew();

                //TODO
                //td.Rows = BinaryStream.Reader.ImportBinaryFile<TripAttributes>(new FileStream(file + ".dat", FileMode.Open));

                watch.Stop();
                var elapsedSec = watch.ElapsedMilliseconds / 1000f;

                Console.WriteLine("Execution time: " + elapsedSec.ToString() + "sec");
            });

            task.Wait();
            Console.WriteLine("Import complete");
            return(td);
        }