public void UploadImage(int gameId, int teamId, double latitude, double longitude, byte[] image, string imageName = null) { if (image == null) { throw new ArgumentException("Parameter image is not provided"); } var team = GetTeamById(teamId); var currentGame = Context.Games.Single(g => g.Id == gameId); var closestNode = Context.Nodes .OrderBy(n => GeographyComputation.Distance(n.Latitude, n.Longitude, latitude, longitude)) .FirstOrDefault(); var gameAction = new GameAction() { DateOccured = DateTime.Now, Game = currentGame, Team = team, Latitude = latitude, Longitude = longitude, Picture = new Picture() { Image = image }, Action = Action.SubmitPicture, Node = closestNode }; Context.GameActions.Add(gameAction); Context.SaveChanges(); }
public void SetCenterOfGameByNodes(int gameId) { var game = Context.Games.Include(g => g.Nodes).Single(g => g.Id == gameId); var nodes = game.Nodes; var nodesPoints = nodes.Select(n => (n.Latitude, n.Longitude)); var center = GeographyComputation.CenterOfGeoPoints(nodesPoints); game.MapCenterLat = center.Item1; game.MapCenterLng = center.Item2; Context.SaveChanges(); }
public void DistanceBetweenTwoPosition() { // Arrange var point1 = (48.8501065, 2.327722); var point2 = (48.851291, 2.3318698); // Act var distance = GeographyComputation.Distance(point1, point2); // Assert Check.That(distance).IsEqualsWithDelta(331.208482931862, 0.001); }
protected virtual double ComputeDelta(GameAction gameAction) { if (gameAction.Node != null) { var delta = GeographyComputation.Distance(gameAction.Node.Latitude, gameAction.Node.Longitude, gameAction.Latitude, gameAction.Longitude); _logger.LogDebug($"Delta = {delta} for nodeId {gameAction.Node.Id}"); return(delta); } else { return(double.NaN); } }
public void CenterOfGeoPoints() { // Arrange var points = new List <(double, double)>() { (48.8501065, 2.327722), (48.851291, 2.3318698), (48.8537828, 2.3310879) }; // Act var result = GeographyComputation.CenterOfGeoPoints(points); // Assert Check.That(result.Item1).IsEqualsWithDelta(48.8517267806692, 0.001); Check.That(result.Item2).IsEqualsWithDelta(2.33022653262665, 0.001); }
/// <summary> /// Returns all the games in a specific radius (5km) /// </summary> /// <param name="lat">latitude of the point to check games for</param> /// <param name="lng">longitude of the point to check games for</param> /// <returns>List of games where the center is less than 5km from the position</returns> public IEnumerable <Game> GetGamesFromPosition(double lat, double lng) { return(Context.Games.Where(g => g.IsActive && g.MapCenterLat.HasValue && GeographyComputation.Distance(lat, lng, g.MapCenterLat.Value, g.MapCenterLng.Value) < 5000)); }