public async void CanRunMultipleGLOSARequests_ShouldReturnTrue() { // arrange //SETTINGS_ROUTE_DIRECTION_ANY = 0: - Not Supported Yet //SETTINGS_ROUTE_DIRECTION_IB = 1: - Not Supported Yet //SETTINGS_ROUTE_DIRECTION_OB = 2; var intersectionId = "1992"; var route = KMLHelper.GLOSATestRoute().ToList(); var gpsHistory = KMLHelper.GLOSATestRouteIntersectionHistory(intersectionId, 2); NavigationService navigationService = new NavigationService(); var waypoint1 = navigationService.LocateWaypointOnRoute(WaypointDetectionMethod.GPSHistoryDirection, route, gpsHistory, 0, 0); var waypoint2 = navigationService.LocateWaypointOnRoute(WaypointDetectionMethod.GPSHistoryDirection, route, gpsHistory, 0, 1); var webService = new GLOSAWebService(null); //await Task.Run(async () => await webService.SyncMAPSPATAsync(KMLHelper.IntersectionIdOfPlacemark(waypoint1))); //await Task.Run(async () => await webService.SyncMAPSPATAsync(KMLHelper.IntersectionIdOfPlacemark(waypoint2))); var waypoint1Id = KMLHelper.IntersectionIdOfPlacemark(waypoint1); var waypoint2Id = waypoint2 != null?KMLHelper.IntersectionIdOfPlacemark(waypoint2) : null; await Task.Run(async() => await webService.SyncMAPSPATAsync(waypoint1Id, waypoint2Id)); bool expectedResult = true; //act bool actualResult = waypoint1 != null; //assert Assert.Equal(expectedResult, actualResult); }
public void IsNextMAPDataWaypointInSameDirectionAsTravel_ShouldReturnTrue() { // arrange //SETTINGS_ROUTE_DIRECTION_ANY = 0: - Not Supported Yet //SETTINGS_ROUTE_DIRECTION_IB = 1: - Not Supported Yet //SETTINGS_ROUTE_DIRECTION_OB = 2; //< name > 2130 - Gilberstone Avenue </ name > // 2130 only has inbound SPAT var intersectionId = "2130"; var route = KMLHelper.GLOSATestRoute().ToList(); var gpsHistory = KMLHelper.GLOSATestRouteIntersectionHistory(intersectionId, 1); NavigationService navigationService = new NavigationService(); var waypoint = navigationService.LocateWaypointWithLineOfSight(WaypointDetectionMethod.GPSHistoryDirection, gpsHistory, 0, 50, 0.04); bool expectedResult = true; //act bool actualResult = waypoint != null; //assert Assert.Equal(expectedResult, actualResult); }
public void LoadPlacemarksFromFile_WithNotExistFile_ReturnResultShouldBeEmptyList() { //arrange string inputTestFile = "Not-Exist.kml"; //act var actualResult = KMLHelper.LoadPlacemarksFromFile(inputTestFile); //assert Assert.Equal(emptyList, actualResult); }
public void LoadPlacemarksFromFile_WithA45GLOSAReferencePoint_ReturnResultShouldNotBeEmptyList() { //arrange string inputTestFile = "GreenLight.Core.Test.GLOSA-MAP-CHACHE.kml"; //act var actualResult = KMLHelper.LoadPlacemarksFromFile(inputTestFile); //assert Assert.NotEqual(emptyList, actualResult); }
private void PopulateGeofenceList() { IList <kmlDocumentPlacemark> placemarks = KMLHelper.GLOSATestRoute(); foreach (var placemark in placemarks) { // https://developers.google.com/kml/documentation/kmlreference?csw=1#coordinates var coordinatesString = placemark.Point.coordinates; string[] parts = coordinatesString.Split(','); double longitude = double.Parse(parts[0]); double latitude = double.Parse(parts[1]); _geoList.Add(new GeofenceBuilder().SetRequestId(placemark.name).SetCircularRegion(latitude, longitude, Constants.GeofenceDefaultRadiusMeters).SetExpirationDuration(Geofence.NeverExpire).SetTransitionTypes(Geofence.GeofenceTransitionEnter | Geofence.GeofenceTransitionExit).Build()); } }
private void UpdateCurrentPosition() { _waypointDescription = "[Locating Intersection]"; _currentDistanceToWaypoint = 0; if (IsNavigating == true) { LocateWaypoint(); if (IsNavigatingToWaypoint == true) { _currentDistanceToWaypoint = Convert.ToInt32(KMLHelper.DistanceFromCurrentIntersection(_currentWaypoint, _latitude, _longitude)); _waypointDescription = _currentWaypoint.name; } } }
/// <summary> /// Finds next waypoint by distance from current location /// </summary> private void LocateWaypoint() { if (_routeMode == true) { _currentWaypoint = null; var waypoint = LocateWaypointWithLineOfSight(WaypointDetectionMethod.GPSHistoryDirection, 0, 50, 1.0); if (waypoint == null) { return; } var waypointID = waypoint.intersections.IntersectionGeometry.id.id.ToString(); var nextMAPPlacemark = _testRoute.Find(match => match.name.Contains(waypointID)); if (nextMAPPlacemark != null) { var nextIntersectionId = KMLHelper.IntersectionIdOfPlacemark(nextMAPPlacemark); _currentWaypointId = waypoint.intersections.IntersectionGeometry.id.id.ToString(); _currentWaypoint = nextMAPPlacemark; } } }
public async void IsNextWaypointInSameDirection_ShouldReturnTrue() { // arrange //SETTINGS_ROUTE_DIRECTION_ANY = 0: - Not Supported Yet //SETTINGS_ROUTE_DIRECTION_IB = 1: - Not Supported Yet //SETTINGS_ROUTE_DIRECTION_OB = 2; var intersectionId = "2105"; var route = KMLHelper.GLOSATestRoute().ToList(); var gpsHistory = KMLHelper.GLOSATestRouteIntersectionHistory(intersectionId, 2); NavigationService navigationService = new NavigationService(); var waypoint = navigationService.LocateWaypointOnRoute(WaypointDetectionMethod.GPSHistoryDirection, route, gpsHistory, 0, 0); bool expectedResult = true; //act bool actualResult = waypoint != null; //assert Assert.Equal(expectedResult, actualResult); }
public void IsVehicleHeadingInSameDirectionAsLaneDirection_WithLaneInSameDirection_ShouldReturnTrue() { // arrange //SETTINGS_ROUTE_DIRECTION_NS = 1: - Not Supported Yet //SETTINGS_ROUTE_DIRECTION_SN = 2: - Not Supported Yet //SETTINGS_ROUTE_DIRECTION_EW = 3; //SETTINGS_ROUTE_DIRECTION_WE = 4; var intersectionId = "2111"; var gpsHistory = KMLHelper.GLOSATestRouteIntersectionHistory(intersectionId, 2); // Load Map from file string file = $"MAP-{Settings.IntersectionId}.xml"; MapData map = XMLHelper.LoadMAPDataFromFile(file); GLOSAResult result = GLOSAHelper.ProjectedLaneForManeuver(map, gpsHistory, 0, Constants.MANEUVER_DIRECTION_AHEAD); var lane = (MapDataIntersectionsIntersectionGeometryGenericLane)result.Object; var nodes = GLOSAHelper.ExtractTrafficNodesFromLane(lane); // Let's sort all lane nodes from MAP Ref Point var refPoint = map.intersections.IntersectionGeometry.refPoint; var mapLocation = new GPSLocation() { Latitude = refPoint.lat / Constants.MAPCoordinateIntConverterUnit, Longitude = refPoint.@long / Constants.MAPCoordinateIntConverterUnit, }; // Sort the nodes by distance ascending var sortedNodes = nodes.OrderBy(node => Distance.CalculateDistanceBetween2PointsKMs(node.GPSLocation.Latitude, node.GPSLocation.Longitude, mapLocation.Latitude, mapLocation.Longitude)).ToList(); bool expectedResult = true; //act result = GLOSAHelper.IsDirectionOfVehicleInSameDirectionAsLane(map.intersections.IntersectionGeometry.id.id, sortedNodes, 0, gpsHistory, 50, Constants.MANEUVER_DIRECTION_AHEAD); bool actualResult = result.Errors == GLOSAErrors.NoErrors; //assert Assert.Equal(expectedResult, actualResult); }
public kmlDocumentPlacemark LocateWaypointOnRoute(WaypointDetectionMethod method, List <kmlDocumentPlacemark> route, List <GPSLocation> history, double heading, int waypointIndex = 0) { kmlDocumentPlacemark nearestMAPPlacemark = null; var location = history.Last(); var sortedMAPPoints = GLOSAHelper.SortMAPKMLDataByDistanceFromCurrentLocation(route, location.Latitude, location.Longitude).ToList(); if (sortedMAPPoints != null && sortedMAPPoints.Count > 0) { if (method == WaypointDetectionMethod.ShortestDistance) { nearestMAPPlacemark = sortedMAPPoints.First(); } else if (method == WaypointDetectionMethod.DeviceHeading) { // No valid method chosen throw new Exception("Waypoint Detection Method not implemented."); } else if (method == WaypointDetectionMethod.GPSHistoryDirection) { List <TrafficNode> listOfWaypoints = new List <TrafficNode>(); GPSLocation from = history[history.Count - 2]; GPSLocation to = history[history.Count - 1]; double?vehicleBearing = LocationHelper.HeadingBetweenTwoGPSLocations(from, to); foreach (var mapPoint in sortedMAPPoints) { listOfWaypoints.Add(new TrafficNode() { GPSLocation = KMLHelper.XMLCoordinateStringToGPSLocation(mapPoint.Point.coordinates), ID = mapPoint.name, angleDiff = 0, }); } foreach (var waypoint in listOfWaypoints) { double?bearingLocationToWaypoint = LocationHelper.HeadingBetweenTwoGPSLocations(to, waypoint.GPSLocation); double delta = LocationHelper.DeltaOfVehicleToLaneDirection(vehicleBearing, bearingLocationToWaypoint); waypoint.angleDiff = Math.Abs(delta);//Make positive waypoint.distance = Distance.CalculateDistanceBetween2PointsKMs(to.Latitude, to.Longitude, waypoint.GPSLocation.Latitude, waypoint.GPSLocation.Longitude); } var sortedByBearingAndDistance = listOfWaypoints.OrderBy(wp => wp.distance) .ThenBy(wp => wp.angleDiff) .Where(wp => wp.angleDiff >= -50 && wp.angleDiff <= 50 && wp.distance <= 1.0); if (sortedByBearingAndDistance != null && sortedByBearingAndDistance.Count() > waypointIndex) { var tn = sortedByBearingAndDistance.ToList()[waypointIndex]; var pm = sortedMAPPoints.Find(mp => mp.name == tn.ID); nearestMAPPlacemark = pm; } } else { // No valid method chosen throw new Exception("Waypoint Detection Method not properly set."); } } return(nearestMAPPlacemark); }