-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f46a90d
commit 3db585b
Showing
6 changed files
with
118 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 32 additions & 28 deletions
60
src/QSP/RouteFinding/FileExport/Providers/Ifly737Provider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,57 @@ | ||
using QSP.RouteFinding.Airports; | ||
using QSP.MathTools; | ||
using QSP.RouteFinding.Routes; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using static CommonLibrary.LibraryExtension.Types; | ||
using static System.Linq.Enumerable; | ||
|
||
namespace QSP.RouteFinding.FileExport.Providers | ||
{ | ||
// TODO: Add test. | ||
public static class Ifly737Provider | ||
{ | ||
public static string GetExportText(Route route, AirportManager airports) | ||
// In the waypoint part, each line contain a waypoint. Let's say the | ||
// waypoint is B, and the previous waypoint is A. The line contains A also | ||
// contains a true heading. If you fly a great circle route from A to B, you | ||
// will have true heading equal to that value. | ||
|
||
public static string GetExportText(Route route) | ||
{ | ||
if (route.Count < 2) throw new ArgumentException(); | ||
var linesPart1 = List( | ||
route.FirstWaypoint.ID.Substring(0, 4), | ||
route.FirstWaypoint.ID.Substring(4), | ||
route.LastWaypoint.ID.Substring(0, 4) | ||
route.LastWaypoint.ID.Substring(0, 4), | ||
route.FirstWaypoint.ID.Substring(4) | ||
).Concat(Repeat("", 7)) | ||
.Concat(List("-1", "", "", "", "", "0")); | ||
|
||
var node = route.First.Next; | ||
var part2 = List(("DIRECT", node.Value.Waypoint)); | ||
node = node.Next; | ||
var linesPart2 = new List<string>(); | ||
var prev = route.First; | ||
var current = prev.Next; | ||
|
||
while (node != null) | ||
while (current != route.Last) | ||
{ | ||
var a = node.Previous.Value.Neighbor.Airway; | ||
var airway = a == "DCT" ? "DIRECT" : a; | ||
part2.Add((a, node.Value.Waypoint)); | ||
node = node.Next; | ||
var airway = prev.Value.Neighbor.Airway; | ||
bool isDirect = (prev == route.First) || (airway == "DCT"); | ||
|
||
var w = current.Value.Waypoint; | ||
var heading = EarthGeometry.TrueHeading(prev.Value.Waypoint, w); | ||
|
||
linesPart2.Add(string.Format( | ||
"{0},{1},0, {2} {3},0,0, {4},0,0,1,-1,0.000,0,-1000,-1000,-1,-1,-1,0,0,000.00000,0,0,,-1000,-1,-1,-1000,0,-1000,-1,-1,-1000,0,-1000,-1,-1,-1000,0,-1000,-1,-1,-1000,0,-1000,-1000,0", | ||
isDirect ? "DIRECT,3" : $"{airway},2", | ||
w.ID, | ||
w.Lat.ToString("###0.000000"), | ||
w.Lon.ToString("###0.000000"), | ||
heading.ToString("###0.00000"))); | ||
|
||
prev = current; | ||
current = current.Next; | ||
} | ||
|
||
var linesPart2 = part2.Select(v => | ||
{ | ||
var (airway, wpt) = v; | ||
var words = List( | ||
airway, | ||
airway == "DIRECT" ? "3" : "2", | ||
wpt.ID, | ||
string.Format("{0} {1}", wpt.Lat, wpt.Lon), | ||
"0", | ||
"0", | ||
"Put heading here"); //TODO: calculate true heading towards next wpt | ||
return string.Join(",", words) + | ||
",0,0,1,-1,0.000,0,-1000,-1000,-1,-1,-1,0,0,000.00000,0,0,,-1000,-1,-1,-1000,0,-1000,-1,-1,-1000,0,-1000,-1,-1,-1000,0,-1000,-1,-1,-1000,0,-1000,-1000,0"; | ||
}); | ||
linesPart2.Add(""); | ||
|
||
return string.Join(",\n", linesPart1.Concat(linesPart2)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/Tests/UnitTest/RouteFinding/FileExport/Providers/Ifly737ProviderTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using CommonLibrary.LibraryExtension; | ||
using NUnit.Framework; | ||
using QSP.RouteFinding.Containers; | ||
using QSP.RouteFinding.FileExport.Providers; | ||
|
||
namespace UnitTest.RouteFinding.FileExport.Providers | ||
{ | ||
[TestFixture] | ||
public class Ifly737ProviderTest | ||
{ | ||
[Test] | ||
public void GetExportTextTest() | ||
{ | ||
var route = Common.GetRoute( | ||
new Waypoint("RJBB06L", 0.0, 0.0), "A", -1.0, | ||
new Waypoint("WPT0", 0.0, 1.0), "B", -1.0, | ||
new Waypoint("WPT1", 0.0, 2.0), "DCT", -1.0, | ||
new Waypoint("WPT2", 0.0, 2.5), "C", -1.0, | ||
new Waypoint("RJAA18", 0.0, 3.0)); | ||
|
||
var text = Ifly737Provider.GetExportText(route); | ||
|
||
var expected = | ||
@"RJBB, | ||
RJAA, | ||
06L, | ||
, | ||
, | ||
, | ||
, | ||
, | ||
, | ||
, | ||
-1, | ||
, | ||
, | ||
, | ||
, | ||
0, | ||
DIRECT,3,WPT0,0, 0.000000 1.000000,0,0, 90.00000,0,0,1,-1,0.000,0,-1000,-1000,-1,-1,-1,0,0,000.00000,0,0,,-1000,-1,-1,-1000,0,-1000,-1,-1,-1000,0,-1000,-1,-1,-1000,0,-1000,-1,-1,-1000,0,-1000,-1000,0, | ||
B,2,WPT1,0, 0.000000 2.000000,0,0, 90.00000,0,0,1,-1,0.000,0,-1000,-1000,-1,-1,-1,0,0,000.00000,0,0,,-1000,-1,-1,-1000,0,-1000,-1,-1,-1000,0,-1000,-1,-1,-1000,0,-1000,-1,-1,-1000,0,-1000,-1000,0, | ||
DIRECT,3,WPT2,0, 0.000000 2.500000,0,0, 90.00000,0,0,1,-1,0.000,0,-1000,-1000,-1,-1,-1,0,0,000.00000,0,0,,-1000,-1,-1,-1000,0,-1000,-1,-1,-1000,0,-1000,-1,-1,-1000,0,-1000,-1,-1,-1000,0,-1000,-1000,0, | ||
"; | ||
|
||
Assert.IsTrue(expected.EqualsIgnoreNewlineStyle(text)); | ||
} | ||
|
||
[Test] | ||
public void GetExportTextNoWaypontDoesNotThrow() | ||
{ | ||
var route = Common.GetRoute( | ||
new Waypoint("RJBB06L", 0.0, 0.0), "DCT", -1.0, | ||
new Waypoint("RJAA18", 0.0, 3.0)); | ||
|
||
var text = Ifly737Provider.GetExportText(route); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters