overhauled Luxembourg

This commit is contained in:
Andreas Schildbach 2012-06-20 12:01:19 +02:00
parent b61ebf3a7d
commit 15050b91ba
2 changed files with 42 additions and 12 deletions

View file

@ -19,6 +19,7 @@ package de.schildbach.pte;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.regex.Pattern;
import de.schildbach.pte.dto.Location; import de.schildbach.pte.dto.Location;
import de.schildbach.pte.dto.LocationType; import de.schildbach.pte.dto.LocationType;
@ -35,7 +36,7 @@ public class LuProvider extends AbstractHafasProvider
public LuProvider() public LuProvider()
{ {
super(API_BASE + "query.exe/dn", 10, null); super(API_BASE + "query.exe/fn", 10, null, UTF_8, UTF_8);
} }
public NetworkId id() public NetworkId id()
@ -98,12 +99,41 @@ public class LuProvider extends AbstractHafasProvider
} }
} }
private static final String[] PLACES = { "Luxembourg", "Luxembourg/Centre" };
@Override
protected String[] splitPlaceAndName(final String name)
{
for (final String place : PLACES)
{
if (name.startsWith(place + " ") || name.startsWith(place + "-"))
return new String[] { place, name.substring(place.length() + 1) };
else if (name.startsWith(place + ", "))
return new String[] { place, name.substring(place.length() + 2) };
}
return super.splitPlaceAndName(name);
}
public NearbyStationsResult queryNearbyStations(final Location location, final int maxDistance, final int maxStations) throws IOException public NearbyStationsResult queryNearbyStations(final Location location, final int maxDistance, final int maxStations) throws IOException
{ {
if (location.type == LocationType.STATION && location.hasId()) final StringBuilder uri = new StringBuilder(API_BASE);
if (location.hasLocation())
{ {
final StringBuilder uri = new StringBuilder(API_BASE); uri.append("query.exe/fny");
uri.append("stboard.exe/dn"); 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/fn");
uri.append("?productsFilter=").append(allProductsString()); uri.append("?productsFilter=").append(allProductsString());
uri.append("&boardType=dep"); uri.append("&boardType=dep");
uri.append("&input=").append(location.id); uri.append("&input=").append(location.id);
@ -120,7 +150,7 @@ public class LuProvider extends AbstractHafasProvider
public QueryDeparturesResult queryDepartures(final int stationId, final int maxDepartures, final boolean equivs) throws IOException public QueryDeparturesResult queryDepartures(final int stationId, final int maxDepartures, final boolean equivs) throws IOException
{ {
final StringBuilder uri = new StringBuilder(); final StringBuilder uri = new StringBuilder();
uri.append(API_BASE).append("stboard.exe/dn"); uri.append(API_BASE).append("stboard.exe/fn");
uri.append("?productsFilter=").append(allProductsString()); uri.append("?productsFilter=").append(allProductsString());
uri.append("&boardType=dep"); uri.append("&boardType=dep");
uri.append("&disableEquivs=yes"); // don't use nearby stations uri.append("&disableEquivs=yes"); // don't use nearby stations

View file

@ -44,7 +44,7 @@ public class LuProviderLiveTest extends AbstractProviderLiveTest
@Test @Test
public void nearbyStations() throws Exception public void nearbyStations() throws Exception
{ {
final NearbyStationsResult result = provider.queryNearbyStations(new Location(LocationType.STATION, 9865836), 0, 0); final NearbyStationsResult result = provider.queryNearbyStations(new Location(LocationType.STATION, 120405001), 0, 0);
print(result); print(result);
} }
@ -60,7 +60,7 @@ public class LuProviderLiveTest extends AbstractProviderLiveTest
@Test @Test
public void queryDepartures() throws Exception public void queryDepartures() throws Exception
{ {
final QueryDeparturesResult result = provider.queryDepartures(9865836, 0, false); final QueryDeparturesResult result = provider.queryDepartures(120405001, 0, false);
print(result); print(result);
} }
@ -68,7 +68,7 @@ public class LuProviderLiveTest extends AbstractProviderLiveTest
@Test @Test
public void autocomplete() throws Exception public void autocomplete() throws Exception
{ {
final List<Location> autocompletes = provider.autocompleteStations("Flughafen"); final List<Location> autocompletes = provider.autocompleteStations("Aéroport");
print(autocompletes); print(autocompletes);
} }
@ -76,8 +76,8 @@ public class LuProviderLiveTest extends AbstractProviderLiveTest
@Test @Test
public void shortConnection() throws Exception public void shortConnection() throws Exception
{ {
final QueryConnectionsResult result = queryConnections(new Location(LocationType.STATION, 9409001, null, "Echternach, Bel Air"), null, final QueryConnectionsResult result = queryConnections(new Location(LocationType.STATION, 200416001, null, "Cité Aéroport"), null,
new Location(LocationType.STATION, 9440001, null, "Echternach, Gare"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL, new Location(LocationType.STATION, 200405035, "Luxembourg", "Gare Centrale"), new Date(), true, ALL_PRODUCTS, WalkSpeed.NORMAL,
Accessibility.NEUTRAL); Accessibility.NEUTRAL);
System.out.println(result); System.out.println(result);
final QueryConnectionsResult laterResult = queryMoreConnections(result.context, true); final QueryConnectionsResult laterResult = queryMoreConnections(result.context, true);
@ -88,8 +88,8 @@ public class LuProviderLiveTest extends AbstractProviderLiveTest
public void addressConnection() throws Exception public void addressConnection() throws Exception
{ {
final QueryConnectionsResult result = queryConnections(new Location(LocationType.ADDRESS, 0, 49611610, 6130265, null, final QueryConnectionsResult result = queryConnections(new Location(LocationType.ADDRESS, 0, 49611610, 6130265, null,
"Luxembourg, Rue Génistre 2"), null, new Location(LocationType.STATION, 9217081, null, "Luxembourg, Gare Centrale"), new Date(), "Luxembourg, Rue Génistre 2"), null, new Location(LocationType.STATION, 200405035, "Luxembourg", "Gare Centrale"), new Date(), true,
true, ALL_PRODUCTS, WalkSpeed.NORMAL, Accessibility.NEUTRAL); ALL_PRODUCTS, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
System.out.println(result); System.out.println(result);
final QueryConnectionsResult laterResult = queryMoreConnections(result.context, true); final QueryConnectionsResult laterResult = queryMoreConnections(result.context, true);
System.out.println(laterResult); System.out.println(laterResult);