summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Krause <[email protected]>2017-12-27 10:48:47 +0100
committerVolker Krause <[email protected]>2017-12-27 10:48:47 +0100
commita0dac51d5f1a99077cc3268a7a62472df5057ef7 (patch)
tree8e88c0c040fc6210cb038940e5a7078445de7187
parent462ffb864fb0d156647b81c7131c0a699a26b7db (diff)
Sort booking data chronologically
The structured data included in trainline.eu mails has multiple legs in random order.
-rw-r--r--plugins/messageviewer/bodypartformatter/autotests/postprocessordata/train-unsorted.post.json78
-rw-r--r--plugins/messageviewer/bodypartformatter/autotests/postprocessordata/train-unsorted.pre.json128
-rw-r--r--plugins/messageviewer/bodypartformatter/semantic/extractorpostprocessor.cpp17
-rw-r--r--plugins/messageviewer/bodypartformatter/semantic/extractorpostprocessor.h2
4 files changed, 225 insertions, 0 deletions
diff --git a/plugins/messageviewer/bodypartformatter/autotests/postprocessordata/train-unsorted.post.json b/plugins/messageviewer/bodypartformatter/autotests/postprocessordata/train-unsorted.post.json
new file mode 100644
index 0000000..ebc6456
--- /dev/null
+++ b/plugins/messageviewer/bodypartformatter/autotests/postprocessordata/train-unsorted.post.json
@@ -0,0 +1,78 @@
+[
+ {
+ "@context": "http://schema.org",
+ "@type": "TrainReservation",
+ "reservationFor": {
+ "@type": "TrainTrip",
+ "arrivalStation": {
+ "@type": "TrainStation",
+ "geo": {
+ "@type": "GeoCoordinates",
+ "latitude": 43.83229064941406,
+ "longitude": 4.365845203399658
+ },
+ "name": "Nîmes Gare"
+ },
+ "arrivalTime": "2017-09-24T20:33:00+02:00",
+ "departureStation": {
+ "@type": "TrainStation",
+ "geo": {
+ "@type": "GeoCoordinates",
+ "latitude": 45.76055908203125,
+ "longitude": 4.8593549728393555
+ },
+ "name": "Lyon Part-Dieu"
+ },
+ "departureTime": "2017-09-24T19:09:00+02:00",
+ "trainName": "TGV",
+ "trainNumber": "5119"
+ },
+ "reservationNumber": "XXX007",
+ "reservedTicket": {
+ "@type": "Ticket",
+ "ticketedSeat": {
+ "@type": "Seat",
+ "seatNumber": "71",
+ "seatSection": "13"
+ }
+ }
+ },
+ {
+ "@context": "http://schema.org",
+ "@type": "TrainReservation",
+ "reservationFor": {
+ "@type": "TrainTrip",
+ "arrivalStation": {
+ "@type": "TrainStation",
+ "geo": {
+ "@type": "GeoCoordinates",
+ "latitude": 45.76055908203125,
+ "longitude": 4.8593549728393555
+ },
+ "name": "Lyon Part-Dieu"
+ },
+ "arrivalTime": "2017-09-29T19:52:00+02:00",
+ "departureStation": {
+ "@type": "TrainStation",
+ "geo": {
+ "@type": "GeoCoordinates",
+ "latitude": 43.83229064941406,
+ "longitude": 4.365845203399658
+ },
+ "name": "Nîmes Gare"
+ },
+ "departureTime": "2017-09-29T18:26:00+02:00",
+ "trainName": "TGV",
+ "trainNumber": "5186"
+ },
+ "reservationNumber": "XXX007",
+ "reservedTicket": {
+ "@type": "Ticket",
+ "ticketedSeat": {
+ "@type": "Seat",
+ "seatNumber": "62",
+ "seatSection": "17"
+ }
+ }
+ }
+]
diff --git a/plugins/messageviewer/bodypartformatter/autotests/postprocessordata/train-unsorted.pre.json b/plugins/messageviewer/bodypartformatter/autotests/postprocessordata/train-unsorted.pre.json
new file mode 100644
index 0000000..73907d8
--- /dev/null
+++ b/plugins/messageviewer/bodypartformatter/autotests/postprocessordata/train-unsorted.pre.json
@@ -0,0 +1,128 @@
+[
+ {
+ "@context": "http://schema.org",
+ "@type": "TrainReservation",
+ "bookingAgent": {
+ "@type": "Organization",
+ "email": "[email protected]",
+ "name": "Trainline"
+ },
+ "bookingTime": "2017-09-19T13:42:00+02:00",
+ "cancelReservationUrl": "https://www.trainline.fr/tickets",
+ "modifiedTime": "2017-09-21T09:19:38+02:00",
+ "modifyReservationUrl": "https://www.trainline.fr/tickets",
+ "reservationFor": {
+ "@type": "TrainTrip",
+ "arrivalStation": {
+ "@type": "TrainStation",
+ "geo": {
+ "@type": "GeoCoordinates",
+ "latitude": 45.760559,
+ "longitude": 4.859355
+ },
+ "name": "Lyon Part-Dieu"
+ },
+ "arrivalTime": "2017-09-29T19:52:00+02:00",
+ "departureStation": {
+ "@type": "TrainStation",
+ "geo": {
+ "@type": "GeoCoordinates",
+ "latitude": 43.832291,
+ "longitude": 4.365845
+ },
+ "name": "Nîmes Gare"
+ },
+ "departureTime": "2017-09-29T18:26:00+02:00",
+ "trainCompany": {
+ "@type": "Organization",
+ "name": "SNCF"
+ },
+ "trainName": "TGV",
+ "trainNumber": "5186"
+ },
+ "reservationNumber": "XXX007",
+ "reservationStatus": "http://schema.org/ReservationConfirmed",
+ "reservedTicket": {
+ "@type": "Ticket",
+ "ticketToken": "aztecCode:somerandomdata DOE JOHN111110 00000",
+ "ticketedSeat": {
+ "@type": "Seat",
+ "seatNumber": "62",
+ "seatSection": "17",
+ "seatingType": "Economy"
+ },
+ "underName": {
+ "@type": "Person",
+ "name": "John Doe"
+ }
+ },
+ "underName": {
+ "@type": "Person",
+ "name": "John Doe"
+ },
+ "url": "https://www.trainline.fr/tickets"
+ },
+ {
+ "@context": "http://schema.org",
+ "@type": "TrainReservation",
+ "bookingAgent": {
+ "@type": "Organization",
+ "email": "[email protected]",
+ "name": "Trainline"
+ },
+ "bookingTime": "2017-09-19T13:42:00+02:00",
+ "cancelReservationUrl": "https://www.trainline.fr/tickets",
+ "modifiedTime": "2017-09-21T09:19:38+02:00",
+ "modifyReservationUrl": "https://www.trainline.fr/tickets",
+ "reservationFor": {
+ "@type": "TrainTrip",
+ "arrivalStation": {
+ "@type": "TrainStation",
+ "geo": {
+ "@type": "GeoCoordinates",
+ "latitude": 43.832291,
+ "longitude": 4.365845
+ },
+ "name": "Nîmes Gare"
+ },
+ "arrivalTime": "2017-09-24T20:33:00+02:00",
+ "departureStation": {
+ "@type": "TrainStation",
+ "geo": {
+ "@type": "GeoCoordinates",
+ "latitude": 45.760559,
+ "longitude": 4.859355
+ },
+ "name": "Lyon Part-Dieu"
+ },
+ "departureTime": "2017-09-24T19:09:00+02:00",
+ "trainCompany": {
+ "@type": "Organization",
+ "name": "SNCF"
+ },
+ "trainName": "TGV",
+ "trainNumber": "5119"
+ },
+ "reservationNumber": "XXX007",
+ "reservationStatus": "http://schema.org/ReservationConfirmed",
+ "reservedTicket": {
+ "@type": "Ticket",
+ "ticketToken": "aztecCode:somerandomdata DOE JOHN111110 00000",
+ "ticketedSeat": {
+ "@type": "Seat",
+ "seatNumber": "71",
+ "seatSection": "13",
+ "seatingType": "First"
+ },
+ "underName": {
+ "@type": "Person",
+ "name": "John Doe"
+ }
+ },
+ "underName": {
+ "@type": "Person",
+ "name": "John Doe"
+ },
+ "url": "https://www.trainline.fr/tickets"
+ }
+]
diff --git a/plugins/messageviewer/bodypartformatter/semantic/extractorpostprocessor.cpp b/plugins/messageviewer/bodypartformatter/semantic/extractorpostprocessor.cpp
index 88e87ff..eabe7d0 100644
--- a/plugins/messageviewer/bodypartformatter/semantic/extractorpostprocessor.cpp
+++ b/plugins/messageviewer/bodypartformatter/semantic/extractorpostprocessor.cpp
@@ -25,6 +25,8 @@
#include <QDebug>
#include <QTimeZone>
+#include <algorithm>
+
void ExtractorPostprocessor::process(const QVector<QVariant> &data)
{
m_data.reserve(data.size());
@@ -37,6 +39,10 @@ void ExtractorPostprocessor::process(const QVector<QVariant> &data)
m_data.push_back(d);
}
}
+
+ std::stable_sort(m_data.begin(), m_data.end(), [](const QVariant &lhs, const QVariant &rhs) {
+ return startDateTime(lhs) < startDateTime(rhs);
+ });
}
QVector<QVariant> ExtractorPostprocessor::result() const
@@ -171,3 +177,14 @@ bool ExtractorPostprocessor::filterTrainStation(const QVariant &station) const
{
return !JsonLdDocument::readProperty(station, "name").toString().isEmpty();
}
+
+QDateTime ExtractorPostprocessor::startDateTime(const QVariant& res)
+{
+ if (res.userType() == qMetaTypeId<FlightReservation>() || res.userType() == qMetaTypeId<TrainReservation>()) {
+ const auto trip = JsonLdDocument::readProperty(res, "reservationFor");
+ return JsonLdDocument::readProperty(trip, "departureTime").toDateTime();
+ } else if (res.userType() == qMetaTypeId<LodgingReservation>()) {
+ return JsonLdDocument::readProperty(res, "checkinDate").toDateTime();
+ }
+ return {};
+}
diff --git a/plugins/messageviewer/bodypartformatter/semantic/extractorpostprocessor.h b/plugins/messageviewer/bodypartformatter/semantic/extractorpostprocessor.h
index 005a00e..1b7e5b3 100644
--- a/plugins/messageviewer/bodypartformatter/semantic/extractorpostprocessor.h
+++ b/plugins/messageviewer/bodypartformatter/semantic/extractorpostprocessor.h
@@ -44,6 +44,8 @@ private:
bool filterTrainTrip(const QVariant &trip) const;
bool filterTrainStation(const QVariant &station) const;
+ static QDateTime startDateTime(const QVariant &res);
+
QVector<QVariant> m_data;
};