예제 #1
0
        //Created a new instance of a drone object
        private static Drone CreateDrone(DAL.Domain.Drone drone)
        {
            var navigationPoints = NavigationLogic.UnitOfWork.NavigationPoints.GetNaviationPoints().ToList();
            var currentPoint     = NavigationLogic.UnitOfWork.NavigationPoints.GetRandom(drone.TargetPoint.Id);
            var returnedDrone    = new Drone
            {
                Id    = drone.Id,
                Name  = drone.Name,
                Scale = new Scale
                {
                    Id        = drone.Scale.Id,
                    XPosition = drone.Scale.XSize,
                    YPosition = drone.Scale.YSize,
                    ZPosition = drone.Scale.ZSize
                },
                TargetPoint  = new NavigationPoint(drone.TargetPoint),
                CurrentPoint = new NavigationPoint(currentPoint),
                Speed        = 2f
            };

            File.AppendAllText(
                @"C:\Users\Jack\Documents\Fourth Year\Fourth Year Project\2017-ca400-murpj238\docs\blog\RandomNavigationPoints.csv",
                "Create Drone Method," + returnedDrone.TargetPoint.Id + "," + returnedDrone.TargetPoint.XPosition + "," +
                returnedDrone.TargetPoint.ZPosition + "," + returnedDrone.CurrentPoint.Id + "," +
                returnedDrone.CurrentPoint.XPosition + "," + returnedDrone.CurrentPoint.ZPosition + "\n");
            navigationPoints    = navigationPoints.Where(x => x.Id != returnedDrone.TargetPoint.Id).ToList();
            returnedDrone.Route = NavigationLogic.GenerateRoute(returnedDrone,
                                                                new List <NavigationPoint>
            {
                returnedDrone.CurrentPoint,
                returnedDrone.TargetPoint
            },
                                                                navigationPoints, 0);
            return(returnedDrone);
        }
예제 #2
0
 public static void UpdateStatistics(Statistic statistic, NavigationPoint navPoint = null)
 {
     statistic.CollisionLocation = null;
     try
     {
         if (navPoint != null)
         {
             var point = NavigationLogic.UnitOfWork.NavigationPoints.GetCollisionPoints()
                         .FirstOrDefault(x => Math.Round(x.XPosition, 2).Equals(Math.Round(navPoint.XPosition, 2)) &&
                                         Math.Round(x.ZPosition, 2).Equals(Math.Round(navPoint.ZPosition, 2)));
             if (point == null)
             {
                 var streets        = NavigationLogic.FindStreets(navPoint.XPosition, navPoint.ZPosition).ToList();
                 var collisionPoint = new NavigationPoints
                 {
                     Id = Guid.NewGuid(),
                     IsCollisionPoint = true,
                     XPosition        = navPoint.XPosition,
                     YPosition        = navPoint.YPosition,
                     ZPosition        = navPoint.ZPosition,
                     XNeighbourId     = Guid.Empty,
                     ZNeighbourId     = Guid.Empty
                 };
                 collisionPoint.Street.Add(streets.First());
                 collisionPoint.Street.Add(streets.Last());
                 statistic.CollisionLocation = collisionPoint;
             }
             else
             {
                 statistic.CollisionLocation = point;
             }
         }
         NavigationLogic.UnitOfWork.Statistics.Add(CreateStatistic(statistic));
         NavigationLogic.UnitOfWork.Complete();
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         Console.WriteLine(ex.StackTrace);
     }
 }