static void Main(string[] args) { Console.WriteLine((Math.Sin(MeasureConverter.ConvertDegreeToRadian(210)))); Console.WriteLine(MeasureConverter.ConvertRadiansToDegrees(Math.Asin(-0.5))); AircraftIdData testData = new AircraftIdData(); //AirTrafficController testController = new AirTrafficController(TrafficControllerType.Approach); var testPilot = new Person("ivan"); Airport testDeparturePort = new Airport("testAirport", new Position3D(0, 0, 1), new Person("disp")); Airport testArrivalPort = new Airport("testAirport2", new Position3D(10, 10, 1), new Person("disp")); Airport newAirport = new Airport("John F. Kennedy International Airport", new Position3D(-90.9187999m, 46.5482781m, 251), new Person("John Kennedy")); FlightRoute testRoute = new FlightRoute(); testRoute.AddFix(new AirspaceFix(new Position3D(2, 2, 2), false, false)); FlightPlan testPlan = new FlightPlan(testDeparturePort, testArrivalPort, new DateTime(), new DateTime(), 10000, testRoute, 100, FlightType.Cargo); Aircraft testAircraft = new Aircraft(testData, 45); var flight = new Flight(testAircraft, testPilot, testPlan, "7382"); Console.WriteLine(flight.CurrentPosition); while (true) { flight.UpdatePosition(); Console.WriteLine(flight.CurrentPosition); System.Threading.Thread.Sleep(3000); } }
public void WhenConvertingWithProjectMeausreShouldAppendProjectMeasure() { this.measureConverter = new MeasureConverter <int>(new DateTime(2018, 9, 17), new DateTime(2018, 9, 18), metric, mockMeasureAggregatorProject.Object, "//prefix/"); var dailyCodeChurn1 = new DailyCodeChurn() { Timestamp = "2018/09/17 00:00:00", FileName = "file1", Added = 10, Deleted = 10 }; var dailyCodeChurn2 = new DailyCodeChurn() { Timestamp = "2018/09/17 00:00:00", FileName = "file2", Added = 5, Deleted = 5 }; var measures = new SonarMeasuresJson(); this.measureConverter.ProcessProjectMeasure(measures); this.measureConverter.ProcessProjectMeasure(measures); Assert.Single(measures.MeasuresProject.Where(m => m.MetricKey == "key")); }
public GivenAMeasureConverter() { metric = new Metric(); metric.MetricKey = "key"; this.mockMeasureAggregator = new Mock <IMeasureAggregator <int> >(); this.mockMeasureAggregator.Setup(m => m.HasValue(It.IsAny <DailyCodeChurn>())). Returns((DailyCodeChurn d) => d.TotalLinesChanged > 0); this.mockMeasureAggregator.Setup(m => m.GetValueForNewMeasure(It.IsAny <DailyCodeChurn>())). Returns((DailyCodeChurn d) => d.TotalLinesChanged); this.mockMeasureAggregator.Setup(m => m.GetValueForExistingMeasure(It.IsAny <DailyCodeChurn>(), It.IsAny <Measure <int> >())). Returns((DailyCodeChurn d, Measure <int> existingMeasure) => d.TotalLinesChanged + existingMeasure.Value); this.mockMeasureAggregatorProject = new Mock <IMeasureAggregatorProject <int> >(); this.mockMeasureAggregatorProject.Setup(m => m.HasValue(It.IsAny <DailyCodeChurn>())). Returns((DailyCodeChurn d) => d.TotalLinesChanged > 0); this.mockMeasureAggregatorProject.Setup(m => m.GetValueForNewMeasure(It.IsAny <DailyCodeChurn>())). Returns((DailyCodeChurn d) => d.TotalLinesChanged); this.mockMeasureAggregatorProject.Setup(m => m.GetValueForExistingMeasure(It.IsAny <DailyCodeChurn>(), It.IsAny <Measure <int> >())). Returns((DailyCodeChurn d, Measure <int> existingMeasure) => d.TotalLinesChanged + existingMeasure.Value); this.mockMeasureAggregatorProject.Setup(m => m.GetValueForProjectMeasure()). Returns(0); this.measureConverter = new MeasureConverter <int>(new DateTime(2018, 9, 17), new DateTime(2018, 9, 18), metric, mockMeasureAggregator.Object, "//prefix/"); }
protected override bool UpdateValueCore(string name, string value, UndoRedoRecorder recorder) { if (name == "Value") { var converter = new MeasureConverter(); this.Value = ((double)converter.ConvertBack(value, typeof(double), Measure, null)); return(true); // UpdateValueCore handled. } return(base.UpdateValueCore(name, value, recorder)); }
/// <summary> /// Generates the measures for the song to use. /// </summary> /// <returns>Byte representation of the measure track.</returns> private byte[] generateMeasure() { MeasureConverter converter = new MeasureConverter(); List <MID2RIF.MeasureConverter.Measure> measures = converter.measures; List <byte> outByte = new List <byte>(); outByte.Add(0x00); outByte.Add(0x00); outByte.Add(0x00); outByte.Add(0x04); outByte.Add(0x00); outByte.Add(0x00); outByte.Add(0x00); outByte.Add(0x0c); int numEntries = measures.Count; byte[] numEntries_byte = BitConverter.GetBytes(numEntries).Reverse().ToArray(); outByte.Add(numEntries_byte[0]); outByte.Add(numEntries_byte[1]); outByte.Add(numEntries_byte[2]); outByte.Add(numEntries_byte[3]); outByte.Add(0x00); outByte.Add(0x00); outByte.Add(0x00); outByte.Add(0x04); foreach (MID2RIF.MeasureConverter.Measure measure in measures) { byte[] start = BitConverter.GetBytes((float)measure.start).Reverse().ToArray(); for (int i = 0; i < start.Length; i++) { outByte.Add(start[i]); } for (int i = 0; i < start.Length; i++) { outByte.Add(start[i]); } byte[] upDown = BitConverter.GetBytes((float)measure.upDown).Reverse().ToArray(); for (int i = 0; i < upDown.Length; i++) { outByte.Add(upDown[i]); } } return(outByte.ToArray()); }
protected override bool UpdateValueCore(UpdateValueParams updateValueParams) { string name = updateValueParams.PropertyName; string value = updateValueParams.PropertyValue; if (name == "Value") { var converter = new MeasureConverter(); this.Value = ((double)converter.ConvertBack(value, typeof(double), Measure, null)); return(true); // UpdateValueCore handled. } return(base.UpdateValueCore(updateValueParams)); }
/// <summary> /// Method responsible for updating the position of aircraft at a certain time. /// </summary> public void UpdatePosition() { this.CurrentHeadingInDegrees = CalculateCurrentHeading(FlightPlan.PreplannedRoute.GetNextFix().Coordinates); double currentHeadingInRadians = MeasureConverter.ConvertDegreeToRadian(CurrentHeadingInDegrees); decimal newLongitude = CurrentPosition.Longitude; decimal newLatitude = CurrentPosition.Latitude; DateTime currentDateTime = DateTime.Now; double secondsElapsed = (currentDateTime - lastUpdated).Seconds; double distanceElapsed = secondsElapsed * CurrentSpeed / 3600; // to convert NM/h to NM/s newLongitude += (decimal)(distanceElapsed * Math.Sin(currentHeadingInRadians)); newLatitude += (decimal)(distanceElapsed * Math.Cos(currentHeadingInRadians)); this.CurrentPosition = new Position3D(newLongitude, newLatitude, CurrentPosition.Altitude); lastUpdated = currentDateTime; }
public void WhenConvertingWithinRangeAndNoFilePrefixShouldConvert() { this.measureConverter = new MeasureConverter <int>(new DateTime(2018, 9, 17), new DateTime(2018, 9, 18), metric, mockMeasureAggregator.Object, null); var dailyCodeChurn = new DailyCodeChurn() { Timestamp = "2018/09/17 00:00:00", FileName = "//prefix/file", Added = 10, Deleted = 10 }; var measures = new SonarMeasuresJson(); this.measureConverter.ProcessFileMeasure(dailyCodeChurn, measures); Assert.Equal("//prefix/file", measures.Measures.Where(m => m.MetricKey == "key").Single().File); }
public int CalculateCurrentHeading(Position3D nextPosition) { int updatedHeading = 0; if (CurrentPosition.Longitude < nextPosition.Longitude) { double longitudeDifference = (CurrentPosition.LongitudeInNauticalMiles - nextPosition.LongitudeInNauticalMiles); double latitudeDifference = (CurrentPosition.LatitudeInNauticalMiles - nextPosition.LatitudeInNauticalMiles); double distanceBetweenPoints = Math.Sqrt(longitudeDifference * longitudeDifference + latitudeDifference * latitudeDifference); updatedHeading = (int)MeasureConverter.ConvertRadiansToDegrees(( Math.Asin(Math.Abs(longitudeDifference) / distanceBetweenPoints))); if (longitudeDifference > 0) { updatedHeading = updatedHeading + 180; } } return(updatedHeading); }