Ejemplo n.º 1
0
        public async Task <IActionResult> GetNearDrivers(LatLonDto latLonDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var drivers = await _locationRepository.GetNear(latLonDto.Latitude, latLonDto.Longitude);

            var driverLocationToReturn = new List <DriverLocationDto>();

            foreach (var driver in drivers)
            {
                var place = Helpers.Location.PointToPlaceDto(driver.Location);
                driverLocationToReturn.Add(new DriverLocationDto()
                {
                    DriverId  = driver.Id,
                    Latitude  = place.Latitude,
                    Longitude = place.Longitude
                });
            }


            return(Ok(driverLocationToReturn));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> FinishTripAsync([FromBody] LatLonDto finishTrip)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var driverId = User.Claims.FirstOrDefault(c => c.Type == Helpers.Constants.Strings.JwtClaimIdentifiers.DriverId)?.Value;

            var trip = _tripsRepo.GetTripByDriver(Guid.Parse(driverId), true);

            if (trip == null)
            {
                return(BadRequest());
            }

            trip.FinishTime = DateTime.UtcNow;

            #region AddLastNode
            var node = _mapper.Map <TripRouteNode>(finishTrip);

            node.UpdateTime = DateTime.UtcNow;

            node.TripId = trip.Id;

            await _tripsRepo.AddNode(node);

            var delta = Helpers.Location.CalculateKilometersDistance(trip.LastLat, trip.LastLon, finishTrip.Latitude, finishTrip.Longitude);

            //trip.Distance += delta;

            trip.LastLat = node.Latitude;

            trip.LastLon = node.Longitude;

            trip.LastUpdateTime = node.UpdateTime;

            var res = await _tripsRepo.UpdateTrip(trip, null, Mapper.Map <PlaceDto>(finishTrip));

            if (res == false)
            {
                return(BadRequest());
            }
            #endregion

            var tripStatusDto = Mapper.Map <TripStatusDto>(trip);

            var from = trip.From;
            var to   = trip.To;

            tripStatusDto.From = Taxi.Helpers.Location.PointToPlaceDto(from);

            tripStatusDto.To = Taxi.Helpers.Location.PointToPlaceDto(to);

            return(Ok(tripStatusDto));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> UpdateDriverLocation([FromBody] LatLonDto latLonDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var driverid = User.Claims.Single(c => c.Type == Constants.Strings.JwtClaimIdentifiers.DriverId).Value;

            //var res = _driverLocationRepository.UpdateUser(Guid.Parse(driverid), latLonDto.Longitude, latLonDto.Latitude, DateTime.Now);

            var res = await _locationRepository.UpdateLocation(Guid.Parse(driverid), latLonDto.Latitude, latLonDto.Longitude);

            if (res != true)
            {
                return(Conflict());
            }

            return(NoContent());
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> UpdateDriverLocation([FromBody] LatLonDto latLon)
        {
            var driverId = Guid.Parse(User.Claims
                                      .FirstOrDefault(c => c.Type == Helpers.Constants.Strings.JwtClaimIdentifiers.DriverId)?.Value);
            var trip = _tripsRepo.GetTripByDriver(driverId);

            if (trip == null)
            {
                return(NotFound());
            }

            try
            {
                // Sending driver's position to the customer
                await _hubContext.Clients.Client(_usersRepository.GetCustomerById(trip.CustomerId).ConnectionId)
                .SendAsync("postGeoData", latLon.Latitude, latLon.Longitude);
            }
            catch
            {
            }

            return(NoContent());
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> UpdateTripStartLocation([FromBody] LatLonDto location)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var customerId = Guid.Parse(User.Claims.FirstOrDefault(c => c.Type == Helpers.Constants.Strings.JwtClaimIdentifiers.CustomerId)?.Value);

            var trip = _tripsRepo.GetTrip(customerId);

            if (trip == null)
            {
                return(NotFound());
            }

            var res = await _tripsRepo.UpdateTrip(trip, Mapper.Map <PlaceDto>(location));

            if (res == false)
            {
                return(BadRequest());
            }

            return(NoContent());
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> UpdateTripRoute([FromBody] LatLonDto latLon)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var driverId = Guid.Parse(User.Claims
                                      .FirstOrDefault(c => c.Type == Helpers.Constants.Strings.JwtClaimIdentifiers.DriverId)?.Value);

            var trip = _tripsRepo.GetTripByDriver(driverId);

            if (trip == null)
            {
                return(NotFound());
            }

            if (trip.StartTime == default(DateTime))
            {
                ModelState.AddModelError(nameof(Trip), "Trip not started.");
                return(BadRequest(ModelState));
            }
            var delta = Helpers.Location.CalculateKilometersDistance(trip.LastLat, trip.LastLon, latLon.Latitude, latLon.Longitude);

            if (Math.Abs(delta) > 0.001) //traveled 1+ meters
            {
                var node = _mapper.Map <TripRouteNode>(latLon);

                node.UpdateTime = DateTime.UtcNow;

                node.TripId = trip.Id;

                await _tripsRepo.AddNode(node);

                //    trip.Distance += delta;

                trip.LastLat = latLon.Latitude;

                trip.LastLon = latLon.Longitude;

                trip.LastUpdateTime = node.UpdateTime;

                try
                {
                    // Sending driver's position to the customer
                    await _hubContext.Clients.Client(_usersRepository.GetCustomerById(trip.CustomerId).ConnectionId)
                    .SendAsync("postGeoData", trip.LastLat, trip.LastLon);
                }
                catch
                {
                }

                await _tripsRepo.UpdateTrip(trip);
            }

            var from = trip.From;
            var to   = trip.To;


            var tripToReturn = new UpdateResultTripDto()
            {
                CustomerId      = trip.CustomerId,
                From            = Taxi.Helpers.Location.PointToPlaceDto(from),
                To              = Taxi.Helpers.Location.PointToPlaceDto(to),
                LastUpdatePoint = new PlaceDto()
                {
                    Longitude = trip.LastLon,
                    Latitude  = trip.LastLat
                },
                //TraveledDistance = trip.Distance
            };

            return(Ok(tripToReturn));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> StartTrip([FromBody] LatLonDto location)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var driverId = User.Claims.FirstOrDefault(c => c.Type == Helpers.Constants.Strings.JwtClaimIdentifiers.DriverId)?.Value;

            var driver = _usersRepository.GetDriverByIdentityId(driverId);

            // Set connectionId for Diver
            //_routeHub.ConnectDriver(driver);

            var trip = _tripsRepo.GetTripByDriver(Guid.Parse(driverId));

            if (trip == null)
            {
                return(BadRequest());
            }

            trip.StartTime = DateTime.UtcNow;

            #region StartNode
            var node = _mapper.Map <TripRouteNode>(location);

            node.UpdateTime = DateTime.UtcNow;

            node.TripId = trip.Id;

            await _tripsRepo.AddNode(node);

            //  trip.Distance = 0;

            trip.LastLat = location.Latitude;

            trip.LastLon = location.Longitude;

            trip.LastUpdateTime = node.UpdateTime;
            #endregion

            var res = await _tripsRepo.UpdateTrip(trip, Mapper.Map <PlaceDto>(location));

            if (res != true)
            {
                return(BadRequest());
            }

            var from     = trip.From;
            var to       = trip.To;
            var customer = _usersRepository.GetCustomerById(trip.CustomerId);
            var toReturn = new TripDto()
            {
                CustomerId = trip.CustomerId,
                From       = Helpers.Location.PointToPlaceDto(from),
                To         = Helpers.Location.PointToPlaceDto(to),
                FirstName  = customer.Identity.FirstName,
                LastName   = customer.Identity.LastName
            };

            return(Ok(toReturn));
        }
Ejemplo n.º 8
0
        private AreaDto BuildArea(string scene, int areaNumber, int X1, int Y1, int OFFSET)
        {
            LatLonDto lonLat = new LatLonDto();

            var mapPoints  = new List <MapPointDto>();
            var unitPoints = new List <UnitPointDto>();

            string sceneName = Path.GetDirectoryName(scene);

            var files = Directory.GetFiles(scene);

            var band10 = files.FirstOrDefault(x => Path.GetFileNameWithoutExtension(x).EndsWith("B10"));

            var band5 = files.FirstOrDefault(x => Path.GetFileNameWithoutExtension(x).EndsWith("B5"));

            var band4 = files.FirstOrDefault(x => Path.GetFileNameWithoutExtension(x).EndsWith("B4"));

            if (band10 != null && band4 != null && band5 != null)
            {
                int utm_zone = int.Parse(GetMetadataValue(scene, MetadataTags.UTM_ZONE).ToString());

                lonLat = GeoTIFF.LonLat(band10, utm_zone, X1, Y1, OFFSET);

                Band10Tiff = new GeoTIFF(band10, X1, Y1, OFFSET);

                Band4Tiff = new GeoTIFF(band4, X1, Y1, OFFSET);

                Band5Tiff = new GeoTIFF(band5, X1, Y1, OFFSET);

                float Ml = GetMetadataValue(scene, MetadataTags.RADIANCE_MULT_BAND_10);

                float Al = GetMetadataValue(scene, MetadataTags.RADIANCE_ADD_BAND_10);

                float K1 = GetMetadataValue(scene, MetadataTags.K1_CONSTANT_BAND_10);

                float K2 = GetMetadataValue(scene, MetadataTags.K2_CONSTANT_BAND_10);

                int ndviHeight = OFFSET;
                int ndviWidth  = OFFSET;

                BT = new double[ndviHeight, ndviWidth];

                Ndvi = new float[ndviHeight, ndviWidth];
                Eps  = new double[ndviHeight, ndviWidth];
                LST  = new double[ndviHeight, ndviWidth];

                float ndviMin = float.MaxValue, ndviMax = float.MinValue;

                for (int i = 0; i < ndviHeight; i++)
                {
                    for (int j = 0; j < ndviWidth; j++)
                    {
                        float band4Value = Band4Tiff.HeightMap[i, j];
                        float band5value = Band5Tiff.HeightMap[i, j];

                        if (band4Value > 0 && band5value > 0)
                        {
                            float ndvi = (band5value - band4Value) / (band5value + band4Value);

                            if (ndvi > ndviMax)
                            {
                                ndviMax = ndvi;
                            }

                            if (ndvi < ndviMin)
                            {
                                ndviMin = ndvi;
                            }

                            Ndvi[i, j] = ndvi;
                        }
                    }
                }

                for (int i = 0; i < ndviHeight; i++)
                {
                    for (int j = 0; j < ndviWidth; j++)
                    {
                        var height = Band10Tiff.HeightMap[i, j];

                        if (height > 0)
                        {
                            var L = (Ml * height) + Al;                                                          //step 1

                            BT[i, j] = ((K2 / Math.Log(K1 / L) + 1F) - 273.15F);                                 // step 2

                            double pv = Math.Pow((Ndvi[i, j] - ndviMin) / (ndviMax - ndviMin), 2);               // step 3

                            Eps[i, j] = 0.004 * pv + 0.986;                                                      // step 4

                            double val = (BT[i, j] / (1 + (0.00115 * BT[i, j] / 1.4388) * Math.Log(Eps[i, j]))); // step 5

                            if (val > 0)
                            {
                                Console.WriteLine(val);
                                LST[i, j] = val;

                                unitPoints.Add(new UnitPointDto()
                                {
                                    X    = X1 + i,
                                    Y    = Y1 + j,
                                    Ndvi = Ndvi[i, j],
                                    PictureTemperature = LST[i, j],
                                    StationTemperature = null,
                                });

                                mapPoints.Add(new MapPointDto()
                                {
                                    X            = X1 + i,
                                    Y            = Y1 + j,
                                    ChanelValues = new List <ChanelValueDto>()
                                    {
                                        new ChanelValueDto(10, Band10Tiff.HeightMap[i, j]),
                                        new ChanelValueDto(5, Band5Tiff.HeightMap[i, j]),
                                        new ChanelValueDto(4, Band4Tiff.HeightMap[i, j]),
                                    }
                                });
                            }
                        }
                    }
                }
            }

            return(new AreaDto()
            {
                MapPoints = mapPoints,
                UnitPoints = unitPoints,
                Number = areaNumber,
                LonLat = lonLat
            });
        }