public PositionEstimation(List <NeighbourPosition> neighbourPositions, bool useDistance) { if (!useDistance) { NeighbourPositions = neighbourPositions.Where(position => position.Score > 0).ToList(); var zonesScores = NeighbourPositions.GroupBy(neighbourPosition => neighbourPosition.Position.ZoneId) .Select(group => new { ZoneId = group.Key, Weight = group.Count() }) .ToList(); if (NeighbourPositions.Count > 0) { var totalScore = NeighbourPositions.Sum(neighbour => neighbour.Score * zonesScores.FirstOrDefault(zone => zone.ZoneId == neighbour.Position.ZoneId).Weight); NeighbourPositions.ForEach(position => { X += position.Position.X * position.Score * zonesScores.FirstOrDefault(zone => zone.ZoneId == position.Position.ZoneId).Weight; Y += position.Position.Y * position.Score * zonesScores.FirstOrDefault(zone => zone.ZoneId == position.Position.ZoneId).Weight; }); X = X / totalScore; Y = Y / totalScore; } } else { NeighbourPositions = neighbourPositions; var zonesScores = neighbourPositions.GroupBy(neighbourPosition => neighbourPosition.Position.ZoneId) .Select(group => new { ZoneId = group.Key, Weight = group.Count() }) .ToList(); if (NeighbourPositions.Count > 0) { var totalScore = NeighbourPositions.Sum(neighbour => 1 / neighbour.Distance * zonesScores.FirstOrDefault(zone => zone.ZoneId == neighbour.Position.ZoneId).Weight); NeighbourPositions.ForEach(position => { X += position.Position.X * 1 / position.Distance * zonesScores.FirstOrDefault(zone => zone.ZoneId == position.Position.ZoneId).Weight; Y += position.Position.Y * 1 / position.Distance * zonesScores.FirstOrDefault(zone => zone.ZoneId == position.Position.ZoneId).Weight; }); X = X / totalScore; Y = Y / totalScore; } } NeighbourPositions.ForEach(neighbour => { neighbour.Position.Calibrations = null; neighbour.Position.PositionSignalData = null; neighbour.Position.Zone.Positions = null; neighbour.Position.Zone.Locale = null; }); }
private Vector2 GetNeighbourPosition(NeighbourPositions Pos) { Vector2 Position = new Vector2(); switch (Pos) { case NeighbourPositions.TopLeft: Position.X = NodePosition.X - 1; Position.Y = NodePosition.Y - 1; break; case NeighbourPositions.Top: Position.X = NodePosition.X; Position.Y = NodePosition.Y - 1; break; case NeighbourPositions.TopRight: Position.X = NodePosition.X + 1; Position.Y = NodePosition.Y - 1; break; case NeighbourPositions.Left: Position.X = NodePosition.X - 1; Position.Y = NodePosition.Y; break; case NeighbourPositions.Right: Position.X = NodePosition.X + 1; Position.Y = NodePosition.Y; break; case NeighbourPositions.BottomLeft: Position.X = NodePosition.X - 1; Position.Y = NodePosition.Y + 1; break; case NeighbourPositions.Bottom: Position.X = NodePosition.X; Position.Y = NodePosition.Y + 1; break; case NeighbourPositions.BottomRight: Position.X = NodePosition.X + 1; Position.Y = NodePosition.Y + 1; break; } return Position; }