Commit 9a5237cb authored by Volker Krause's avatar Volker Krause
Browse files

Use the new coordinate-based timezone/country lookup in post-processing

This is particularly useful for elements that don't refer to an airport
or train station we have explicitly listed in the database, ie. hotels,
restaurants, event locations, etc.
parent c4c8ea8a
......@@ -11,22 +11,26 @@ DESCRIPTION:Coach: 17\nSeat: 62\nBooking reference: XXX007
SUMMARY:Train 5186 from Nîmes Gare to Lyon Part-Dieu
LOCATION:Nîmes Gare
GEO:43.832291;4.365845
DTSTART;TZID="UTC+02:00":20170929T182600
DTEND;TZID="UTC+02:00":20170929T195200
DTSTART;TZID=Europe/Paris:20170929T182600
DTEND;TZID=Europe/Paris:20170929T195200
TRANSP:OPAQUE
X-KDE-KITINERARY-RESERVATION:[{"@context":"http://schema.org"\,"@type":
"TrainReservation"\,"potentialAction":[{"@type":"ViewAction"\,"target":
"https://www.trainline.fr/tickets"}]\,"reservationFor":{"@type":
"TrainTrip"\,"arrivalStation":{"@type":"TrainStation"\,"geo":{"@type":
"TrainTrip"\,"arrivalStation":{"@type":"TrainStation"\,"address":{"@type":
"PostalAddress"\,"addressCountry":"FR"}\,"geo":{"@type":
"GeoCoordinates"\,"latitude":45.76055908203125\,"longitude":
4.8593549728393555}\,"name":"Lyon Part-Dieu"}\,"arrivalTime":
"2017-09-29T19:52:00+02:00"\,"departureDay":"2017-09-29"\,"departureStation":{"@type":
"TrainStation"\,"geo":{"@type":"GeoCoordinates"\,"latitude":
43.83229064941406\,"longitude":4.365845203399658}\,"name":"Nîmes Gare"}\,"departureTime":"2017-09-29T18:26:00+02:00"\,"provider":{"@type":
4.8593549728393555}\,"name":"Lyon Part-Dieu"}\,"arrivalTime":{"@type":
"QDateTime"\,"@value":"2017-09-29T19:52:00+02:00"\,"timezone":
"Europe/Paris"}\,"departureDay":"2017-09-29"\,"departureStation":{"@type":
"TrainStation"\,"address":{"@type":"PostalAddress"\,"addressCountry":
"FR"}\,"geo":{"@type":"GeoCoordinates"\,"latitude":
43.83229064941406\,"longitude":4.365845203399658}\,"name":"Nîmes Gare"}\,"departureTime":{"@type":"QDateTime"\,"@value":"2017-09-29T18:26:00+02:00"\,"timezone":"Europe/Paris"}\,"provider":{"@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"}\,"url":"https://www.trainline.fr/tickets"}]
"5186"}\,"reservationNumber":"XXX007"\,"reservationStatus":"http://schema.org/ReservationConfirmed"\,"reservedTicket":{"@type":
"Ticket"\,"ticketedSeat":{"@type":
"Seat"\,"seatNumber":"62"\,"seatSection":"17"\,"seatingType":
"Economy"}}\,"underName":{"@type":"Person"\,"name":"John Doe"}\,"url":
"https://www.trainline.fr/tickets"}]
END:VEVENT
END:VCALENDAR
......@@ -43,7 +43,6 @@
"reservationStatus": "http://schema.org/ReservationConfirmed",
"reservedTicket": {
"@type": "Ticket",
"ticketToken": "aztecCode:somerandomdata DOE JOHN111110 00000",
"ticketedSeat": {
"@type": "Seat",
"seatNumber": "62",
......
......@@ -16,6 +16,10 @@
"departureDay": "2019-01-02",
"departureStation": {
"@type": "TrainStation",
"address": {
"@type": "PostalAddress",
"addressCountry": "AT"
},
"geo": {
"@type": "GeoCoordinates",
"latitude": 48.18522644042969,
......
......@@ -13,6 +13,10 @@
"@type": "TrainTrip",
"arrivalStation": {
"@type": "TrainStation",
"address": {
"@type": "PostalAddress",
"addressCountry": "FR"
},
"geo": {
"@type": "GeoCoordinates",
"latitude": 43.83229064941406,
......@@ -20,10 +24,18 @@
},
"name": "Nîmes Gare"
},
"arrivalTime": "2017-09-24T20:33:00+02:00",
"arrivalTime": {
"@type": "QDateTime",
"@value": "2017-09-24T20:33:00+02:00",
"timezone": "Europe/Paris"
},
"departureDay": "2017-09-24",
"departureStation": {
"@type": "TrainStation",
"address": {
"@type": "PostalAddress",
"addressCountry": "FR"
},
"geo": {
"@type": "GeoCoordinates",
"latitude": 45.76055908203125,
......@@ -31,11 +43,15 @@
},
"name": "Lyon Part-Dieu"
},
"departureTime": "2017-09-24T19:09:00+02:00",
"departureTime": {
"@type": "QDateTime",
"@value": "2017-09-24T19:09:00+02:00",
"timezone": "Europe/Paris"
},
"provider": {
"@type": "Organization",
"name": "SNCF"
},
"@type": "Organization",
"name": "SNCF"
},
"trainName": "TGV",
"trainNumber": "5119"
},
......@@ -71,6 +87,10 @@
"@type": "TrainTrip",
"arrivalStation": {
"@type": "TrainStation",
"address": {
"@type": "PostalAddress",
"addressCountry": "FR"
},
"geo": {
"@type": "GeoCoordinates",
"latitude": 45.76055908203125,
......@@ -78,22 +98,34 @@
},
"name": "Lyon Part-Dieu"
},
"arrivalTime": "2017-09-29T19:52:00+02:00",
"arrivalTime": {
"@type": "QDateTime",
"@value": "2017-09-29T19:52:00+02:00",
"timezone": "Europe/Paris"
},
"departureDay": "2017-09-29",
"departureStation": {
"@type": "TrainStation",
"address": {
"@type": "PostalAddress",
"addressCountry": "FR"
},
"geo": {
"@type": "GeoCoordinates",
"latitude": 43.83229064941406,
"longitude": 4.365845203399658
},
"name": "Nîmes Gare"
"name": "Nîmes Gare"
},
"departureTime": {
"@type": "QDateTime",
"@value": "2017-09-29T18:26:00+02:00",
"timezone": "Europe/Paris"
},
"departureTime": "2017-09-29T18:26:00+02:00",
"provider": {
"@type": "Organization",
"name": "SNCF"
},
"@type": "Organization",
"name": "SNCF"
},
"trainName": "TGV",
"trainNumber": "5186"
},
......
......@@ -442,7 +442,7 @@ Person ExtractorPostprocessorPrivate::processPerson(Person person) const
return person;
}
PostalAddress ExtractorPostprocessorPrivate::processAddress(PostalAddress addr, const QString &phoneNumber)
PostalAddress ExtractorPostprocessorPrivate::processAddress(PostalAddress addr, const QString &phoneNumber, const GeoCoordinates &geo)
{
// convert to ISO 3166-1 alpha-2 country codes
if (addr.addressCountry().size() > 2) {
......@@ -485,6 +485,13 @@ PostalAddress ExtractorPostprocessorPrivate::processAddress(PostalAddress addr,
}
#endif
if (geo.isValid() && addr.addressCountry().isEmpty()) {
const auto isoCode = KnowledgeDb::countryForCoordinate(geo.latitude(), geo.longitude());
if (isoCode.isValid()) {
addr.setAddressCountry(isoCode.toString());
}
}
addr = ExtractorUtil::extractPostalCode(addr);
return addr;
}
......@@ -565,7 +572,8 @@ QDateTime ExtractorPostprocessorPrivate::processTimeForLocation(QDateTime dt, co
QTimeZone tz;
if (!place.address().addressCountry().isEmpty()) {
tz = KnowledgeDb::toQTimeZone(KnowledgeDb::timezoneForCountry(KnowledgeDb::CountryId{place.address().addressCountry()}));
tz = KnowledgeDb::toQTimeZone(KnowledgeDb::timezoneForLocation(place.geo().latitude(), place.geo().longitude(),
KnowledgeDb::CountryId{place.address().addressCountry()}));
}
if (!tz.isValid()) {
return dt;
......
......@@ -36,6 +36,7 @@ class EventReservation;
class Flight;
class FlightReservation;
class FoodEstablishmentReservation;
class GeoCoordinates;
class LodgingReservation;
class Person;
class PostalAddress;
......@@ -74,7 +75,7 @@ public:
template <typename T> T processReservation(T res) const;
Person processPerson(Person person) const;
template <typename T> static T processPlace(T place);
static PostalAddress processAddress(PostalAddress addr, const QString &phoneNumber);
static PostalAddress processAddress(PostalAddress addr, const QString &phoneNumber, const GeoCoordinates &geo);
static QString processPhoneNumber(const QString &phoneNumber, const PostalAddress &addr);
QVariantList processActions(QVariantList actions) const;
template <typename T> QDateTime processTimeForLocation(QDateTime dt, const T &place) const;
......@@ -89,7 +90,7 @@ public:
template<typename T> inline T ExtractorPostprocessorPrivate::processPlace(T place)
{
place.setName(place.name().simplified());
auto addr = processAddress(place.address(), place.telephone());
auto addr = processAddress(place.address(), place.telephone(), place.geo());
place.setAddress(addr);
place.setTelephone(processPhoneNumber(place.telephone(), place.address()));
return place;
......
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