Skip to content

Commit

Permalink
feat(intentioncode): Dont cancel intention codes after leaving the FIR (
Browse files Browse the repository at this point in the history
#437)

* Dont remove intention code when passing exit

* Dont take point passed into account when generating code
  • Loading branch information
AndyTWF committed Mar 2, 2022
1 parent 1e57ab1 commit fed8a43
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 143 deletions.
24 changes: 0 additions & 24 deletions src/plugin/intention/IntentionCodeCache.cpp
Expand Up @@ -31,30 +31,6 @@ namespace UKControllerPlugin::IntentionCode {
this->intentionCodeMap.clear();
}

/*
Returns true if the intention code is still valid.
*/
bool IntentionCodeCache::IntentionCodeValid(const std::string& callsign, EuroscopeExtractedRouteInterface& route)
{
if (!this->HasIntentionCodeForAircraft(callsign)) {
return false;
}

// If they don't have an exit point, or they're cleared direct beyond it but aren't yet close.
if (this->intentionCodeMap[callsign].exitPointIndex == IntentionCodeData::INVALID_EXIT_POINT ||
(route.GetPointsAssignedIndex() > this->intentionCodeMap[callsign].exitPointIndex &&
route.GetPointsCalculatedIndex() <= this->intentionCodeMap[callsign].exitPointIndex)) {
return true;
}

// If they've passed their exit point, then the intention code is no longer valid.
if (route.GetPointDistanceInMinutes(this->intentionCodeMap[callsign].exitPointIndex) == this->exitPointPassed) {
return false;
}

return true;
}

/*
Registers an aircraft with the cache.
*/
Expand Down
2 changes: 0 additions & 2 deletions src/plugin/intention/IntentionCodeCache.h
Expand Up @@ -17,8 +17,6 @@ namespace UKControllerPlugin::IntentionCode {
{
public:
void Clear(void);
bool IntentionCodeValid(
const std::string& callsign, UKControllerPlugin::Euroscope::EuroscopeExtractedRouteInterface& route);
std::string GetIntentionCodeForAircraft(const std::string& callsign) const;
bool HasIntentionCodeForAircraft(const std::string& callsign) const;
auto GetDataForAircraft(const std::string& callsign) const -> IntentionCodeData;
Expand Down
3 changes: 1 addition & 2 deletions src/plugin/intention/IntentionCodeEventHandler.cpp
Expand Up @@ -79,8 +79,7 @@ namespace UKControllerPlugin::IntentionCode {
// If we have it cached, then use the cached value
const auto& flightplan = tagData.GetFlightplan();
EuroscopeExtractedRouteInterface extractedRoute = flightplan.GetExtractedRoute();
if (this->codeCache.HasIntentionCodeForAircraft(flightplan.GetCallsign()) &&
this->codeCache.IntentionCodeValid(flightplan.GetCallsign(), extractedRoute)) {
if (this->codeCache.HasIntentionCodeForAircraft(flightplan.GetCallsign())) {
tagData.SetItemString(this->codeCache.GetIntentionCodeForAircraft(flightplan.GetCallsign()));
return;
}
Expand Down
17 changes: 0 additions & 17 deletions src/plugin/intention/IntentionCodeGenerator.cpp
Expand Up @@ -50,23 +50,6 @@ namespace UKControllerPlugin::IntentionCode {
continue;
}

// If they're cleared direct beyond their SEP, but not yet close to it
// then keep the intention code for now.
if (route.GetPointsAssignedIndex() > i && route.GetPointsCalculatedIndex() <= i) {
this->SetExitIndexes(exitIndexes, i);
if (this->FoundAllExitPoints(exitIndexes)) {
return exitIndexes;
}

i++;
continue;
}

// Otherwise, if they're past the exit fix, they're not going to exit.
if (route.GetPointDistanceInMinutes(i) == this->exitPointPassed) {
return invalidExitPair;
}

this->SetExitIndexes(exitIndexes, i);
if (this->FoundAllExitPoints(exitIndexes)) {
return exitIndexes;
Expand Down
4 changes: 1 addition & 3 deletions src/plugin/intention/IntentionCodeGenerator.h
Expand Up @@ -59,9 +59,7 @@ namespace UKControllerPlugin::IntentionCode {
// Used for the exit point index when its not a valid point on the route.
static const int invalidExitPointIndex = -1;

// The pair of exit points given if they're not valid
static constexpr std::pair<int, int> invalidExitPair = {invalidExitPointIndex, invalidExitPointIndex};

// The value given to us by Euroscope if we try to find the time to a point that has been passed.
const int exitPointPassed = -1;
};
} // namespace UKControllerPlugin::IntentionCode
63 changes: 0 additions & 63 deletions test/plugin/intention/IntentionCodeCacheTest.cpp
Expand Up @@ -74,69 +74,6 @@ namespace UKControllerPluginTest::IntentionCode {
EXPECT_EQ(1, cache.TotalCached());
}

TEST(IntentionCodeCache, IntentionCodeValidReturnsFalseIfNotCached)
{
IntentionCodeCache cache;
StrictMock<MockEuroscopeExtractedRouteInterface> mockFlightplan;
EXPECT_FALSE(cache.IntentionCodeValid("BAW123", mockFlightplan));
}

TEST(IntentionCodeCache, IntentionCodeValidReturnsTrueIfNotExiting)
{
IntentionCodeCache cache;
StrictMock<MockEuroscopeExtractedRouteInterface> mockFlightplan;
cache.RegisterAircraft("BAW123", IntentionCodeData("--", -1, -1, "", ""));
EXPECT_TRUE(cache.IntentionCodeValid("BAW123", mockFlightplan));
}

TEST(IntentionCodeCache, IntentionCodeValidReturnsTrueDirectGivenExitIfNotPassed)
{
IntentionCodeCache cache;
StrictMock<MockEuroscopeExtractedRouteInterface> mockFlightplan;
EXPECT_CALL(mockFlightplan, GetPointsAssignedIndex()).Times(1).WillOnce(Return(7));

EXPECT_CALL(mockFlightplan, GetPointsCalculatedIndex()).Times(1).WillOnce(Return(4));

cache.RegisterAircraft("BAW123", IntentionCodeData("--", 5, 5, "", ""));
EXPECT_TRUE(cache.IntentionCodeValid("BAW123", mockFlightplan));
}

TEST(IntentionCodeCache, IntentionCodeValidReturnsTrueDirectGivenButCloserToExit)
{
IntentionCodeCache cache;
StrictMock<MockEuroscopeExtractedRouteInterface> mockFlightplan;
EXPECT_CALL(mockFlightplan, GetPointsAssignedIndex()).Times(1).WillOnce(Return(7));

EXPECT_CALL(mockFlightplan, GetPointsCalculatedIndex()).Times(1).WillOnce(Return(5));

cache.RegisterAircraft("BAW123", IntentionCodeData("--", 5, 5, "", ""));
EXPECT_TRUE(cache.IntentionCodeValid("BAW123", mockFlightplan));
}

TEST(IntentionCodeCache, IntentionCodeValidReturnsFalseNoDirectPointPassed)
{
IntentionCodeCache cache;
StrictMock<MockEuroscopeExtractedRouteInterface> mockFlightplan;
EXPECT_CALL(mockFlightplan, GetPointsAssignedIndex()).Times(1).WillOnce(Return(mockFlightplan.noDirect));

EXPECT_CALL(mockFlightplan, GetPointDistanceInMinutes(5)).Times(1).WillOnce(Return(mockFlightplan.pointPassed));

cache.RegisterAircraft("BAW123", IntentionCodeData("--", 5, 5, "", ""));
EXPECT_FALSE(cache.IntentionCodeValid("BAW123", mockFlightplan));
}

TEST(IntentionCodeCache, IntentionCodeValidReturnsTrueNoDirectPointNotPassed)
{
IntentionCodeCache cache;
StrictMock<MockEuroscopeExtractedRouteInterface> mockFlightplan;
EXPECT_CALL(mockFlightplan, GetPointsAssignedIndex()).Times(1).WillOnce(Return(mockFlightplan.noDirect));

EXPECT_CALL(mockFlightplan, GetPointDistanceInMinutes(5)).Times(1).WillOnce(Return(999));

cache.RegisterAircraft("BAW123", IntentionCodeData("--", 5, 5, "", ""));
EXPECT_TRUE(cache.IntentionCodeValid("BAW123", mockFlightplan));
}

TEST(IntentionCodeCache, ClearCacheEmptiesCache)
{
IntentionCodeCache cache;
Expand Down
32 changes: 0 additions & 32 deletions test/plugin/intention/IntentionCodeGeneratorTest.cpp
Expand Up @@ -381,36 +381,4 @@ namespace UKControllerPluginTest::IntentionCode {
EXPECT_EQ("", data.exitPoint);
EXPECT_EQ("", data.ukExitPoint);
}

TEST_F(IntentionCodeGeneratorTest, GetIntentionCodeReturnsIcaoIfPointPassed)
{
NiceMock<MockEuroscopeExtractedRouteInterface> mockFlightPlan;
std::vector<std::unique_ptr<AirfieldGroup>> groups;

ON_CALL(mockFlightPlan, GetPointsNumber()).WillByDefault(Return(3));

ON_CALL(mockFlightPlan, GetPointName(0)).WillByDefault(Return("EGLL"));

ON_CALL(mockFlightPlan, GetPointName(1)).WillByDefault(Return("BAKUR"));

ON_CALL(mockFlightPlan, GetPointName(2)).WillByDefault(Return("KLAS"));

ON_CALL(mockFlightPlan, GetPointPosition(1)).WillByDefault(Return(exitPositionWest));

ON_CALL(mockFlightPlan, GetPointPosition(2)).WillByDefault(Return(nextFixPositonWest));

EXPECT_CALL(mockFlightPlan, GetPointDistanceInMinutes(1)).Times(1).WillOnce(Return(-1));

EXPECT_CALL(mockFlightPlan, GetPointsAssignedIndex()).Times(1).WillOnce(Return(-1));

std::unique_ptr<SectorExitRepository> exitPoints = SectorExitRepositoryFactory::Create();
IntentionCodeGenerator intention(std::move(groups), *exitPoints);
IntentionCodeData data =
intention.GetIntentionCodeForFlightplan("BAW123", "EGLL", "KLAS", mockFlightPlan, 33000);
EXPECT_TRUE(data.intentionCode == "KLAS");
EXPECT_EQ(IntentionCodeData::INVALID_EXIT_POINT, data.exitPointIndex);
EXPECT_EQ(IntentionCodeData::INVALID_EXIT_POINT, data.ukExitPointIndex);
EXPECT_EQ("", data.exitPoint);
EXPECT_EQ("", data.ukExitPoint);
}
} // namespace UKControllerPluginTest::IntentionCode

0 comments on commit fed8a43

Please sign in to comment.