mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-14 08:40:29 +00:00
departures for Leipzig
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@225 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
00e145dd49
commit
66cfd29f3a
6 changed files with 328 additions and 224 deletions
|
@ -19,7 +19,9 @@ package de.schildbach.pte;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -80,4 +82,108 @@ public abstract class AbstractHafasProvider implements NetworkProvider
|
|||
else
|
||||
return stations.subList(0, maxStations);
|
||||
}
|
||||
|
||||
protected static final Pattern P_NORMALIZE_LINE = Pattern.compile("([A-Za-zÄÖÜäöüßáàâéèêíìîóòôúùû/-]+)[\\s-]*(.*)");
|
||||
|
||||
protected final String normalizeLine(final String type, final String line)
|
||||
{
|
||||
final Matcher m = P_NORMALIZE_LINE.matcher(line);
|
||||
final String strippedLine = m.matches() ? m.group(1) + m.group(2) : line;
|
||||
|
||||
final char normalizedType = normalizeType(type);
|
||||
if (normalizedType != 0)
|
||||
return normalizedType + strippedLine;
|
||||
|
||||
throw new IllegalStateException("cannot normalize type " + type + " line " + line);
|
||||
}
|
||||
|
||||
protected abstract char normalizeType(String type);
|
||||
|
||||
protected final char normalizeCommonTypes(final String ucType)
|
||||
{
|
||||
// Intercity
|
||||
if (ucType.equals("EC")) // EuroCity
|
||||
return 'I';
|
||||
if (ucType.equals("EN")) // EuroNight
|
||||
return 'I';
|
||||
if (ucType.equals("ICE")) // InterCityExpress
|
||||
return 'I';
|
||||
if (ucType.equals("IC")) // InterCity
|
||||
return 'I';
|
||||
if (ucType.equals("EN")) // EuroNight
|
||||
return 'I';
|
||||
if (ucType.equals("CNL")) // CityNightLine
|
||||
return 'I';
|
||||
if (ucType.equals("OEC")) // ÖBB-EuroCity
|
||||
return 'I';
|
||||
if (ucType.equals("OIC")) // ÖBB-InterCity
|
||||
return 'I';
|
||||
if (ucType.equals("RJ")) // RailJet, Österreichische Bundesbahnen
|
||||
return 'I';
|
||||
if (ucType.equals("THA")) // Thalys
|
||||
return 'I';
|
||||
if (ucType.equals("TGV")) // Train à Grande Vitesse
|
||||
return 'I';
|
||||
if (ucType.equals("DNZ")) // Berlin-Saratov, Berlin-Moskva, Connections only?
|
||||
return 'I';
|
||||
|
||||
// Regional Germany
|
||||
if (ucType.equals("ZUG")) // Generic Train
|
||||
return 'R';
|
||||
if (ucType.equals("R")) // Generic Regional Train
|
||||
return 'R';
|
||||
if (ucType.equals("DPN")) // Dritter Personen Nahverkehr
|
||||
return 'R';
|
||||
if (ucType.equals("RB")) // RegionalBahn
|
||||
return 'R';
|
||||
if (ucType.equals("RE")) // RegionalExpress
|
||||
return 'R';
|
||||
if (ucType.equals("IRE")) // Interregio Express
|
||||
return 'R';
|
||||
if (ucType.equals("HEX")) // Harz-Berlin-Express, Veolia
|
||||
return 'R';
|
||||
if (ucType.equals("WFB")) // Westfalenbahn
|
||||
return 'R';
|
||||
if (ucType.equals("RT")) // RegioTram
|
||||
return 'R';
|
||||
if (ucType.equals("REX")) // RegionalExpress, Österreich
|
||||
return 'R';
|
||||
|
||||
// Suburban Trains
|
||||
if (ucType.equals("S")) // Generic S-Bahn
|
||||
return 'S';
|
||||
|
||||
// Subway
|
||||
if (ucType.equals("U")) // Generic U-Bahn
|
||||
return 'U';
|
||||
|
||||
// Tram
|
||||
if (ucType.equals("STR")) // Generic Tram
|
||||
return 'T';
|
||||
|
||||
// Bus
|
||||
if (ucType.equals("BUS")) // Generic Bus
|
||||
return 'B';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static final Map<Character, int[]> LINES = new HashMap<Character, int[]>();
|
||||
|
||||
static
|
||||
{
|
||||
LINES.put('I', new int[] { Color.WHITE, Color.RED, Color.RED });
|
||||
LINES.put('R', new int[] { Color.GRAY, Color.WHITE });
|
||||
LINES.put('S', new int[] { Color.parseColor("#006e34"), Color.WHITE });
|
||||
LINES.put('U', new int[] { Color.parseColor("#003090"), Color.WHITE });
|
||||
LINES.put('T', new int[] { Color.parseColor("#cc0000"), Color.WHITE });
|
||||
LINES.put('B', new int[] { Color.parseColor("#993399"), Color.WHITE });
|
||||
LINES.put('F', new int[] { Color.BLUE, Color.WHITE });
|
||||
LINES.put('?', new int[] { Color.DKGRAY, Color.WHITE });
|
||||
}
|
||||
|
||||
public final int[] lineColors(final String line)
|
||||
{
|
||||
return LINES.get(line.charAt(0));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,16 +18,28 @@
|
|||
package de.schildbach.pte;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import de.schildbach.pte.QueryDeparturesResult.Status;
|
||||
|
||||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class NasaProvider extends AbstractHafasProvider
|
||||
{
|
||||
public static final String NETWORK_ID = "www.nasa.de";
|
||||
private static final String API_BASE = "http://www.nasa.de/delfi52/";
|
||||
|
||||
private static final long PARSER_DAY_ROLLOVER_THRESHOLD_MS = 12 * 60 * 60 * 1000;
|
||||
|
||||
public boolean hasCapabilities(Capability... capabilities)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
|
@ -38,7 +50,8 @@ public class NasaProvider extends AbstractHafasProvider
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
private final String NEARBY_URI = API_BASE + "stboard.exe/dn?input=%s&selectDate=today&boardType=dep&productsFilter=11111111&distance=50&near=Anzeigen";
|
||||
private final String NEARBY_URI = API_BASE
|
||||
+ "stboard.exe/dn?input=%s&selectDate=today&boardType=dep&productsFilter=11111111&distance=50&near=Anzeigen";
|
||||
|
||||
@Override
|
||||
protected String nearbyStationUri(final String stationId)
|
||||
|
@ -51,14 +64,163 @@ public class NasaProvider extends AbstractHafasProvider
|
|||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String departuresQueryUri(String stationId, int maxDepartures)
|
||||
public String departuresQueryUri(final String stationId, final int maxDepartures)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
final DateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yy");
|
||||
final DateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm");
|
||||
final Date now = new Date();
|
||||
|
||||
final StringBuilder uri = new StringBuilder();
|
||||
uri.append(API_BASE).append("stboard.exe/dn");
|
||||
uri.append("?input=").append(stationId);
|
||||
uri.append("&boardType=dep");
|
||||
uri.append("&time=").append(TIME_FORMAT.format(now));
|
||||
uri.append("&selectDate=").append(DATE_FORMAT.format(now));
|
||||
uri.append("&productsFilter=11111111");
|
||||
if (maxDepartures != 0)
|
||||
uri.append("&maxJourneys=").append(maxDepartures);
|
||||
uri.append("&disableEquivs=yes"); // don't use nearby stations
|
||||
uri.append("&start=yes");
|
||||
|
||||
return uri.toString();
|
||||
}
|
||||
|
||||
public QueryDeparturesResult queryDepartures(String queryUri) throws IOException
|
||||
private static final Pattern P_DEPARTURES_HEAD_COARSE = Pattern
|
||||
.compile(
|
||||
".*?" //
|
||||
+ "(?:" //
|
||||
+ "<table class=\"hafasResult\"[^>]*>(.+?)</table>.*?" //
|
||||
+ "(?:<table cellspacing=\"0\" class=\"hafasResult\"[^>]*>(.+?)</table>|(verkehren an dieser Haltestelle keine))"//
|
||||
+ "|(Eingabe kann nicht interpretiert)|(Verbindung zum Server konnte leider nicht hergestellt werden|kann vom Server derzeit leider nicht bearbeitet werden))" //
|
||||
+ ".*?" //
|
||||
, Pattern.DOTALL);
|
||||
private static final Pattern P_DEPARTURES_HEAD_FINE = Pattern.compile(".*?" //
|
||||
+ "<td class=\"querysummary screennowrap\">\\s*(.*?)\\s*<.*?" // location
|
||||
+ "(\\d{2}\\.\\d{2}\\.\\d{2}).*?" // date
|
||||
+ "Abfahrt (\\d{1,2}:\\d{2}).*?" // time
|
||||
, Pattern.DOTALL);
|
||||
private static final Pattern P_DEPARTURES_COARSE = Pattern.compile("<tr class=\"(depboard-\\w*)\">(.*?)</tr>", Pattern.DOTALL);
|
||||
private static final Pattern P_DEPARTURES_FINE = Pattern.compile(".*?" //
|
||||
+ "<td class=\"[\\w ]*\">(\\d{1,2}:\\d{2})</td>\n" // plannedTime
|
||||
+ "(?:<td class=\"[\\w ]*prognosis[\\w ]*\">\n" //
|
||||
+ "(?: |<span class=\"rtLimit\\d\">(pünktlich|\\d{1,2}:\\d{2})</span>)\n</td>\n" // predictedTime
|
||||
+ ")?.*?" //
|
||||
+ "<img src=\"/img52/(\\w+)_pic\\.gif\"[^>]*>\\s*(.*?)\\s*</.*?" // type, line
|
||||
+ "<span class=\"bold\">\n" //
|
||||
+ "<a href=\"/delfi52/stboard\\.exe/dn\\?input=(\\d+)&[^>]*>" // destinationId
|
||||
+ "\\s*(.*?)\\s*</a>\n" // destination
|
||||
+ "</span>.*?" //
|
||||
+ "(?:<td class=\"center sepline top\">\n(" + ParserUtils.P_PLATFORM + ").*?)?" // position
|
||||
, Pattern.DOTALL);
|
||||
|
||||
public QueryDeparturesResult queryDepartures(final String uri) throws IOException
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
// scrape page
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
// parse page
|
||||
final Matcher mHeadCoarse = P_DEPARTURES_HEAD_COARSE.matcher(page);
|
||||
if (mHeadCoarse.matches())
|
||||
{
|
||||
// messages
|
||||
if (mHeadCoarse.group(3) != null)
|
||||
return new QueryDeparturesResult(uri, Status.NO_INFO);
|
||||
else if (mHeadCoarse.group(4) != null)
|
||||
return new QueryDeparturesResult(uri, Status.INVALID_STATION);
|
||||
else if (mHeadCoarse.group(5) != null)
|
||||
return new QueryDeparturesResult(uri, Status.SERVICE_DOWN);
|
||||
|
||||
final Matcher mHeadFine = P_DEPARTURES_HEAD_FINE.matcher(mHeadCoarse.group(1));
|
||||
if (mHeadFine.matches())
|
||||
{
|
||||
final String location = ParserUtils.resolveEntities(mHeadFine.group(1));
|
||||
final Date currentTime = ParserUtils.joinDateTime(ParserUtils.parseDate(mHeadFine.group(2)), ParserUtils
|
||||
.parseTime(mHeadFine.group(3)));
|
||||
final List<Departure> departures = new ArrayList<Departure>(8);
|
||||
String oldZebra = null;
|
||||
|
||||
final Matcher mDepCoarse = P_DEPARTURES_COARSE.matcher(mHeadCoarse.group(2));
|
||||
while (mDepCoarse.find())
|
||||
{
|
||||
final String zebra = mDepCoarse.group(1);
|
||||
if (oldZebra != null && zebra.equals(oldZebra))
|
||||
throw new IllegalArgumentException("missed row? last:" + zebra);
|
||||
else
|
||||
oldZebra = zebra;
|
||||
|
||||
final Matcher mDepFine = P_DEPARTURES_FINE.matcher(mDepCoarse.group(2));
|
||||
if (mDepFine.matches())
|
||||
{
|
||||
final Calendar current = new GregorianCalendar();
|
||||
current.setTime(currentTime);
|
||||
final Calendar parsed = new GregorianCalendar();
|
||||
parsed.setTime(ParserUtils.parseTime(mDepFine.group(1)));
|
||||
parsed.set(Calendar.YEAR, current.get(Calendar.YEAR));
|
||||
parsed.set(Calendar.MONTH, current.get(Calendar.MONTH));
|
||||
parsed.set(Calendar.DAY_OF_MONTH, current.get(Calendar.DAY_OF_MONTH));
|
||||
if (ParserUtils.timeDiff(parsed.getTime(), currentTime) < -PARSER_DAY_ROLLOVER_THRESHOLD_MS)
|
||||
parsed.add(Calendar.DAY_OF_MONTH, 1);
|
||||
|
||||
final Date plannedTime = parsed.getTime();
|
||||
|
||||
Date predictedTime = null;
|
||||
final String prognosis = ParserUtils.resolveEntities(mDepFine.group(2));
|
||||
if (prognosis != null)
|
||||
{
|
||||
if (prognosis.equals("pünktlich"))
|
||||
predictedTime = plannedTime;
|
||||
else
|
||||
predictedTime = ParserUtils.joinDateTime(currentTime, ParserUtils.parseTime(prognosis));
|
||||
}
|
||||
|
||||
final String lineType = mDepFine.group(3);
|
||||
|
||||
final String line = normalizeLine(lineType, ParserUtils.resolveEntities(mDepFine.group(4)));
|
||||
|
||||
final int destinationId = mDepFine.group(5) != null ? Integer.parseInt(mDepFine.group(5)) : 0;
|
||||
|
||||
final String destination = ParserUtils.resolveEntities(mDepFine.group(6));
|
||||
|
||||
final String position = mDepFine.group(7) != null ? "Gl. " + ParserUtils.resolveEntities(mDepFine.group(7)) : null;
|
||||
|
||||
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? lineColors(line) : null, null, position,
|
||||
destinationId, destination, null);
|
||||
|
||||
if (!departures.contains(dep))
|
||||
departures.add(dep);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("cannot parse '" + mDepCoarse.group(2) + "' on " + uri);
|
||||
}
|
||||
}
|
||||
|
||||
return new QueryDeparturesResult(uri, 0, location, departures);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("cannot parse '" + mHeadCoarse.group(1) + "' on " + uri);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new IllegalArgumentException("cannot parse '" + page + "' on " + uri);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected char normalizeType(String type)
|
||||
{
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
final char t = normalizeCommonTypes(ucType);
|
||||
if (t != 0)
|
||||
return t;
|
||||
|
||||
if (ucType.equals("BSV"))
|
||||
return 'B';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public QueryConnectionsResult queryConnections(LocationType fromType, String from, LocationType viaType, String via, LocationType toType,
|
||||
|
@ -76,9 +238,4 @@ public class NasaProvider extends AbstractHafasProvider
|
|||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public int[] lineColors(String line)
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -415,7 +415,7 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
|
||||
final String arrivalPosition = mDetFine.group(12) != null ? ParserUtils.resolveEntities(mDetFine.group(12)) : null;
|
||||
|
||||
final Connection.Trip trip = new Connection.Trip(line, LINES.get(line.charAt(0)), null, detailsDepartureDateTime,
|
||||
final Connection.Trip trip = new Connection.Trip(line, lineColors(line), null, detailsDepartureDateTime,
|
||||
departurePosition, departureId, departure, detailsArrivalDateTime, arrivalPosition, arrivalId, arrival);
|
||||
connection.parts.add(trip);
|
||||
}
|
||||
|
@ -521,8 +521,8 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
final boolean rt = head.optBoolean("rt", false);
|
||||
final String lineLink = departure.optString("tinfoline");
|
||||
|
||||
departures.add(new Departure(!rt ? time : null, rt ? time : null, line, line != null ? LINES.get(line.charAt(0)) : null,
|
||||
lineLink, position, 0, destination, null));
|
||||
departures.add(new Departure(!rt ? time : null, rt ? time : null, line, line != null ? lineColors(line) : null, lineLink,
|
||||
position, 0, destination, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -535,12 +535,11 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
}
|
||||
}
|
||||
|
||||
private static final Pattern P_NORMALIZE_LINE = Pattern.compile("([A-Za-zÄÖÜäöüßáàâéèêíìîóòôúùû/-]+)[\\s]*(.*)");
|
||||
private static final Pattern P_NORMALIZE_LINE_NUMBER = Pattern.compile("\\d{2,5}");
|
||||
private static final Pattern P_NORMALIZE_LINE_RUSSIA = Pattern.compile("\\d{1,3}[A-Z]{2}");
|
||||
private static final Pattern P_NORMALIZE_LINE_RUSSIA_INT = Pattern.compile("\\d{3}Y");
|
||||
|
||||
private static String normalizeLine(final String line)
|
||||
private String normalizeLine(final String line)
|
||||
{
|
||||
final Matcher m = P_NORMALIZE_LINE.matcher(line);
|
||||
if (m.matches())
|
||||
|
@ -571,40 +570,17 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
throw new IllegalStateException("cannot normalize line " + line);
|
||||
}
|
||||
|
||||
private static String normalizeLine(final String type, final String line)
|
||||
{
|
||||
final Matcher m = P_NORMALIZE_LINE.matcher(line);
|
||||
final String strippedLine = m.matches() ? m.group(1) + m.group(2) : line;
|
||||
|
||||
final char normalizedType = normalizeType(type);
|
||||
if (normalizedType != 0)
|
||||
return normalizedType + strippedLine;
|
||||
|
||||
throw new IllegalStateException("cannot normalize type " + type + " line " + line);
|
||||
}
|
||||
|
||||
private static char normalizeType(final String type)
|
||||
@Override
|
||||
protected char normalizeType(final String type)
|
||||
{
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
if (ucType.equals("OEC")) // ÖBB-EuroCity
|
||||
return 'I';
|
||||
if (ucType.equals("OIC")) // ÖBB-InterCity
|
||||
return 'I';
|
||||
if (ucType.equals("EC")) // EuroCity
|
||||
return 'I';
|
||||
if (ucType.equals("IC")) // InterCity
|
||||
return 'I';
|
||||
if (ucType.equals("ICE")) // InterCityExpress
|
||||
return 'I';
|
||||
final char t = normalizeCommonTypes(ucType);
|
||||
if (t != 0)
|
||||
return t;
|
||||
|
||||
// if (ucType.equals("X")) // Interconnex, Connections only?
|
||||
// return 'I';
|
||||
if (ucType.equals("EN")) // EuroNight
|
||||
return 'I';
|
||||
if (ucType.equals("CNL")) // CityNightLine
|
||||
return 'I';
|
||||
if (ucType.equals("DNZ")) // Berlin-Saratov, Berlin-Moskva, Connections only?
|
||||
return 'I';
|
||||
if (ucType.equals("INT")) // Rußland, Connections only?
|
||||
return 'I';
|
||||
if (ucType.equals("D")) // Rußland
|
||||
|
@ -617,8 +593,6 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
return 'I';
|
||||
if (ucType.equals("SC")) // SuperCity, Tschechien
|
||||
return 'I';
|
||||
if (ucType.equals("RJ")) // RailJet, Österreichische Bundesbahnen
|
||||
return 'I';
|
||||
if (ucType.equals("EST")) // Eurostar Frankreich
|
||||
return 'I';
|
||||
if (ucType.equals("ALS")) // Spanien
|
||||
|
@ -641,10 +615,6 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
return 'I';
|
||||
if (ucType.equals("X")) // Schweden, via JSON API
|
||||
return 'I';
|
||||
if (ucType.equals("THA")) // Thalys
|
||||
return 'I';
|
||||
if (ucType.equals("TGV")) // Train à Grande Vitesse
|
||||
return 'I';
|
||||
if (ucType.equals("LYN")) // Dänemark
|
||||
return 'I';
|
||||
if (ucType.equals("ARZ")) // Frankreich, Nacht
|
||||
|
@ -668,18 +638,10 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
if (ucType.equals("AIR")) // Connections only?
|
||||
return 'I';
|
||||
|
||||
if (ucType.equals("R"))
|
||||
return 'R';
|
||||
if (ucType.equals("REX")) // RegionalExpress
|
||||
return 'R';
|
||||
if (ucType.equals("ZUG")) // Connections only?
|
||||
return 'R';
|
||||
if (ucType.equals("EZ")) // Erlebniszug
|
||||
return 'R';
|
||||
if (ucType.equals("S2")) // Helsinki-Turku, Connections only?
|
||||
return 'R';
|
||||
if (ucType.equals("RB")) // RegionalBahn Deutschland
|
||||
return 'R';
|
||||
if (ucType.equals("RE")) // RegionalExpress Deutschland
|
||||
return 'R';
|
||||
if (ucType.equals("DPN")) // Connections only? TODO nicht evtl. doch eher ne S-Bahn?
|
||||
|
@ -720,10 +682,6 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
return 'R';
|
||||
if (ucType.equals("CAT")) // Stockholm-Arlanda, Arlanda Express
|
||||
return 'R';
|
||||
if (ucType.equals("RT")) // Deutschland
|
||||
return 'R';
|
||||
if (ucType.equals("IRE")) // Interregio Express
|
||||
return 'R';
|
||||
if (ucType.equals("N")) // Frankreich, Tours
|
||||
return 'R';
|
||||
if (ucType.equals("DPF")) // VX=Vogtland Express, Connections only?
|
||||
|
@ -766,8 +724,6 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
return 'R';
|
||||
if (ucType.equals("MRB")) // Mitteldeutsche Regiobahn, via JSON API
|
||||
return 'R';
|
||||
if (ucType.equals("WFB")) // Westfalenbahn, via JSON API
|
||||
return 'R';
|
||||
if (ucType.equals("ARR")) // Ostfriesland, via JSON API
|
||||
return 'R';
|
||||
if (ucType.equals("SHB")) // Schleswig-Holstein-Bahn, via JSON API
|
||||
|
@ -786,8 +742,6 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
return 'R';
|
||||
if (ucType.equals("DAB")) // Daadetalbahn, via JSON API
|
||||
return 'R';
|
||||
if (ucType.equals("HEX")) // Harz-Berlin-Express, Veolia, via JSON API
|
||||
return 'R';
|
||||
if (ucType.equals("WEG")) // Württembergische Eisenbahn-Gesellschaft, via JSON API
|
||||
return 'R';
|
||||
if (ucType.equals("RBG")) // Regental Bahnbetriebs GmbH, via JSON API
|
||||
|
@ -825,8 +779,6 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
if (ucType.equals("P")) // Kasbachtalbahn, via JSON API
|
||||
return 'R';
|
||||
|
||||
if (ucType.equals("S"))
|
||||
return 'S';
|
||||
if (ucType.equals("RSB")) // Schnellbahn Wien
|
||||
return 'S';
|
||||
if (ucType.equals("BSB")) // Breisgau S-Bahn, via JSON API
|
||||
|
@ -838,18 +790,11 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
if (ucType.equals("RER")) // Réseau Express Régional, Frankreich
|
||||
return 'S';
|
||||
|
||||
if (ucType.equals("U"))
|
||||
return 'U';
|
||||
|
||||
if (ucType.equals("STR"))
|
||||
return 'T';
|
||||
if (ucType.equals("LKB")) // Connections only?
|
||||
return 'T';
|
||||
if (ucType.equals("WLB")) // via JSON API
|
||||
return 'T';
|
||||
|
||||
if (ucType.equals("BUS"))
|
||||
return 'B';
|
||||
if (ucType.equals("RFB"))
|
||||
return 'B';
|
||||
if (ucType.equals("OBU")) // Connections only?
|
||||
|
@ -907,23 +852,4 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static final Map<Character, int[]> LINES = new HashMap<Character, int[]>();
|
||||
|
||||
static
|
||||
{
|
||||
LINES.put('I', new int[] { Color.WHITE, Color.RED, Color.RED });
|
||||
LINES.put('R', new int[] { Color.GRAY, Color.WHITE });
|
||||
LINES.put('S', new int[] { Color.parseColor("#006e34"), Color.WHITE });
|
||||
LINES.put('U', new int[] { Color.parseColor("#003090"), Color.WHITE });
|
||||
LINES.put('T', new int[] { Color.parseColor("#cc0000"), Color.WHITE });
|
||||
LINES.put('B', new int[] { Color.parseColor("#993399"), Color.WHITE });
|
||||
LINES.put('F', new int[] { Color.BLUE, Color.WHITE });
|
||||
LINES.put('?', new int[] { Color.DKGRAY, Color.WHITE });
|
||||
}
|
||||
|
||||
public int[] lineColors(final String line)
|
||||
{
|
||||
return LINES.get(line.charAt(0));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -319,7 +319,7 @@ public class RmvProvider extends AbstractHafasProvider
|
|||
else
|
||||
line = null;
|
||||
final Connection connection = new Connection(ParserUtils.extractId(link), link, departureTime, arrivalTime, line,
|
||||
line != null ? LINES.get(line.charAt(0)) : null, 0, from, 0, to, null);
|
||||
line != null ? lineColors(line) : null, 0, from, 0, to, null);
|
||||
connections.add(connection);
|
||||
}
|
||||
else
|
||||
|
@ -403,8 +403,8 @@ public class RmvProvider extends AbstractHafasProvider
|
|||
|
||||
final String arrivalPosition = ParserUtils.resolveEntities(mDetFine.group(6));
|
||||
|
||||
lastTrip = new Connection.Trip(line, line != null ? LINES.get(line.charAt(0)) : null, destination, departureTime,
|
||||
departurePosition, 0, departure, arrivalTime, arrivalPosition, 0, arrival);
|
||||
lastTrip = new Connection.Trip(line, line != null ? lineColors(line) : null, destination, departureTime, departurePosition,
|
||||
0, departure, arrivalTime, arrivalPosition, 0, arrival);
|
||||
parts.add(lastTrip);
|
||||
|
||||
if (firstDepartureTime == null)
|
||||
|
@ -556,8 +556,8 @@ public class RmvProvider extends AbstractHafasProvider
|
|||
|
||||
final String position = ParserUtils.resolveEntities(ParserUtils.selectNotNull(mDepFine.group(5), mDepFine.group(6)));
|
||||
|
||||
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line.charAt(0)) : null, null,
|
||||
position, 0, destination, null);
|
||||
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? lineColors(line) : null, null, position,
|
||||
0, destination, null);
|
||||
|
||||
if (!departures.contains(dep))
|
||||
departures.add(dep);
|
||||
|
@ -581,8 +581,6 @@ public class RmvProvider extends AbstractHafasProvider
|
|||
}
|
||||
}
|
||||
|
||||
private static final Pattern P_NORMALIZE_LINE = Pattern.compile("([A-Za-zÄÖÜäöüßáàâéèêíìîóòôúùû]+)[\\s-]*(.*)");
|
||||
|
||||
private static String normalizeLine(final String line)
|
||||
{
|
||||
if (line == null || line.length() == 0)
|
||||
|
@ -643,21 +641,9 @@ public class RmvProvider extends AbstractHafasProvider
|
|||
throw new IllegalStateException("cannot normalize line " + line);
|
||||
}
|
||||
|
||||
private static final Map<Character, int[]> LINES = new HashMap<Character, int[]>();
|
||||
|
||||
static
|
||||
@Override
|
||||
protected char normalizeType(final String type)
|
||||
{
|
||||
LINES.put('I', new int[] { Color.WHITE, Color.RED, Color.RED });
|
||||
LINES.put('R', new int[] { Color.GRAY, Color.WHITE });
|
||||
LINES.put('S', new int[] { Color.parseColor("#006e34"), Color.WHITE });
|
||||
LINES.put('U', new int[] { Color.parseColor("#003090"), Color.WHITE });
|
||||
LINES.put('T', new int[] { Color.parseColor("#cc0000"), Color.WHITE });
|
||||
LINES.put('B', new int[] { Color.parseColor("#993399"), Color.WHITE });
|
||||
LINES.put('F', new int[] { Color.BLUE, Color.WHITE });
|
||||
}
|
||||
|
||||
public int[] lineColors(final String line)
|
||||
{
|
||||
return LINES.get(line.charAt(0));
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,9 +24,7 @@ import java.util.ArrayList;
|
|||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -337,7 +335,7 @@ public class SbbProvider extends AbstractHafasProvider
|
|||
|
||||
final String arrivalPosition = mDetFine.group(13) != null ? ParserUtils.resolveEntities(mDetFine.group(13)) : null;
|
||||
|
||||
final Connection.Trip trip = new Connection.Trip(line, LINES.get(line.charAt(0)), null, departureTime, departurePosition,
|
||||
final Connection.Trip trip = new Connection.Trip(line, lineColors(line), null, departureTime, departurePosition,
|
||||
departureId, departure, arrivalTime, arrivalPosition, arrivalId, arrival);
|
||||
connection.parts.add(trip);
|
||||
}
|
||||
|
@ -466,8 +464,7 @@ public class SbbProvider extends AbstractHafasProvider
|
|||
|
||||
final String position = ParserUtils.resolveEntities(mDepFine.group(4));
|
||||
|
||||
final Departure dep = new Departure(parsed.getTime(), line, line != null ? LINES.get(line.charAt(0)) : null, position, 0,
|
||||
destination);
|
||||
final Departure dep = new Departure(parsed.getTime(), line, line != null ? lineColors(line) : null, position, 0, destination);
|
||||
|
||||
if (!departures.contains(dep))
|
||||
departures.add(dep);
|
||||
|
@ -491,21 +488,7 @@ public class SbbProvider extends AbstractHafasProvider
|
|||
}
|
||||
}
|
||||
|
||||
private static final Pattern P_NORMALIZE_LINE = Pattern.compile("([A-Za-zÄÖÜäöüßáàâéèêíìîóòôúùû]+)[\\s-]*(.*)");
|
||||
|
||||
private static String normalizeLine(final String type, final String line)
|
||||
{
|
||||
final Matcher m = P_NORMALIZE_LINE.matcher(line);
|
||||
final String strippedLine = m.matches() ? m.group(1) + m.group(2) : line;
|
||||
|
||||
final char normalizedType = normalizeType(type);
|
||||
if (normalizedType != 0)
|
||||
return normalizedType + strippedLine;
|
||||
|
||||
throw new IllegalStateException("cannot normalize type " + type + " line " + line);
|
||||
}
|
||||
|
||||
private static String normalizeLine(final String line)
|
||||
private String normalizeLine(final String line)
|
||||
{
|
||||
if (line == null || line.length() == 0)
|
||||
return null;
|
||||
|
@ -529,32 +512,17 @@ public class SbbProvider extends AbstractHafasProvider
|
|||
private static final Pattern P_NORMALIZE_TYPE_SBAHN = Pattern.compile("SN?\\d*");
|
||||
private static final Pattern P_NORMALIZE_TYPE_BUS = Pattern.compile("BUS\\w*");
|
||||
|
||||
private static char normalizeType(final String type)
|
||||
@Override
|
||||
protected char normalizeType(final String type)
|
||||
{
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
if (ucType.equals("EC")) // EuroCity
|
||||
return 'I';
|
||||
if (ucType.equals("EN")) // EuroNight
|
||||
return 'I';
|
||||
if (ucType.equals("ICE")) // InterCityExpress
|
||||
return 'I';
|
||||
if (ucType.equals("IC")) // InterCity
|
||||
return 'I';
|
||||
final char t = normalizeCommonTypes(ucType);
|
||||
if (t != 0)
|
||||
return t;
|
||||
|
||||
if (ucType.equals("ICN")) // Intercity-Neigezug, Schweiz
|
||||
return 'I';
|
||||
if (ucType.equals("CNL")) // CityNightLine
|
||||
return 'I';
|
||||
if (ucType.equals("THA")) // Thalys
|
||||
return 'I';
|
||||
if (ucType.equals("TGV")) // Train à Grande Vitesse
|
||||
return 'I';
|
||||
if (ucType.equals("RJ")) // RailJet, Österreichische Bundesbahnen
|
||||
return 'I';
|
||||
if (ucType.equals("OEC")) // ÖBB-EuroCity
|
||||
return 'I';
|
||||
if (ucType.equals("OIC")) // ÖBB-InterCity
|
||||
return 'I';
|
||||
if (ucType.equals("X")) // InterConnex
|
||||
return 'I';
|
||||
if (ucType.equals("ES")) // Eurostar Italia
|
||||
|
@ -574,14 +542,8 @@ public class SbbProvider extends AbstractHafasProvider
|
|||
if (ucType.equals("ARZ")) // Frankreich, Nacht
|
||||
return 'I';
|
||||
|
||||
if (ucType.equals("R"))
|
||||
return 'R';
|
||||
if (ucType.equals("RE")) // RegionalExpress
|
||||
return 'R';
|
||||
if (ucType.equals("IR"))
|
||||
return 'R';
|
||||
if (ucType.equals("IRE")) // Interregio Express
|
||||
return 'R';
|
||||
if (ucType.equals("D"))
|
||||
return 'R';
|
||||
if (ucType.equals("E"))
|
||||
|
@ -604,8 +566,6 @@ public class SbbProvider extends AbstractHafasProvider
|
|||
return 'R';
|
||||
if (ucType.equals("ATR")) // Spanien
|
||||
return 'R';
|
||||
if (ucType.equals("ZUG"))
|
||||
return 'R';
|
||||
|
||||
if (P_NORMALIZE_TYPE_SBAHN.matcher(ucType).matches())
|
||||
return 'S';
|
||||
|
@ -624,8 +584,6 @@ public class SbbProvider extends AbstractHafasProvider
|
|||
if (ucType.equals("NTR"))
|
||||
return 'T';
|
||||
|
||||
if (ucType.equals("BUS"))
|
||||
return 'B';
|
||||
if (ucType.equals("TRO"))
|
||||
return 'B';
|
||||
if (ucType.equals("NTO")) // Niederflurtrolleybus zwischen Bern, Bahnhofsplatz und Bern, Wankdorf Bahnhof
|
||||
|
@ -672,23 +630,4 @@ public class SbbProvider extends AbstractHafasProvider
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static final Map<Character, int[]> LINES = new HashMap<Character, int[]>();
|
||||
|
||||
static
|
||||
{
|
||||
LINES.put('I', new int[] { Color.WHITE, Color.RED, Color.RED });
|
||||
LINES.put('R', new int[] { Color.GRAY, Color.WHITE });
|
||||
LINES.put('S', new int[] { Color.parseColor("#006e34"), Color.WHITE });
|
||||
LINES.put('U', new int[] { Color.parseColor("#003090"), Color.WHITE });
|
||||
LINES.put('T', new int[] { Color.parseColor("#cc0000"), Color.WHITE });
|
||||
LINES.put('B', new int[] { Color.parseColor("#993399"), Color.WHITE });
|
||||
LINES.put('F', new int[] { Color.BLUE, Color.WHITE });
|
||||
LINES.put('?', new int[] { Color.DKGRAY, Color.WHITE });
|
||||
}
|
||||
|
||||
public int[] lineColors(final String line)
|
||||
{
|
||||
return LINES.get(line.charAt(0));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,20 @@
|
|||
/*
|
||||
* Copyright 2010 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;
|
||||
|
@ -5,14 +22,15 @@ import java.util.ArrayList;
|
|||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import de.schildbach.pte.QueryDeparturesResult.Status;
|
||||
|
||||
/**
|
||||
* @author Andreas Schildbach
|
||||
*/
|
||||
public class SncbProvider extends AbstractHafasProvider
|
||||
{
|
||||
public static final String NETWORK_ID = "hari.b-rail.be";
|
||||
|
@ -141,8 +159,7 @@ public class SncbProvider extends AbstractHafasProvider
|
|||
|
||||
mDepFine.group(4); // TODO delay
|
||||
|
||||
final Departure dep = new Departure(parsed.getTime(), line, line != null ? LINES.get(line.charAt(0)) : null, null, 0,
|
||||
destination);
|
||||
final Departure dep = new Departure(parsed.getTime(), line, line != null ? lineColors(line) : null, null, 0, destination);
|
||||
|
||||
if (!departures.contains(dep))
|
||||
departures.add(dep);
|
||||
|
@ -166,9 +183,7 @@ public class SncbProvider extends AbstractHafasProvider
|
|||
}
|
||||
}
|
||||
|
||||
private static final Pattern P_NORMALIZE_LINE = Pattern.compile("([A-Za-zÄÖÜäöüßáàâéèêíìîóòôúùû]+)[\\s-]*(.*)");
|
||||
|
||||
private static String normalizeLine(final String line)
|
||||
private String normalizeLine(final String line)
|
||||
{
|
||||
if (line == null || line.length() == 0)
|
||||
return null;
|
||||
|
@ -189,20 +204,17 @@ public class SncbProvider extends AbstractHafasProvider
|
|||
throw new IllegalStateException("cannot normalize line " + line);
|
||||
}
|
||||
|
||||
private static char normalizeType(final String type)
|
||||
@Override
|
||||
protected char normalizeType(final String type)
|
||||
{
|
||||
final String ucType = type.toUpperCase();
|
||||
|
||||
if (ucType.equals("ICE")) // InterCityExpress
|
||||
return 'I';
|
||||
if (ucType.equals("IC")) // InterCity
|
||||
return 'I';
|
||||
final char t = normalizeCommonTypes(ucType);
|
||||
if (t != 0)
|
||||
return t;
|
||||
|
||||
if (ucType.equals("EST")) // Eurostar Frankreich
|
||||
return 'I';
|
||||
if (ucType.equals("THA")) // Thalys
|
||||
return 'I';
|
||||
if (ucType.equals("TGV")) // Train à Grande Vitesse
|
||||
return 'I';
|
||||
if (ucType.equals("INT")) // Zürich-Brüssel
|
||||
return 'I';
|
||||
|
||||
|
@ -225,28 +237,6 @@ public class SncbProvider extends AbstractHafasProvider
|
|||
if (ucType.equals("TRA"))
|
||||
return 'T';
|
||||
|
||||
if (ucType.equals("BUS"))
|
||||
return 'B';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static final Map<Character, int[]> LINES = new HashMap<Character, int[]>();
|
||||
|
||||
static
|
||||
{
|
||||
LINES.put('I', new int[] { Color.WHITE, Color.RED, Color.RED });
|
||||
LINES.put('R', new int[] { Color.GRAY, Color.WHITE });
|
||||
LINES.put('S', new int[] { Color.parseColor("#006e34"), Color.WHITE });
|
||||
LINES.put('U', new int[] { Color.parseColor("#003090"), Color.WHITE });
|
||||
LINES.put('T', new int[] { Color.parseColor("#cc0000"), Color.WHITE });
|
||||
LINES.put('B', new int[] { Color.parseColor("#993399"), Color.WHITE });
|
||||
LINES.put('F', new int[] { Color.BLUE, Color.WHITE });
|
||||
LINES.put('?', new int[] { Color.DKGRAY, Color.WHITE });
|
||||
}
|
||||
|
||||
public int[] lineColors(final String line)
|
||||
{
|
||||
return LINES.get(line.charAt(0));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue