public void StandardShipEtasFromStLouisBay() { Position testPosition = ShipPositions.StLouisBay; var ship = new ShipTest { Position = testPosition, NavigationalStatus = NavigationalStatus.Underway, CanalEntryTimestamp = DateTime.UtcNow.AddHours(-6), Speed = 1 }; var directDistanceToDuluth = GeoHelper.DistanceBetweenCoord(Ports.Duluth, testPosition); var shipSideDistance = directDistanceToDuluth * Math.Sin(60d.ToRadians()); var canalSideDistance = directDistanceToDuluth * Math.Cos(60d.ToRadians()); var totalDistance = shipSideDistance + canalSideDistance; var expected = DateTime.UtcNow.AddHours(totalDistance / ship.Speed) + ShipTestProcessor.DataLag; ship.Update(); // ReSharper disable once PossibleInvalidOperationException Assert.IsTrue(expected > ship.DerivedEta.Value.AddSeconds(-1)); Assert.IsTrue(expected < ship.DerivedEta.Value.AddSeconds(1)); }
public void SuccessfulDistanceCalculationInNauticalMiles() { Assert.AreEqual( GeoHelper.DistanceBetweenCoord(TestDestination, TestShipPosition, GeoHelper.Units.NauticalMiles), ExpectedDistanceInNmi, ExpectedDistanceInNmi * DeltaPercentage ); }
public void SuccessfulDistanceCalculationInKilometers() { Assert.AreEqual( GeoHelper.DistanceBetweenCoord(TestDestination, TestShipPosition, GeoHelper.Units.KiloMeter), ExpectedDistanceInKm, ExpectedDistanceInKm * DeltaPercentage ); }
public void SuccessfulDistanceCalculationInMiles() { Assert.AreEqual( GeoHelper.DistanceBetweenCoord(TestDestination, TestShipPosition), ExpectedDistanceInMiles, ExpectedDistanceInMiles * DeltaPercentage ); }
/// <summary> /// Ships in St. Louis bay have an Eta to Duluth calculated in a specific manner, based on triangulation from St. Louis Bay. /// The method uses a 60/60/60 triangle between ship position and Duluth Canal position. /// </summary> /// <param name="shipPosition">The current coordinates of the ship.</param> /// <param name="speed">The speed of the ship.</param> /// <returns>The Eta of the ship to reach Duluth</returns> private static DateTime CalculateEtaToDuluthFromStLouisBay(Position shipPosition, double speed) { //// first, calculate the direct distance to the canal and use it as the hypotenuse of a 30/60/90 triangle var directLineDistance = GeoHelper.DistanceBetweenCoord(Ports.Duluth, shipPosition); //// next, find lengths of the opposite and adjacent sides (convert angle to radians) var shipSideDistance = directLineDistance * SinSixtyDegrees; var canalSideDistance = directLineDistance * CosSixtyDegrees; //// last, d=rt provides time to travel in hours var totalDistance = shipSideDistance + canalSideDistance; return(GetLagAdjustedDerivedEta(totalDistance, speed)); }
public void ShipEtasFromStandardLocations() { var testPosition = ShipPositions.DuluthSuperiorDeadZone; var ship = new ShipTest { Position = testPosition, NavigationalStatus = NavigationalStatus.Underway, CanalEntryTimestamp = DateTime.UtcNow.AddHours(-6), Speed = 1, Heading = 280 }; var directDistanceToDuluth = GeoHelper.DistanceBetweenCoord(Ports.Duluth, testPosition); var expected = DateTime.UtcNow.AddHours(directDistanceToDuluth / ship.Speed) + ShipTestProcessor.DataLag; ship.Update(); // ReSharper disable once PossibleInvalidOperationException Assert.IsTrue(expected > ship.DerivedEta.Value.AddSeconds(-1)); Assert.IsTrue(expected < ship.DerivedEta.Value.AddSeconds(1)); }
/// <summary> /// This method calculates the Eta of a ship to Duluth. /// </summary> /// <param name="shipPosition">The current coordinates of the ship.</param> /// <param name="speed">The speed of the ship.</param> /// <returns>The Eta of the ship to reach Duluth</returns> private static DateTime CalculateEtaToDuluth(Position shipPosition, double speed) { var directLineDistance = GeoHelper.DistanceBetweenCoord(Ports.Duluth, shipPosition); return(GetLagAdjustedDerivedEta(directLineDistance, speed)); }
/// <summary> /// Is a ship within 50 miles of the Duluth Canal? /// </summary> /// <param name="shipTest">shipTest object</param> /// <returns>true or false</returns> public static bool IsWithinFiftyMilesOfDuluth(this ShipTest shipTest) { return(GeoHelper.DistanceBetweenCoord(shipTest.Position, Ports.Duluth) <= 50); }