VAGFR: Merge Freiburg & Strasbourg into Baden-Württemberg, Constance & Basel.

This commit is contained in:
Andreas Schildbach 2018-12-06 11:49:36 +01:00
parent e5aa74254b
commit 84585d4fb6
5 changed files with 106 additions and 242 deletions

View file

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

View file

@ -17,6 +17,8 @@
package de.schildbach.pte; package de.schildbach.pte;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -24,6 +26,8 @@ import javax.annotation.Nullable;
import de.schildbach.pte.dto.Line; import de.schildbach.pte.dto.Line;
import de.schildbach.pte.dto.Product; import de.schildbach.pte.dto.Product;
import de.schildbach.pte.dto.Style;
import de.schildbach.pte.dto.Style.Shape;
import okhttp3.HttpUrl; import okhttp3.HttpUrl;
@ -31,13 +35,14 @@ import okhttp3.HttpUrl;
* @author Andreas Schildbach * @author Andreas Schildbach
*/ */
public class NvbwProvider extends AbstractEfaProvider { public class NvbwProvider extends AbstractEfaProvider {
// no intermeditate stops
private final static HttpUrl API_BASE = HttpUrl.parse("https://www.efa-bw.de/nvbw3L/"); private final static HttpUrl API_BASE = HttpUrl.parse("https://www.efa-bw.de/nvbw3L/");
// https://efaserver.vag-freiburg.de/vagfr/
// http://efa2.naldo.de/naldo/ // http://efa2.naldo.de/naldo/
public NvbwProvider() { public NvbwProvider() {
super(NetworkId.NVBW, API_BASE); super(NetworkId.NVBW, API_BASE);
setIncludeRegionId(false); setIncludeRegionId(false);
setStyles(STYLES);
setSessionCookieName("EFABWLB"); setSessionCookieName("EFABWLB");
} }
@ -85,4 +90,19 @@ public class NvbwProvider extends AbstractEfaProvider {
return super.parseLine(id, network, mot, symbol, name, longName, trainType, trainNum, trainName); return super.parseLine(id, network, mot, symbol, name, longName, trainType, trainNum, trainName);
} }
private static final Map<String, Style> STYLES = new HashMap<>();
static {
// Tram
STYLES.put("T1", new Style(Shape.RECT, Style.parseColor("#ed1c24"), Style.WHITE));
STYLES.put("T2", new Style(Shape.RECT, Style.parseColor("#33b540"), Style.WHITE));
STYLES.put("T3", new Style(Shape.RECT, Style.parseColor("#f79210"), Style.WHITE));
STYLES.put("T4", new Style(Shape.RECT, Style.parseColor("#ef58a1"), Style.WHITE));
STYLES.put("T5", new Style(Shape.RECT, Style.parseColor("#0994ce"), Style.WHITE));
// Nachtbus
STYLES.put("N46", new Style(Style.parseColor("#28bda5"), Style.WHITE));
STYLES.put("N47", new Style(Style.parseColor("#d6de20"), Style.WHITE));
}
} }

View file

