Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit a0dac51d authored by Volker Krause's avatar Volker Krause

Sort booking data chronologically

The structured data included in trainline.eu mails has multiple legs in
random order.
parent 462ffb86
[
{
"@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"
}
}
}
]
[
{
"@context": "http://schema.org",
"@type": "TrainReservation",
"bookingAgent": {
"@type": "Organization",
"email": "someone@trainline.fr",
"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": "somebody@trainline.fr",
"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"
}
]
......@@ -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 {};
}
......@@ -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;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment