VMT: New provider for Mittelthüringen.

This commit is contained in:
Andreas Schildbach 2012-11-17 17:48:12 +01:00
parent a0bec90f9a
commit 6fe713bbc6
4 changed files with 164 additions and 1 deletions

View file

@ -25,7 +25,7 @@ public enum NetworkId {
RT,
// Germany
DB, BVG, VBB, NVV, BAYERN, MVV, INVG, AVV, VGN, VVM, VMV, SH, GVH, BSVAG, VBN, NASA, VVO, VMS, VGS, VRR, VRS, MVG, VRN, VVS, DING, KVV, VAGFR, NVBW, VVV,
DB, BVG, VBB, NVV, BAYERN, MVV, INVG, AVV, VGN, VVM, VMV, SH, GVH, BSVAG, VBN, NASA, VMT, VVO, VMS, VGS, VRR, VRS, MVG, VRN, VVS, DING, KVV, VAGFR, NVBW, VVV,
// Austria
OEBB, VAO, VOR, WIEN, OOEVV, LINZ, SVV, VVT, IVB, STV, VMOBIL,

View file

@ -0,0 +1,64 @@
/*
* Copyright 2017 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.regex.Matcher;
import de.schildbach.pte.dto.Product;
import okhttp3.HttpUrl;
/**
* @author Andreas Schildbach
*/
public class VmtProvider extends AbstractHafasMobileProvider {
private static final HttpUrl API_BASE = HttpUrl.parse("https://vmt.hafas.de/bin/");
// http://www.routenplaner.nahverkehr-jena.de/bin/
private static final Product[] PRODUCTS_MAP = { Product.HIGH_SPEED_TRAIN, Product.HIGH_SPEED_TRAIN,
Product.HIGH_SPEED_TRAIN, Product.REGIONAL_TRAIN, Product.SUBURBAN_TRAIN, Product.TRAM, Product.FERRY,
Product.BUS /* guessing */, Product.BUS };
public VmtProvider(final String jsonApiAuthorization) {
super(NetworkId.VMT, API_BASE, PRODUCTS_MAP);
setApiVersion("1.10");
setApiClient("{\"name\":\"VMT\"}");
setApiAuthorization(jsonApiAuthorization);
}
private static final String[] PLACES = { "Erfurt", "Jena", "Gera", "Weimar", "Gotha" };
@Override
protected String[] splitStationName(final String name) {
for (final String place : PLACES) {
if (name.startsWith(place + ", "))
return new String[] { place, name.substring(place.length() + 2) };
if (name.startsWith(place + " ") || name.startsWith(place + "-"))
return new String[] { place, name.substring(place.length() + 1) };
}
return super.splitStationName(name);
}
@Override
protected String[] splitAddress(final String address) {
final Matcher m = P_SPLIT_NAME_FIRST_COMMA.matcher(address);
if (m.matches())
return new String[] { m.group(1), m.group(2) };
return super.splitStationName(address);
}
}

View file

@ -0,0 +1,98 @@
/*
* Copyright 2017 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 java.util.Date;
import org.junit.Test;
import de.schildbach.pte.NetworkProvider.Accessibility;
import de.schildbach.pte.NetworkProvider.WalkSpeed;
import de.schildbach.pte.VmtProvider;
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 VmtProviderLiveTest extends AbstractProviderLiveTest {
public VmtProviderLiveTest() {
super(new VmtProvider(secretProperty("vmt.api_authorization")));
}
@Test
public void nearbyStations() throws Exception {
final NearbyLocationsResult result = queryNearbyStations(new Location(LocationType.STATION, "153166"));
print(result);
}
@Test
public void nearbyStationsByCoordinate() throws Exception {
final NearbyLocationsResult result = queryNearbyStations(Location.coord(50972622, 11037283));
print(result);
}
@Test
public void queryDepartures() throws Exception {
final QueryDeparturesResult result = queryDepartures("153166", false);
print(result);
}
@Test
public void queryDeparturesInvalidStation() throws Exception {
final QueryDeparturesResult result = queryDepartures("999999", false);
assertEquals(QueryDeparturesResult.Status.INVALID_STATION, result.status);
}
@Test
public void suggestLocationsIncomplete() throws Exception {
final SuggestLocationsResult result = suggestLocations("Jena Stadtzentrum");
print(result);
final SuggestLocationsResult result2 = suggestLocations("Spittelplatz");
print(result2);
}
@Test
public void suggestLocationsUmlaut() throws Exception {
final SuggestLocationsResult result = suggestLocations("Höhle");
print(result);
}
@Test
public void shortTrip() throws Exception {
final QueryTripsResult result = queryTrips(
new Location(LocationType.STATION, "153166", 50926947, 11586987, null, "Jena, Stadtzentrum"), null,
new Location(LocationType.STATION, "153014", 50933887, 11590592, null, "Jena, Spittelpl."), new Date(),
true, Product.ALL, WalkSpeed.NORMAL, Accessibility.NEUTRAL);
System.out.println(result);
if (!result.context.canQueryLater())
return;
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
System.out.println(laterResult);
}
}

View file

@ -3,6 +3,7 @@ vgn.api_base =
navitia.authorization =
vbn.api_authorization =
sh.api_authorization =
vmt.api_authorization =
vor.api_authorization =
ooevv.api_authorization =
svv.api_authorization =