@ -1,72 +0,0 @@
/*
* Copyright 2010-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 <https://www.gnu.org/licenses/>.
*/
package de.schildbach.pte;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
import de.schildbach.pte.dto.Line;
import de.schildbach.pte.dto.Product;
import de.schildbach.pte.dto.Style;
import de.schildbach.pte.dto.Style.Shape;
import okhttp3.HttpUrl;
/**
* @author Andreas Schildbach
*/
public class VagfrProvider extends AbstractEfaProvider {
private static final HttpUrl API_BASE = HttpUrl.parse("https://efaserver.vag-freiburg.de/vagfr/");
public VagfrProvider() {
super(NetworkId.VAGFR, API_BASE);
setUseRouteIndexAsTripId(false);
setStyles(STYLES);
setSessionCookieName("EFABWLB");
}
@Override
protected Line parseLine(final @Nullable String id, final @Nullable String network, final @Nullable String mot,
final @Nullable String symbol, final @Nullable String name, final @Nullable String longName,
final @Nullable String trainType, final @Nullable String trainNum, final @Nullable String trainName) {
if ("0".equals(mot)) {
if (("N".equals(trainType) || "Nahverkehrszug".equals(trainName)) && trainNum != null)
return new Line(id, network, Product.REGIONAL_TRAIN, "N" + trainNum);
}
return super.parseLine(id, network, mot, symbol, name, longName, trainType, trainNum, trainName);
}
private static final Map<String, Style> STYLES = new HashMap<>();
static {
// Tram
STYLES.put("T1", new Style(Shape.RECT, Style.parseColor("#ed1c24"), Style.WHITE));
STYLES.put("T2", new Style(Shape.RECT, Style.parseColor("#33b540"), Style.WHITE));
STYLES.put("T3", new Style(Shape.RECT, Style.parseColor("#f79210"), Style.WHITE));
STYLES.put("T4", new Style(Shape.RECT, Style.parseColor("#ef58a1"), Style.WHITE));
STYLES.put("T5", new Style(Shape.RECT, Style.parseColor("#0994ce"), Style.WHITE));
// Nachtbus
STYLES.put("N46", new Style(Style.parseColor("#28bda5"), Style.WHITE));
STYLES.put("N47", new Style(Style.parseColor("#d6de20"), Style.WHITE));
}
}

View file

