mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-19 08:49:58 +00:00
Liverpool.
This commit is contained in:
parent
5b3ceed733
commit
695fc56d8e
4 changed files with 191 additions and 2 deletions
|
@ -3201,7 +3201,8 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Pattern P_POSITION = Pattern.compile(
|
private static final Pattern P_POSITION = Pattern.compile(
|
||||||
"(?:Gleis|Gl\\.|Bahnsteig|Bstg\\.|Bussteig|Busstg\\.|Steig|Hp\\.|Stop|Pos\\.|Zone|Platform)?\\s*(.+)", Pattern.CASE_INSENSITIVE);
|
"(?:Gleis|Gl\\.|Bahnsteig|Bstg\\.|Bussteig|Busstg\\.|Steig|Hp\\.|Stop|Pos\\.|Zone|Platform|Stand|Bay|Stance)?\\s*(.+)",
|
||||||
|
Pattern.CASE_INSENSITIVE);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Position parsePosition(final String position)
|
protected Position parsePosition(final String position)
|
||||||
|
|
68
enabler/src/de/schildbach/pte/MerseyProvider.java
Normal file
68
enabler/src/de/schildbach/pte/MerseyProvider.java
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2014-2015 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.util.Set;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import de.schildbach.pte.dto.Position;
|
||||||
|
import de.schildbach.pte.dto.Product;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Andreas Schildbach
|
||||||
|
*/
|
||||||
|
public class MerseyProvider extends AbstractEfaProvider
|
||||||
|
{
|
||||||
|
public static final NetworkId NETWORK_ID = NetworkId.MERSEY;
|
||||||
|
private final static String API_BASE = "http://jp.merseytravel.gov.uk/nwm/";
|
||||||
|
|
||||||
|
public MerseyProvider()
|
||||||
|
{
|
||||||
|
super(API_BASE);
|
||||||
|
|
||||||
|
setLanguage("en");
|
||||||
|
setTimeZone("Europe/London");
|
||||||
|
}
|
||||||
|
|
||||||
|
public NetworkId id()
|
||||||
|
{
|
||||||
|
return NETWORK_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Set<Product> defaultProducts()
|
||||||
|
{
|
||||||
|
return Product.ALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Pattern P_POSITION_BOUND = Pattern.compile("([NESW]+)-bound", Pattern.CASE_INSENSITIVE);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Position parsePosition(final String position)
|
||||||
|
{
|
||||||
|
if (position == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
final Matcher m = P_POSITION_BOUND.matcher(position);
|
||||||
|
if (m.matches())
|
||||||
|
return new Position(m.group(1));
|
||||||
|
|
||||||
|
return super.parsePosition(position);
|
||||||
|
}
|
||||||
|
}
|
|
@ -56,7 +56,7 @@ public enum NetworkId
|
||||||
LU,
|
LU,
|
||||||
|
|
||||||
// United Kingdom
|
// United Kingdom
|
||||||
TLEM,
|
TLEM, MERSEY,
|
||||||
|
|
||||||
// Ireland
|
// Ireland
|
||||||
TFI, EIREANN,
|
TFI, EIREANN,
|
||||||
|
|
120
enabler/test/de/schildbach/pte/live/MerseyProviderLiveTest.java
Normal file
120
enabler/test/de/schildbach/pte/live/MerseyProviderLiveTest.java
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2014-2015 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 static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import de.schildbach.pte.MerseyProvider;
|
||||||
|
import de.schildbach.pte.NetworkProvider.Accessibility;
|
||||||
|
import de.schildbach.pte.NetworkProvider.WalkSpeed;
|
||||||
|
import de.schildbach.pte.dto.Location;
|
||||||
|
import de.schildbach.pte.dto.LocationType;
|
||||||
|
import de.schildbach.pte.dto.NearbyLocationsResult;
|
||||||
|
import de.schildbach.pte.dto.Product;
|
||||||
|
import de.schildbach.pte.dto.QueryDeparturesResult;
|
||||||
|
import de.schildbach.pte.dto.QueryTripsResult;
|
||||||
|
import de.schildbach.pte.dto.SuggestLocationsResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Andreas Schildbach
|
||||||
|
*/
|
||||||
|
public class MerseyProviderLiveTest extends AbstractProviderLiveTest
|
||||||
|
{
|
||||||
|
public MerseyProviderLiveTest()
|
||||||
|
{
|
||||||
|
super(new MerseyProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void nearbyStations() throws Exception
|
||||||
|
{
|
||||||
|
final NearbyLocationsResult result = queryNearbyStations(new Location(LocationType.STATION, "4017846"));
|
||||||
|
print(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void nearbyStationsByCoordinate() throws Exception
|
||||||
|
{
|
||||||
|
final NearbyLocationsResult result = queryNearbyStations(new Location(LocationType.ADDRESS, 53401112, -2958903));
|
||||||
|
print(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void nearbyLocationsByCoordinate() throws Exception
|
||||||
|
{
|
||||||
|
final NearbyLocationsResult result = queryNearbyLocations(EnumSet.of(LocationType.STATION, LocationType.POI), new Location(
|
||||||
|
LocationType.ADDRESS, 53401112, -2958903));
|
||||||
|
print(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void queryDepartures() throws Exception
|
||||||
|
{
|
||||||
|
final QueryDeparturesResult result = queryDepartures("4017846", false);
|
||||||
|
print(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void queryDeparturesInvalidStation() throws Exception
|
||||||
|
{
|
||||||
|
final QueryDeparturesResult resultLive = queryDepartures("999999", false);
|
||||||
|
assertEquals(QueryDeparturesResult.Status.INVALID_STATION, resultLive.status);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void suggestLocations() throws Exception
|
||||||
|
{
|
||||||
|
final SuggestLocationsResult result = suggestLocations("Liverpool");
|
||||||
|
print(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shortTrip() throws Exception
|
||||||
|
{
|
||||||
|
final QueryTripsResult result = queryTrips(new Location(LocationType.STATION, "4017846", 53401672, -2958720, "Liverpool", "Orphan Street"),
|
||||||
|
null, new Location(LocationType.STATION, "4027286", 53397324, -2961676, "Liverpool", "Womens Hospital"), new Date(), true,
|
||||||
|
Product.ALL, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
|
||||||
|
print(result);
|
||||||
|
assertEquals(QueryTripsResult.Status.OK, result.status);
|
||||||
|
assertTrue(result.trips.size() > 0);
|
||||||
|
|
||||||
|
if (!result.context.canQueryLater())
|
||||||
|
return;
|
||||||
|
|
||||||
|
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
|
||||||
|
print(laterResult);
|
||||||
|
|
||||||
|
if (!laterResult.context.canQueryLater())
|
||||||
|
return;
|
||||||
|
|
||||||
|
final QueryTripsResult later2Result = queryMoreTrips(laterResult.context, true);
|
||||||
|
print(later2Result);
|
||||||
|
|
||||||
|
if (!later2Result.context.canQueryEarlier())
|
||||||
|
return;
|
||||||
|
|
||||||
|
final QueryTripsResult earlierResult = queryMoreTrips(later2Result.context, false);
|
||||||
|
print(earlierResult);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue