mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-07 14:28:49 +00:00
Kassel & Nordhessen
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@759 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
6cf1f652c3
commit
c1c0a90bf5
2 changed files with 265 additions and 0 deletions
174
src/de/schildbach/pte/NvvProvider.java
Normal file
174
src/de/schildbach/pte/NvvProvider.java
Normal file
|
@ -0,0 +1,174 @@
|
||||||
|
/*
|
||||||
|
* 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 de.schildbach.pte.dto.Location;
|
||||||
|
import de.schildbach.pte.dto.LocationType;
|
||||||
|
import de.schildbach.pte.dto.NearbyStationsResult;
|
||||||
|
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Andreas Schildbach
|
||||||
|
*/
|
||||||
|
public class NvvProvider extends AbstractHafasProvider
|
||||||
|
{
|
||||||
|
public static final NetworkId NETWORK_ID = NetworkId.NVV;
|
||||||
|
private static final String API_BASE = "http://auskunft.nvv.de/nvv/bin/jp/";
|
||||||
|
|
||||||
|
public NvvProvider()
|
||||||
|
{
|
||||||
|
super(API_BASE + "query.exe/dn", 17, null, "UTF-8", "UTF-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
public NetworkId id()
|
||||||
|
{
|
||||||
|
return NETWORK_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasCapabilities(Capability... capabilities)
|
||||||
|
{
|
||||||
|
for (final Capability capability : capabilities)
|
||||||
|
if (capability == Capability.AUTOCOMPLETE_ONE_LINE || capability == Capability.CONNECTIONS)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void setProductBits(final StringBuilder productBits, final char product)
|
||||||
|
{
|
||||||
|
if (product == 'I')
|
||||||
|
{
|
||||||
|
productBits.setCharAt(0, '1'); // Zug ICE
|
||||||
|
productBits.setCharAt(1, '1'); // Zug
|
||||||
|
}
|
||||||
|
else if (product == 'R')
|
||||||
|
{
|
||||||
|
productBits.setCharAt(2, '1'); // Zug Nahverkehr
|
||||||
|
productBits.setCharAt(10, '1'); // RegioTram
|
||||||
|
}
|
||||||
|
else if (product == 'S')
|
||||||
|
{
|
||||||
|
productBits.setCharAt(3, '1'); // S-Bahn
|
||||||
|
}
|
||||||
|
else if (product == 'U')
|
||||||
|
{
|
||||||
|
productBits.setCharAt(4, '1'); // U-Bahn
|
||||||
|
}
|
||||||
|
else if (product == 'T')
|
||||||
|
{
|
||||||
|
productBits.setCharAt(5, '1'); // Tram
|
||||||
|
}
|
||||||
|
else if (product == 'B')
|
||||||
|
{
|
||||||
|
productBits.setCharAt(6, '1'); // Niederflurbus
|
||||||
|
productBits.setCharAt(7, '1'); // Bus
|
||||||
|
}
|
||||||
|
else if (product == 'P')
|
||||||
|
{
|
||||||
|
productBits.setCharAt(9, '1'); // Anruf-Sammel-Taxi
|
||||||
|
}
|
||||||
|
else if (product == 'F')
|
||||||
|
{
|
||||||
|
productBits.setCharAt(8, '1'); // Schiff
|
||||||
|
}
|
||||||
|
else if (product == 'C')
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("cannot handle: " + product);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final String[] PLACES = { "Kassel" };
|
||||||
|
|
||||||
|
@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) };
|
||||||
|
|
||||||
|
return super.splitPlaceAndName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
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/en?near=Anzeigen");
|
||||||
|
uri.append("&distance=").append(maxDistance != 0 ? maxDistance / 1000 : 50);
|
||||||
|
uri.append("&input=").append(location.id);
|
||||||
|
|
||||||
|
return htmlNearbyStations(uri.toString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("cannot handle: " + location.toDebugString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public QueryDeparturesResult queryDepartures(final int stationId, final int maxDepartures, 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);
|
||||||
|
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
// return xmlQueryDepartures(uri.toString(), stationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Location> autocompleteStations(final CharSequence constraint) throws IOException
|
||||||
|
{
|
||||||
|
return xmlMLcReq(constraint);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected char normalizeType(final String type)
|
||||||
|
{
|
||||||
|
final char t = super.normalizeType(type);
|
||||||
|
if (t != 0)
|
||||||
|
return t;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
91
test/de/schildbach/pte/live/NvvProviderLiveTest.java
Normal file
91
test/de/schildbach/pte/live/NvvProviderLiveTest.java
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
/*
|
||||||
|
* 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.NvvProvider;
|
||||||
|
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 NvvProviderLiveTest
|
||||||
|
{
|
||||||
|
private final NvvProvider provider = new NvvProvider();
|
||||||
|
private static final String ALL_PRODUCTS = "IRSUTBFC";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void nearbyStations() throws Exception
|
||||||
|
{
|
||||||
|
final NearbyStationsResult result = provider.queryNearbyStations(new Location(LocationType.STATION, 3011245), 0, 0);
|
||||||
|
|
||||||
|
System.out.println(result.stations.size() + " " + result.stations);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void nearbyStationsByCoordinate() throws Exception
|
||||||
|
{
|
||||||
|
final NearbyStationsResult result = provider.queryNearbyStations(new Location(LocationType.ADDRESS, 51318447, 9496250), 0, 0);
|
||||||
|
|
||||||
|
System.out.println(result.stations.size() + " " + result.stations);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void queryDepartures() throws Exception
|
||||||
|
{
|
||||||
|
final QueryDeparturesResult result = provider.queryDepartures(3011245, 0, false);
|
||||||
|
|
||||||
|
System.out.println(result.stationDepartures);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void autocompleteIdentified() throws Exception
|
||||||
|
{
|
||||||
|
final List<Location> autocompletes = provider.autocompleteStations("Kassel Wilhelmshöhe");
|
||||||
|
|
||||||
|
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, 2200007, null, "Kassel Wilhelmshöhe"), null, new Location(LocationType.STATION,
|
||||||
|
2200278, null, "Kassel Wilhelmshöher Weg"), 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