@ -44,35 +44,62 @@ public class NvbwProviderLiveTest extends AbstractProviderLiveTest {
} }
@Test @Test
public void nearbyStations() throws Exception { public void nearbyStationsStuttgart() throws Exception {
final NearbyLocationsResult result1 = queryNearbyStations(new Location(LocationType.STATION, "6900001")); final NearbyLocationsResult result = queryNearbyStations(new Location(LocationType.STATION, "5006022")); // Schlossplatz
print(result1); print(result);
final NearbyLocationsResult result2 = queryNearbyStations(new Location(LocationType.STATION, "53019174"));
print(result2);
} }
@Test @Test
public void nearbyStationsByCoordinate() throws Exception { public void nearbyStationsReutlingen() throws Exception {
final NearbyLocationsResult result1 = queryNearbyStations(Location.coord(48778953, 9178963)); final NearbyLocationsResult result = queryNearbyStations(new Location(LocationType.STATION, "53019174")); // Reutlingen
print(result1); print(result);
final NearbyLocationsResult result2 = queryNearbyStations(Location.coord(48493550, 9205656));
print(result2);
} }
@Test @Test
public void queryDepartures() throws Exception { public void nearbyStationsFreiburg() throws Exception {
final QueryDeparturesResult result1 = queryDepartures("6900001", false); final NearbyLocationsResult result = queryNearbyStations(new Location(LocationType.STATION, "6930112")); // Faulerstraße
print(result1); print(result);
final QueryDeparturesResult result2 = queryDepartures("53019174", false);
print(result2);
} }
@Test @Test
public void queryDeparturesMesseKarlsruhe() throws Exception { public void nearbyStationsByCoordinateStuttgart() throws Exception {
final QueryDeparturesResult result = queryDepartures("7000211", false); final NearbyLocationsResult result = queryNearbyStations(Location.coord(48778953, 9178963));
print(result);
}
@Test
public void nearbyStationsByCoordinateReutlingen() throws Exception {
final NearbyLocationsResult result = queryNearbyStations(Location.coord(48493550, 9205656));
print(result);
}
@Test
public void nearbyStationsByCoordinateFreiburg() throws Exception {
final NearbyLocationsResult result = queryNearbyStations(Location.coord(48000295, 7854338));
print(result);
}
@Test
public void queryDeparturesStuttgart() throws Exception {
final QueryDeparturesResult result = queryDepartures("5006022", false); // Schlossplatz
print(result);
}
@Test
public void queryDeparturesReutlingen() throws Exception {
final QueryDeparturesResult result = queryDepartures("53019174", false); // Reutlingen
print(result);
}
@Test
public void queryDeparturesKarlsruhe() throws Exception {
final QueryDeparturesResult result = queryDepartures("7000211", false); // Messe
print(result);
}
@Test
public void queryDeparturesFreiburg() throws Exception {
final QueryDeparturesResult result = queryDepartures("6930112", false); // Faulerstraße
print(result); print(result);
} }
@ -95,43 +122,38 @@ public class NvbwProviderLiveTest extends AbstractProviderLiveTest {
} }
@Test @Test
public void suggestLocationsCoverage() throws Exception { public void suggestLocationsCoverageFreiburg() throws Exception {
final SuggestLocationsResult freiburgResult = suggestLocations("Freiburg Hauptbahnhof"); final SuggestLocationsResult result = suggestLocations("Freiburg Hauptbahnhof");
print(freiburgResult); print(result);
assertThat(freiburgResult.getLocations(), hasItem(new Location(LocationType.STATION, "6906508"))); assertThat(result.getLocations(), hasItem(new Location(LocationType.STATION, "6906508")));
}
final SuggestLocationsResult baselResult = suggestLocations("Basel"); @Test
print(baselResult); public void suggestLocationsCoverageBasel() throws Exception {
assertThat(baselResult.getLocations(), hasItem(new Location(LocationType.STATION, "51000007"))); final SuggestLocationsResult result = suggestLocations("Basel");
print(result);
assertThat(result.getLocations(), hasItem(new Location(LocationType.STATION, "51000007")));
}
final SuggestLocationsResult constanceResult = suggestLocations("Konstanz"); @Test
print(constanceResult); public void suggestLocationsCoverageKonstanz() throws Exception {
assertThat(constanceResult.getLocations(), hasItem(new Location(LocationType.STATION, "8706554"))); final SuggestLocationsResult result = suggestLocations("Konstanz");
print(result);
assertThat(result.getLocations(), hasItem(new Location(LocationType.STATION, "8706554")));
} }
@Test @Test
public void shortTrip() throws Exception { public void shortTrip() throws Exception {
final QueryTripsResult result = queryTrips(new Location(LocationType.STATION, "17002402", null, "Bahnhof"), final Location from = new Location(LocationType.STATION, "17002402", null, "Bahnhof");
null, new Location(LocationType.STATION, "17009001", null, "Bahnhof"), new Date(), true, null); final Location to = new Location(LocationType.STATION, "17009001", null, "Bahnhof");
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
print(result); print(result);
assertEquals(QueryTripsResult.Status.OK, result.status); assertEquals(QueryTripsResult.Status.OK, result.status);
assertTrue(result.trips.size() > 0); assertTrue(result.trips.size() > 0);
if (!result.context.canQueryLater())
return;
final QueryTripsResult laterResult = queryMoreTrips(result.context, true); final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
print(laterResult); print(laterResult);
if (!laterResult.context.canQueryLater())
return;
final QueryTripsResult later2Result = queryMoreTrips(laterResult.context, true); final QueryTripsResult later2Result = queryMoreTrips(laterResult.context, true);
print(later2Result); print(later2Result);
if (!later2Result.context.canQueryEarlier())
return;
final QueryTripsResult earlierResult = queryMoreTrips(later2Result.context, false); final QueryTripsResult earlierResult = queryMoreTrips(later2Result.context, false);
print(earlierResult); print(earlierResult);
} }
@ -146,22 +168,26 @@ public class NvbwProviderLiveTest extends AbstractProviderLiveTest {
print(result); print(result);
assertEquals(QueryTripsResult.Status.OK, result.status); assertEquals(QueryTripsResult.Status.OK, result.status);
assertTrue(result.trips.size() > 0); assertTrue(result.trips.size() > 0);
if (!result.context.canQueryLater())
return;
final QueryTripsResult laterResult = queryMoreTrips(result.context, true); final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
print(laterResult); print(laterResult);
if (!laterResult.context.canQueryLater())
return;
final QueryTripsResult later2Result = queryMoreTrips(laterResult.context, true); final QueryTripsResult later2Result = queryMoreTrips(laterResult.context, true);
print(later2Result); print(later2Result);
final QueryTripsResult earlierResult = queryMoreTrips(later2Result.context, false);
print(earlierResult);
}
if (!later2Result.context.canQueryEarlier()) @Test
return; public void shortTripFreiburg() throws Exception {
final Location from = new Location(LocationType.STATION, "6930100", null, "Freiburg Bertoldsbrunnen");
final Location to = new Location(LocationType.STATION, "6930101", null, "Freiburg Siegesdenkmal");
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
print(result);
assertEquals(QueryTripsResult.Status.OK, result.status);
assertTrue(result.trips.size() > 0);
final QueryTripsResult laterResult = queryMoreTrips(result.context, true);
print(laterResult);
final QueryTripsResult later2Result = queryMoreTrips(laterResult.context, true);
print(later2Result);
final QueryTripsResult earlierResult = queryMoreTrips(later2Result.context, false); final QueryTripsResult earlierResult = queryMoreTrips(later2Result.context, false);
print(earlierResult); print(earlierResult);
} }
@ -179,8 +205,9 @@ public class NvbwProviderLiveTest extends AbstractProviderLiveTest {
@Test @Test
public void tripPforzheimToKarlsruhe() throws Exception { public void tripPforzheimToKarlsruhe() throws Exception {
final QueryTripsResult result = queryTrips(new Location(LocationType.STATION, "7900050"), null, final Location from = new Location(LocationType.STATION, "7900050");
new Location(LocationType.STATION, "7000090"), new Date(), true, null); final Location to = new Location(LocationType.STATION, "7000090");
final QueryTripsResult result = queryTrips(from, null, to, new Date(), true, null);
print(result); print(result);
assertEquals(QueryTripsResult.Status.OK, result.status); assertEquals(QueryTripsResult.Status.OK, result.status);
} }

View file

@ -1,111 +0,0 @@
/*
* Copyright 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 <https://www.gnu.org/licenses/>.
*/
package de.schildbach.pte.live;
import static org.hamcrest.CoreMatchers.hasItem;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.Date;
import org.junit.Test;
import de.schildbach.pte.VagfrProvider;
import de.schildbach.pte.dto.Location;
import de.schildbach.pte.dto.LocationType;
import de.schildbach.pte.dto.NearbyLocationsResult;
import de.schildbach.pte.dto.QueryDeparturesResult;
import de.schildbach.pte.dto.QueryTripsResult;
import de.schildbach.pte.dto.SuggestLocationsResult;
/**
* @author Andreas Schildbach
*/
public class VagfrProviderLiveTest extends AbstractProviderLiveTest {
public VagfrProviderLiveTest() {
super(new VagfrProvider());
}
@Test
public void nearbyStations() throws Exception {
final NearbyLocationsResult result = queryNearbyStations(new Location(LocationType.STATION, "6930112"));
print(result);
}
@Test
public void nearbyStationsByCoordinate() throws Exception {
final NearbyLocationsResult result = queryNearbyStations(Location.coord(48000295, 7854338));
print(result);
}
@Test
public void queryDepartures() throws Exception {
final QueryDeparturesResult result = queryDepartures("6930112", false);
print(result);
}
@Test
public void suggestLocationsIncomplete() throws Exception {
final SuggestLocationsResult result = suggestLocations("Kurf");
print(result);
}
@Test
public void suggestLocationsCoverage() throws Exception {
final SuggestLocationsResult freiburgResult = suggestLocations("Betzenhauser Torplatz");
print(freiburgResult);
assertThat(freiburgResult.getLocations(), hasItem(new Location(LocationType.STATION, "6930503")));
}
@Test
public void shortTrip() throws Exception {
final QueryTripsResult result = queryTrips(
new Location(LocationType.STATION, "6930100", null, "Freiburg Bertoldsbrunnen"), null,
new Location(LocationType.STATION, "6930101", null, "Freiburg Siegesdenkmal"), new Date(), true, null);
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);
}
@Test
public void trip() throws Exception {
final QueryTripsResult result = queryTrips(new Location(LocationType.STATION, "6930120"), null,
new Location(LocationType.STATION, "6930071"), new Date(), true, null);
print(result);
assertEquals(QueryTripsResult.Status.OK, result.status);
}
}