Skip to content

Commit 4202e00

Browse files
author
Andy Ford
authored
Merge pull request #10 from ECFMP/event-participant-parsing
feat: event participation parsing
2 parents 71f3957 + 5fe9312 commit 4202e00

12 files changed

Lines changed: 104 additions & 21 deletions

include/ECFMP/event/Event.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace ECFMP::Event {
1515
/**
1616
* The id of the event in the API.
1717
*/
18-
[[nodiscard]] virtual auto Id() const noexcept -> int = 0;
18+
[[nodiscard]] auto Id() const noexcept -> int override = 0;
1919

2020
/**
2121
* Returns the name of the event.
@@ -43,11 +43,14 @@ namespace ECFMP::Event {
4343
*/
4444
[[nodiscard]] virtual auto VatcanCode() const noexcept -> const std::string& = 0;
4545

46+
/**
47+
* Returns the participants of the event.
48+
*/
49+
[[nodiscard]] virtual auto Participants() const -> const std::vector<std::shared_ptr<EventParticipant>>& = 0;
50+
4651
/**
4752
* Compares events.
4853
*/
4954
[[nodiscard]] auto operator==(const class Event& event) const -> bool;
50-
51-
// TODO: Event participants
5255
};
5356
}// namespace ECFMP::Event

include/mock/EventMock.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ namespace ECFMP::Mock::Event {
1616
(const, noexcept, override)
1717
);
1818
MOCK_METHOD(const std::string&, VatcanCode, (), (const, noexcept, override));
19+
MOCK_METHOD(
20+
const std::vector<std::shared_ptr<ECFMP::Event::EventParticipant>>&, Participants, (),
21+
(const, noexcept, override)
22+
);
1923
};
2024

2125
}// namespace ECFMP::Mock::Event

src/api/EventDataParser.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#include "EventDataParser.h"
22
#include "ConcreteApiElementCollection.h"
3+
#include "ECFMP/event/EventParticipant.h"
34
#include "ECFMP/log/Logger.h"
45
#include "date/ParseDateStrings.h"
56
#include "event/ConcreteEvent.h"
7+
#include "event/ConcreteEventParticipant.h"
68
#include "nlohmann/json.hpp"
79

810
namespace ECFMP::Api {
@@ -29,12 +31,23 @@ namespace ECFMP::Api {
2931
continue;
3032
}
3133

34+
// Parse participants
35+
std::vector<std::shared_ptr<Event::EventParticipant>> participants;
36+
for (const auto& participant: event.at("participants")) {
37+
participants.push_back(std::make_shared<Event::ConcreteEventParticipant>(
38+
participant.at("cid").get<int>(),
39+
participant.at("origin").is_string() ? participant.at("origin").get<std::string>() : "",
40+
participant.at("destination").is_string() ? participant.at("destination").get<std::string>()
41+
: ""
42+
));
43+
}
44+
3245
events->Add(std::make_shared<Event::ConcreteEvent>(
3346
event.at("id").get<int>(), event.at("name").get<std::string>(),
3447
Date::TimePointFromDateString(event.at("date_start").get<std::string>()),
3548
Date::TimePointFromDateString(event.at("date_end").get<std::string>()),
3649
firs.Get(event.at("flight_information_region_id").get<int>()),
37-
event.at("vatcan_code").is_null() ? "" : event.at("vatcan_code").get<std::string>()
50+
event.at("vatcan_code").is_null() ? "" : event.at("vatcan_code").get<std::string>(), participants
3851
));
3952
}
4053

