mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-07 05:28:46 +00:00
Europe
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@693 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
13787d55f6
commit
88e9b796b0
8 changed files with 303 additions and 49 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
||||
|
|
139
src/de/schildbach/pte/RtProvider.java
Normal file
139
src/de/schildbach/pte/RtProvider.java
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<Location> 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);
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
129
test/de/schildbach/pte/live/RtProviderLiveTest.java
Normal file
129
test/de/schildbach/pte/live/RtProviderLiveTest.java
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<Location> autocompletes = provider.autocompleteStations("haupt");
|
||||
|
||||
list(autocompletes);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autoCompleteAddress() throws Exception
|
||||
{
|
||||
final List<Location> autocompletes = provider.autocompleteStations("Dorfstrasse 10, Dällikon, Schweiz");
|
||||
|
||||
list(autocompletes);
|
||||
}
|
||||
|
||||
private void list(final List<Location> 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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue