diff --git a/src/de/schildbach/pte/AbstractHafasProvider.java b/src/de/schildbach/pte/AbstractHafasProvider.java index c593e19b..a81d2138 100644 --- a/src/de/schildbach/pte/AbstractHafasProvider.java +++ b/src/de/schildbach/pte/AbstractHafasProvider.java @@ -1275,6 +1275,8 @@ public abstract class AbstractHafasProvider implements NetworkProvider return 'I'; if ("ECB".equals(ucType)) // EC, Verona-München return 'I'; + if ("LYN".equals(ucType)) // Dänemark + return 'I'; if ("NZ".equals(ucType)) // Schweden, Nacht return 'I'; if ("INZ".equals(ucType)) // Nacht @@ -1303,14 +1305,22 @@ public abstract class AbstractHafasProvider implements NetworkProvider return 'R'; if ("TAL".equals(ucType)) // Talgo, Spanien return 'I'; + if ("TLG".equals(ucType)) // Spanien, Madrid + return 'I'; + if ("HOT".equals(ucType)) // Spanien, Nacht + return 'I'; if ("X2".equals(ucType)) // X2000 Neigezug, Schweden return 'I'; if ("X".equals(ucType)) // InterConnex return 'I'; if ("FYR".equals(ucType)) // Fyra, Amsterdam-Schiphol-Rotterdam return 'I'; + if ("SC".equals(ucType)) // SuperCity, Tschechien + return 'I'; if ("FLUG".equals(ucType)) return 'I'; + if ("TLK".equals(ucType)) // Tanie Linie Kolejowe, Polen + return 'I'; // Regional if ("ZUG".equals(ucType)) // Generic Train @@ -1451,18 +1461,29 @@ public abstract class AbstractHafasProvider implements NetworkProvider return 'R'; if ("MBB".equals(ucType)) // Mecklenburgische Bäderbahn Molli return 'R'; + if ("VEB".equals(ucType)) // Vulkan-Eifel-Bahn Betriebsgesellschaft + return 'R'; if ("P".equals(ucType)) // Kasbachtalbahn return 'R'; if ("ATZ".equals(ucType)) // Autotunnelzug return 'R'; + if ("ATB".equals(ucType)) // Autoschleuse Tauernbahn + return 'R'; if ("CAT".equals(ucType)) // City Airport Train return 'R'; if ("EXT".equals(ucType)) // Extrazug return 'R'; if ("KD".equals(ucType)) // Koleje Dolnośląskie (Niederschlesische Eisenbahn) return 'R'; + if ("KM".equals(ucType)) // Koleje Mazowieckie + return 'R'; if ("EX".equals(ucType)) // Polen return 'R'; + if ("PCC".equals(ucType)) // PCC Rail, Polen + return 'R'; + if ("ZR".equals(ucType)) // ZSR (Slovakian Republic Railways) + return 'R'; + // if ("E".equals(normalizedType)) // Eilzug, stimmt wahrscheinlich nicht // return "R" + normalizedName; @@ -1473,6 +1494,14 @@ public abstract class AbstractHafasProvider implements NetworkProvider return 'S'; if ("SWE".equals(ucType)) // Südwestdeutsche Verkehrs-AG, Ortenau-S-Bahn return 'S'; + if ("RER".equals(ucType)) // Réseau Express Régional, Frankreich + return 'S'; + if ("WKD".equals(ucType)) // Warszawska Kolej Dojazdowa (Warsaw Suburban Railway) + return 'S'; + if ("SKM".equals(ucType)) // Szybka Kolej Miejska Tricity + return 'S'; + if ("SKW".equals(ucType)) // Szybka Kolej Miejska Warschau + return 'S'; // if ("SPR".equals(normalizedType)) // Sprinter, Niederlande // return "S" + normalizedName; diff --git a/src/de/schildbach/pte/NetworkId.java b/src/de/schildbach/pte/NetworkId.java index cd2aeca3..c4ceab52 100644 --- a/src/de/schildbach/pte/NetworkId.java +++ b/src/de/schildbach/pte/NetworkId.java @@ -22,6 +22,9 @@ package de.schildbach.pte; */ public enum NetworkId { + // Europe + RT, + // Germany DB, BVG, VBB, RMV, VRT, MVV, INVG, AVV, VMV, SH, GVH, BSVAG, BSAG, VBN, NASA, VVO, VMS, VGS, VRR, MVG, VRN, VVS, NALDO, DING, KVV, VVM, VAGFR, NVBW, diff --git a/src/de/schildbach/pte/OebbProvider.java b/src/de/schildbach/pte/OebbProvider.java index 895c4014..900153fd 100644 --- a/src/de/schildbach/pte/OebbProvider.java +++ b/src/de/schildbach/pte/OebbProvider.java @@ -533,20 +533,10 @@ public class OebbProvider extends AbstractHafasProvider return 'I'; if (ucType.equals("RR")) // Finnland, Connections only? return 'I'; - if (ucType.equals("TLK")) // Tanie Linie Kolejowe, Polen - return 'I'; if (ucType.equals("EE")) // Rumänien, Connections only? return 'I'; - if (ucType.equals("SC")) // SuperCity, Tschechien - return 'I'; - if (ucType.equals("TLG")) // Spanien, Madrid - return 'I'; - if (ucType.equals("HOT")) // Spanien, Nacht - return 'I'; if (ucType.equals("OZ")) // Schweden, Oeresundzug, Connections only? return 'I'; - if (ucType.equals("LYN")) // Dänemark - return 'I'; if (ucType.equals("UUU")) // Italien, Nacht, Connections only? return 'I'; @@ -556,20 +546,10 @@ public class OebbProvider extends AbstractHafasProvider return 'R'; if (ucType.equals("DPN")) // Connections only? TODO nicht evtl. doch eher ne S-Bahn? return 'R'; - if (ucType.equals("PCC")) // Polen - return 'R'; - if (ucType.equals("KM")) // Polen - return 'R'; - if (ucType.equals("SKM")) // Polen - return 'R'; - if (ucType.equals("SKW")) // Polen - return 'R'; if (ucType.equals("E")) // Budapest, Ungarn return 'R'; if (ucType.equals("IP")) // Ozd, Ungarn return 'R'; - if (ucType.equals("ZR")) // Bratislava, Slovakai - return 'R'; if (ucType.equals("N")) // Frankreich, Tours return 'R'; if (ucType.equals("DPF")) // VX=Vogtland Express, Connections only? @@ -587,10 +567,6 @@ public class OebbProvider extends AbstractHafasProvider return 'S'; // if (ucType.equals("DPN")) // S3 Bad Reichenhall-Freilassing, via JSON API // return 'S'; - if (ucType.equals("RER")) // Réseau Express Régional, Frankreich - return 'S'; - if (ucType.equals("WKD")) // Warszawska Kolej Dojazdowa (Warsaw Suburban Railway) - return 'S'; if (ucType.equals("LKB")) // Connections only? return 'T'; diff --git a/src/de/schildbach/pte/PlProvider.java b/src/de/schildbach/pte/PlProvider.java index 036a8641..4a438ad9 100644 --- a/src/de/schildbach/pte/PlProvider.java +++ b/src/de/schildbach/pte/PlProvider.java @@ -137,29 +137,14 @@ public class PlProvider extends AbstractHafasProvider { final String ucType = type.toUpperCase(); - if ("TLK".equals(ucType)) // Tanie Linie Kolejowe, Polen - return 'I'; - if ("LYN".equals(ucType)) // Dänemark - return 'I'; - if ("HOT".equals(ucType)) // Spanien, Nacht - return 'I'; - if ("TLG".equals(ucType)) // Spanien, Madrid - return 'I'; - if ("SC".equals(ucType)) // SuperCity, Tschechien - return 'I'; - if ("REG".equals(ucType)) return 'R'; - if ("KM".equals(ucType)) // Koleje Mazowieckie - return 'R'; if ("AR".equals(ucType)) // Arriva Polaczen return 'R'; if ("ÖBA".equals(ucType)) // Öchsle-Bahn Betriebsgesellschaft return 'R'; if ("RNV".equals(ucType)) // Rhein-Neckar-Verkehr GmbH return 'R'; - if ("ZR".equals(ucType)) // Bratislava, Slovakai - return 'R'; if ("KTB".equals(ucType)) // Kandertalbahn return 'R'; if ("LEO".equals(ucType)) // Chiemgauer Lokalbahn @@ -171,15 +156,6 @@ public class PlProvider extends AbstractHafasProvider // if ("INT".equals(ucType)) // Rußland // return 'R'; - if ("SKM".equals(ucType)) // Szybka Kolej Miejska Tricity - return 'S'; - if ("SKW".equals(ucType)) // Szybka Kolej Miejska Warschau - return 'S'; - if ("WKD".equals(ucType)) // Warszawska Kolej Dojazdowa - return 'S'; - if ("RER".equals(ucType)) // Réseau Express Régional, Frankreich - return 'S'; - if ("METRO".equals(ucType)) return 'U'; diff --git a/src/de/schildbach/pte/RtProvider.java b/src/de/schildbach/pte/RtProvider.java new file mode 100644 index 00000000..d2506db7 --- /dev/null +++ b/src/de/schildbach/pte/RtProvider.java @@ -0,0 +1,139 @@ +/* + * Copyright 2010, 2011 the original author or authors. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package de.schildbach.pte; + +import java.io.IOException; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import de.schildbach.pte.dto.Location; +import de.schildbach.pte.dto.LocationType; +import de.schildbach.pte.dto.NearbyStationsResult; +import de.schildbach.pte.dto.QueryDeparturesResult; +import de.schildbach.pte.util.ParserUtils; + +/** + * @author Andreas Schildbach + */ +public class RtProvider extends AbstractHafasProvider +{ + public static final NetworkId NETWORK_ID = NetworkId.RT; + private static final String API_BASE = "http://railteam.hafas.de/bin/"; + + public RtProvider() + { + super(API_BASE + "query.exe/dn", 10, null); + } + + public NetworkId id() + { + return NETWORK_ID; + } + + public boolean hasCapabilities(final Capability... capabilities) + { + for (final Capability capability : capabilities) + if (capability == Capability.AUTOCOMPLETE_ONE_LINE || capability == Capability.DEPARTURES || capability == Capability.CONNECTIONS) + return true; + + return false; + } + + public NearbyStationsResult queryNearbyStations(final Location location, final int maxDistance, final int maxStations) throws IOException + { + final StringBuilder uri = new StringBuilder(API_BASE); + + if (location.hasLocation()) + { + uri.append("query.exe/dny"); + uri.append("?performLocating=2&tpl=stop2json"); + uri.append("&look_maxno=").append(maxStations != 0 ? maxStations : 200); + uri.append("&look_maxdist=").append(maxDistance != 0 ? maxDistance : 5000); + uri.append("&look_stopclass=").append(allProductsInt()); + uri.append("&look_x=").append(location.lon); + uri.append("&look_y=").append(location.lat); + + return jsonNearbyStations(uri.toString()); + } + else if (location.type == LocationType.STATION && location.hasId()) + { + uri.append("stboard.exe/dn"); + uri.append("?productsFilter=").append(allProductsString()); + uri.append("&boardType=dep"); + uri.append("&input=").append(location.id); + uri.append("&sTI=1&start=yes&hcount=0"); + uri.append("&L=vs_java3"); + + return xmlNearbyStations(uri.toString()); + } + else + { + throw new IllegalArgumentException("cannot handle: " + location.toDebugString()); + } + } + + public QueryDeparturesResult queryDepartures(final int stationId, final int maxDepartures, final boolean equivs) throws IOException + { + final StringBuilder uri = new StringBuilder(); + uri.append(API_BASE).append("stboard.exe/dn"); + uri.append("?productsFilter=").append(allProductsString()); + uri.append("&boardType=dep"); + uri.append("&disableEquivs=yes"); // don't use nearby stations + uri.append("&maxJourneys=50"); // ignore maxDepartures because result contains other stations + uri.append("&start=yes"); + uri.append("&L=vs_java3"); + uri.append("&input=").append(stationId); + + return xmlQueryDepartures(uri.toString(), stationId); + } + + private static final String AUTOCOMPLETE_URI = API_BASE + "ajax-getstop.exe/dn?getstop=1&REQ0JourneyStopsS0A=255&S=%s?&js=true&"; + private static final String ENCODING = "ISO-8859-1"; + + public List autocompleteStations(final CharSequence constraint) throws IOException + { + final String uri = String.format(AUTOCOMPLETE_URI, ParserUtils.urlEncode(constraint.toString(), ENCODING)); + + return jsonGetStops(uri); + } + + private static final Pattern P_NORMALIZE_LINE_AND_TYPE = Pattern.compile("([^#]*)#(.*)"); + + @Override + protected String normalizeLine(final String line) + { + if (line.equals("#")) + return "?"; + + final Matcher m = P_NORMALIZE_LINE_AND_TYPE.matcher(line); + if (m.matches()) + { + final String number = m.group(1).replaceAll("\\s+", " "); + final String type = m.group(2); + + final char normalizedType = normalizeType(type); + if (normalizedType != 0) + return normalizedType + number; + + throw new IllegalStateException("cannot normalize type " + type + " number " + number + " line " + line); + } + + throw new IllegalStateException("cannot normalize line " + line); + } +} diff --git a/src/de/schildbach/pte/SbbProvider.java b/src/de/schildbach/pte/SbbProvider.java index 15865722..3b91c2ee 100644 --- a/src/de/schildbach/pte/SbbProvider.java +++ b/src/de/schildbach/pte/SbbProvider.java @@ -154,6 +154,8 @@ public class SbbProvider extends AbstractHafasProvider if ("TX".equals(ucType)) return 'B'; + if ("NFO".equals(ucType)) + return 'B'; final char t = super.normalizeType(type); if (t != 0) diff --git a/src/de/schildbach/pte/util/ParserUtils.java b/src/de/schildbach/pte/util/ParserUtils.java index 46a88229..3a74cb05 100644 --- a/src/de/schildbach/pte/util/ParserUtils.java +++ b/src/de/schildbach/pte/util/ParserUtils.java @@ -295,7 +295,7 @@ public final class ParserUtils calendar.set(Calendar.DAY_OF_MONTH, Integer.parseInt(m.group(3))); } - private static final Pattern P_GERMAN_DATE = Pattern.compile("(\\d{2})[\\./](\\d{2})[\\./](\\d{2,4})"); + private static final Pattern P_GERMAN_DATE = Pattern.compile("(\\d{2})[\\./-](\\d{2})[\\./-](\\d{2,4})"); public static final void parseGermanDate(final Calendar calendar, final CharSequence str) { diff --git a/test/de/schildbach/pte/live/RtProviderLiveTest.java b/test/de/schildbach/pte/live/RtProviderLiveTest.java new file mode 100644 index 00000000..7e2021c6 --- /dev/null +++ b/test/de/schildbach/pte/live/RtProviderLiveTest.java @@ -0,0 +1,129 @@ +/* + * Copyright 2010, 2011 the original author or authors. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package de.schildbach.pte.live; + +import java.util.Date; +import java.util.List; + +import org.junit.Test; + +import de.schildbach.pte.NetworkProvider.WalkSpeed; +import de.schildbach.pte.RtProvider; +import de.schildbach.pte.dto.Location; +import de.schildbach.pte.dto.LocationType; +import de.schildbach.pte.dto.NearbyStationsResult; +import de.schildbach.pte.dto.QueryConnectionsResult; +import de.schildbach.pte.dto.QueryDeparturesResult; + +/** + * @author Andreas Schildbach + */ +public class RtProviderLiveTest +{ + private RtProvider provider = new RtProvider(); + private static final String ALL_PRODUCTS = "IRSUTBFC"; + + @Test + public void nearbyStations() throws Exception + { + final NearbyStationsResult result = provider.queryNearbyStations(new Location(LocationType.STATION, 8500010), 0, 0); + + System.out.println(result.status + " " + result.stations.size() + " " + result.stations); + } + + @Test + public void nearbyStationsByCoordinate() throws Exception + { + final NearbyStationsResult result = provider.queryNearbyStations(new Location(LocationType.ADDRESS, 52525589, 13369548), 0, 0); + + System.out.println(result.stations.size() + " " + result.stations); + } + + @Test + public void queryDepartures() throws Exception + { + final QueryDeparturesResult result = provider.queryDepartures(8588344, 0, false); + + System.out.println(result.stationDepartures); + } + + @Test + public void autoComplete() throws Exception + { + final List autocompletes = provider.autocompleteStations("haupt"); + + list(autocompletes); + } + + @Test + public void autoCompleteAddress() throws Exception + { + final List autocompletes = provider.autocompleteStations("Dorfstrasse 10, Dällikon, Schweiz"); + + list(autocompletes); + } + + private void list(final List autocompletes) + { + System.out.print(autocompletes.size() + " "); + for (final Location autocomplete : autocompletes) + System.out.print(autocomplete.toDebugString() + " "); + System.out.println(); + } + + @Test + public void shortConnection() throws Exception + { + final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.STATION, 8503000, null, "Zürich HB"), null, + new Location(LocationType.STATION, 8507785, null, "Bern, Hauptbahnhof"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL); + System.out.println(result); + final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context); + System.out.println(moreResult); + } + + @Test + public void slowConnection() throws Exception + { + final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ANY, 0, null, "Schocherswil, Alte Post!"), null, + new Location(LocationType.ANY, 0, null, "Laconnex, Mollach"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL); + System.out.println(result); + final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context); + System.out.println(moreResult); + } + + @Test + public void connectionWithFootway() throws Exception + { + final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, null, "Spiez, Seestraße 62"), null, + new Location(LocationType.ADDRESS, 0, null, "Einsiedeln, Erlenmoosweg 24"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL); + System.out.println(result); + final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context); + System.out.println(moreResult); + } + + @Test + public void connectionFromAddress() throws Exception + { + final QueryConnectionsResult result = provider.queryConnections(new Location(LocationType.ADDRESS, 0, null, + "Dorfstrasse 10, Dällikon, Schweiz"), null, new Location(LocationType.STATION, 8500010, null, "Basel"), new Date(), true, + ALL_PRODUCTS, WalkSpeed.NORMAL); + System.out.println(result); + final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.context); + System.out.println(moreResult); + } +}