src/api/EventDataParser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace ECFMP::Api {
1010
class EventDataParser : public EventDataParserInterface
1111
{
1212
public:
13-
EventDataParser(std::shared_ptr<Log::Logger> logger);
13+
explicit EventDataParser(std::shared_ptr<Log::Logger> logger);
1414
[[nodiscard]] auto
1515
ParseEvents(const nlohmann::json& data, const InternalFlightInformationRegionCollection& firs)
1616
-> std::shared_ptr<InternalEventCollection> override;

src/event/ConcreteEvent.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ namespace ECFMP::Event {
55
ConcreteEvent::ConcreteEvent(
66
int id, std::string name, std::chrono::system_clock::time_point start,
77
std::chrono::system_clock::time_point end,
8-
std::shared_ptr<const FlightInformationRegion::FlightInformationRegion> fir, std::string vatcanCode
8+
std::shared_ptr<const FlightInformationRegion::FlightInformationRegion> fir, std::string vatcanCode,
9+
std::vector<std::shared_ptr<EventParticipant>> participants
910
)
10-
: id(id), name(std::move(name)), start(start), end(end), fir(fir), vatcanCode(std::move(vatcanCode))
11+
: id(id), name(std::move(name)), start(start), end(end), fir(fir), vatcanCode(std::move(vatcanCode)),
12+
participants(std::move(participants))
1113
{
1214
assert(fir && "flight information region not set in event");
1315
}
@@ -42,4 +44,9 @@ namespace ECFMP::Event {
4244
{
4345
return vatcanCode;
4446
}
47+
48+
auto ConcreteEvent::Participants() const -> const std::vector<std::shared_ptr<EventParticipant>>&
49+
{
50+
return participants;
51+
}
4552
}// namespace ECFMP::Event

src/event/ConcreteEvent.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ namespace ECFMP::Event {
1212
ConcreteEvent(
1313
int id, std::string name, std::chrono::system_clock::time_point start,
1414
std::chrono::system_clock::time_point end,
15-
std::shared_ptr<const FlightInformationRegion::FlightInformationRegion> fir, std::string vatcanCode
15+
std::shared_ptr<const FlightInformationRegion::FlightInformationRegion> fir, std::string vatcanCode,
16+
std::vector<std::shared_ptr<EventParticipant>> participants
1617
);
1718
[[nodiscard]] auto Id() const noexcept -> int override;
1819
[[nodiscard]] auto Name() const noexcept -> const std::string& override;
@@ -21,6 +22,7 @@ namespace ECFMP::Event {
2122
[[nodiscard]] auto FlightInformationRegion() const noexcept
2223
-> const FlightInformationRegion::FlightInformationRegion& override;
2324
[[nodiscard]] auto VatcanCode() const noexcept -> const std::string& override;
25+
[[nodiscard]] auto Participants() const -> const std::vector<std::shared_ptr<EventParticipant>>& override;
2426

2527
private:
2628
// Api event id
@@ -40,5 +42,8 @@ namespace ECFMP::Event {
4042

4143
// Code for the vatcan code
4244
std::string vatcanCode;
45+
46+
// The participants
47+
std::vector<std::shared_ptr<EventParticipant>> participants;
4348
};
4449
}// namespace ECFMP::Event

test/api/EventDataParserTest.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ namespace ECFMPTest::Api {
9797
EXPECT_EQ(ECFMP::Date::TimePointFromDateString("2022-04-16T13:16:00Z"), event1->Start());
9898
EXPECT_EQ(ECFMP::Date::TimePointFromDateString("2022-04-16T13:17:00Z"), event1->End());
9999
EXPECT_EQ("abc", event1->VatcanCode());
100+
auto event1Participants = event1->Participants();
101+
EXPECT_EQ(2, event1Participants.size());
102+
const auto event1Participant1 = event1Participants[0];
103+
EXPECT_EQ(1203533, event1Participant1->Cid());
104+
EXPECT_EQ("EGKK", event1Participant1->OriginAirport());
105+
EXPECT_EQ("EGLL", event1Participant1->DestinationAirport());
106+
const auto event1Participant2 = event1Participants[1];
107+
EXPECT_EQ(1203534, event1Participant2->Cid());
108+
EXPECT_EQ("EGKK", event1Participant2->OriginAirport());
109+
EXPECT_EQ("EGLL", event1Participant2->DestinationAirport());
100110

101111
const auto event2 = events->Get(2);
102112
EXPECT_EQ(2, event2->Id());
@@ -105,6 +115,16 @@ namespace ECFMPTest::Api {
105115
EXPECT_EQ(ECFMP::Date::TimePointFromDateString("2022-04-17T13:16:00Z"), event2->Start());
106116
EXPECT_EQ(ECFMP::Date::TimePointFromDateString("2022-04-18T13:17:00Z"), event2->End());
107117
EXPECT_EQ("def", event2->VatcanCode());
118+
auto event2Participants = event2->Participants();
119+
EXPECT_EQ(2, event2Participants.size());
120+
const auto event2Participant1 = event2Participants[0];
121+
EXPECT_EQ(1203535, event2Participant1->Cid());
122+
EXPECT_EQ("EGLL", event2Participant1->OriginAirport());
123+
EXPECT_EQ("EGCC", event2Participant1->DestinationAirport());
124+
const auto event2Participant2 = event2Participants[1];
125+
EXPECT_EQ(1203536, event2Participant2->Cid());
126+
EXPECT_EQ("EGCC", event2Participant2->OriginAirport());
127+
EXPECT_EQ("EGPH", event2Participant2->DestinationAirport());
108128
}
109129

110130
TEST_F(EventDataParserTest, ItParsesEventsWithNoParticipants)
@@ -266,6 +286,14 @@ namespace ECFMPTest::Api {
266286
EXPECT_EQ(ECFMP::Date::TimePointFromDateString("2022-04-16T13:16:00Z"), event1->Start());
267287
EXPECT_EQ(ECFMP::Date::TimePointFromDateString("2022-04-16T13:17:00Z"), event1->End());
268288
EXPECT_EQ("abc", event1->VatcanCode());
289+
auto event1Participants = event1->Participants();
290+
EXPECT_EQ(2, event1Participants.size());
291+
EXPECT_EQ(1203533, event1Participants[0]->Cid());
292+
EXPECT_EQ("", event1Participants[0]->OriginAirport());
293+
EXPECT_EQ("", event1Participants[0]->DestinationAirport());
294+
EXPECT_EQ(1203534, event1Participants[1]->Cid());
295+
EXPECT_EQ("", event1Participants[1]->OriginAirport());
296+
EXPECT_EQ("", event1Participants[1]->DestinationAirport());
269297

270298
const auto event2 = events->Get(2);
271299
EXPECT_EQ(2, event2->Id());
@@ -274,6 +302,14 @@ namespace ECFMPTest::Api {
274302
EXPECT_EQ(ECFMP::Date::TimePointFromDateString("2022-04-17T13:16:00Z"), event2->Start());
275303
EXPECT_EQ(ECFMP::Date::TimePointFromDateString("2022-04-18T13:17:00Z"), event2->End());
276304
EXPECT_EQ("def", event2->VatcanCode());
305+
auto event2Participants = event2->Participants();
306+
EXPECT_EQ(2, event2Participants.size());
307+
EXPECT_EQ(1203535, event2Participants[0]->Cid());
308+
EXPECT_EQ("", event2Participants[0]->OriginAirport());
309+
EXPECT_EQ("", event2Participants[0]->DestinationAirport());
310+
EXPECT_EQ(1203536, event2Participants[1]->Cid());
311+
EXPECT_EQ("", event2Participants[1]->OriginAirport());
312+
EXPECT_EQ("", event2Participants[1]->DestinationAirport());
277313
}
278314

279315
using BadEventDataCheck = struct BadEventDataCheck {

test/api/FlowMeasureDataParserTest.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ namespace ECFMPTest::Api {
7979
2, "EGPX", "Scottish"
8080
));
8181

82-
events.Add(
83-
std::make_shared<ECFMP::Event::ConcreteEvent>(1, "Test event", now, plusOneHour, firs.Get(1), "abc")
84-
);
82+
events.Add(std::make_shared<ECFMP::Event::ConcreteEvent>(
83+
1, "Test event", now, plusOneHour, firs.Get(1), "abc",
84+
std::vector<std::shared_ptr<ECFMP::Event::EventParticipant>>{}
85+
));
8586
}
8687

8788
MockFlowMeasureFilterParser* filterParserRaw;
@@ -284,9 +285,10 @@ namespace ECFMPTest::Api {
284285
2, "EGPX", "Scottish"
285286
));
286287

287-
events.Add(
288-
std::make_shared<ECFMP::Event::ConcreteEvent>(1, "Test event", now, plusOneHour, firs.Get(1), "abc")
289-
);
288+
events.Add(std::make_shared<ECFMP::Event::ConcreteEvent>(
289+
1, "Test event", now, plusOneHour, firs.Get(1), "abc",
290+
std::vector<std::shared_ptr<ECFMP::Event::EventParticipant>>{}
291+
));
290292
}
291293

292294
MockFlowMeasureFilterParser* filterParserRaw;

test/event/ConcreteEventTest.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "event/ConcreteEvent.h"
2+
#include "ECFMP/event/EventParticipant.h"
3+
#include "event/ConcreteEventParticipant.h"
24
#include "flightinformationregion/ConcreteFlightInformationRegion.h"
5+
#include <vector>
36

47
using ECFMP::Event::ConcreteEvent;
58
using ECFMP::FlightInformationRegion::ConcreteFlightInformationRegion;
@@ -12,13 +15,17 @@ namespace ECFMPTest::Event {
1215
: start(std::chrono::system_clock::now()),
1316
end(std::chrono::system_clock::now() + std::chrono::minutes(123)),
1417
fir(std::make_shared<ConcreteFlightInformationRegion>(1, "EGTT", "London")),
15-
event(1, "Some event", start, end, fir, "VATCAN")
18+
participant(std::make_shared<ECFMP::Event::ConcreteEventParticipant>(1, "ABC", "DEF")),
19+
participants({participant}), event(1, "Some event", start, end, fir, "VATCAN", participants)
1620
{}
1721

1822
// 1666803606
1923
std::chrono::system_clock::time_point start;
2024
std::chrono::system_clock::time_point end;
2125
std::shared_ptr<ConcreteFlightInformationRegion> fir;
26+
27+
std::shared_ptr<ECFMP::Event::EventParticipant> participant;
28+
std::vector<std::shared_ptr<ECFMP::Event::EventParticipant>> participants;
2229
ConcreteEvent event;
2330
};
2431

@@ -54,9 +61,14 @@ namespace ECFMPTest::Event {
5461

5562
TEST_F(ConcreteEventTest, ItChecksEquality)
5663
{
57-
ConcreteEvent event2(1, "Some event", start, end, fir, "VATCAN");
58-
ConcreteEvent event3(2, "Some event2", start, end, fir, "VATCAN");
64+
ConcreteEvent event2(1, "Some event", start, end, fir, "VATCAN", participants);
65+
ConcreteEvent event3(2, "Some event2", start, end, fir, "VATCAN", participants);
5966
EXPECT_EQ(event2, event);
6067
EXPECT_NE(event3, event);
6168
}
69+
70+
TEST_F(ConcreteEventTest, ItHasParticipants)
71+
{
72+
EXPECT_EQ(participants, event.Participants());
73+
}
6274
}// namespace ECFMPTest::Event

test/flowmeasure/ConcreteEventFilterTest.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ namespace ECFMPTest::FlowMeasure {
1111
: fir(std::make_shared<ECFMP::FlightInformationRegion::ConcreteFlightInformationRegion>(1, "EGTT", "London")
1212
),
1313
event(std::make_shared<ECFMP::Event::ConcreteEvent>(
14-
1, "TEST", std::chrono::system_clock::now(), std::chrono::system_clock::now(), fir, "ABC"
14+
1, "TEST", std::chrono::system_clock::now(), std::chrono::system_clock::now(), fir, "ABC",
15+
std::vector<std::shared_ptr<ECFMP::Event::EventParticipant>>{}
1516
)),
1617
eventFilter(event, ECFMP::FlowMeasure::EventParticipation::NotParticipating)
1718
{}
@@ -42,7 +43,7 @@ namespace ECFMPTest::FlowMeasure {
4243
TEST_F(ConcreteEventFilterTest, ItHasEventApplicability)
4344
{
4445
ECFMP::Event::ConcreteEvent event2(
45-
2, "TEST", std::chrono::system_clock::now(), std::chrono::system_clock::now(), fir, "ABC"
46+
2, "TEST", std::chrono::system_clock::now(), std::chrono::system_clock::now(), fir, "ABC", {}
4647
);
4748
EXPECT_TRUE(eventFilter.ApplicableToEvent(*event));
4849
EXPECT_FALSE(eventFilter.ApplicableToEvent(event2));

0 commit comments

Comments
 (0)