mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-20 09:19:57 +00:00
product selection for directions
git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@241 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
parent
89da3a9bba
commit
dcd673d6f7
21 changed files with 172 additions and 59 deletions
|
@ -556,6 +556,35 @@ public abstract class AbstractEfaProvider implements NetworkProvider
|
|||
return (double) value / 1000000;
|
||||
}
|
||||
|
||||
protected final String productParams(final String products)
|
||||
{
|
||||
if (products == null)
|
||||
return "";
|
||||
|
||||
final StringBuilder params = new StringBuilder("&includedMeans=checkbox");
|
||||
|
||||
for (final char p : products.toCharArray())
|
||||
{
|
||||
if (p == 'I' || p == 'R')
|
||||
params.append("&inclMOT_0=on");
|
||||
if (p == 'S')
|
||||
params.append("&inclMOT_1=on");
|
||||
if (p == 'U')
|
||||
params.append("&inclMOT_2=on");
|
||||
if (p == 'T')
|
||||
params.append("&inclMOT_3=on&inclMOT_4=on");
|
||||
if (p == 'B')
|
||||
params.append("&inclMOT_5=on&inclMOT_6=on&inclMOT_7=on&inclMOT_10=on");
|
||||
if (p == 'F')
|
||||
params.append("&inclMOT_9=on");
|
||||
if (p == 'C')
|
||||
params.append("&inclMOT_8=on");
|
||||
params.append("&inclMOT_11=on"); // TODO always show 'others', for now
|
||||
}
|
||||
|
||||
return params.toString();
|
||||
}
|
||||
|
||||
private static final Map<Character, int[]> LINES = new HashMap<Character, int[]>();
|
||||
|
||||
static
|
||||
|
|
|
@ -176,7 +176,8 @@ public final class BahnProvider implements NetworkProvider
|
|||
.compile("(zu dicht beieinander|mehrfach vorhanden oder identisch)|(leider konnte zu Ihrer Anfrage keine Verbindung gefunden werden)|(derzeit nur Auskünfte vom)");
|
||||
|
||||
public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed) throws IOException
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final String products, final WalkSpeed walkSpeed)
|
||||
throws IOException
|
||||
{
|
||||
final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep);
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
|
|
@ -85,7 +85,7 @@ public class GvhProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
public QueryConnectionsResult queryConnections(LocationType fromType, String from, LocationType viaType, String via, LocationType toType,
|
||||
String to, Date date, boolean dep, WalkSpeed walkSpeed) throws IOException
|
||||
String to, Date date, boolean dep, String products, WalkSpeed walkSpeed) throws IOException
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
|
|
@ -79,7 +79,8 @@ public class LinzProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed) throws IOException
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final String products, final WalkSpeed walkSpeed)
|
||||
throws IOException
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
|
|
@ -189,7 +189,7 @@ public class MvvProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
private String connectionsQueryUri(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed)
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final String products, final WalkSpeed walkSpeed)
|
||||
{
|
||||
final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
|
||||
final DateFormat YEAR_FORMAT = new SimpleDateFormat("yyyy");
|
||||
|
@ -305,6 +305,7 @@ public class MvvProvider extends AbstractEfaProvider
|
|||
uri.append("&itdTimeMinute=").append(ParserUtils.urlEncode(MINUTE_FORMAT.format(date)));
|
||||
uri.append("&itdDate=").append(ParserUtils.urlEncode(DATE_FORMAT.format(date)));
|
||||
uri.append("&changeSpeed=").append(WALKSPEED_MAP.get(walkSpeed));
|
||||
uri.append(productParams(products));
|
||||
|
||||
return uri.toString();
|
||||
}
|
||||
|
@ -342,9 +343,11 @@ public class MvvProvider extends AbstractEfaProvider
|
|||
"(Start und Ziel sind identisch)|(konnte keine Verbindung gefunden werden)", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed) throws IOException
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, String products, final WalkSpeed walkSpeed)
|
||||
throws IOException
|
||||
{
|
||||
final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep, walkSpeed);
|
||||
final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep, products, walkSpeed);
|
||||
System.out.println(uri);
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page);
|
||||
|
|
|
@ -251,7 +251,7 @@ public class NasaProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
public QueryConnectionsResult queryConnections(LocationType fromType, String from, LocationType viaType, String via, LocationType toType,
|
||||
String to, Date date, boolean dep, WalkSpeed walkSpeed) throws IOException
|
||||
String to, Date date, boolean dep, String products, WalkSpeed walkSpeed) throws IOException
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
|
|
@ -109,13 +109,16 @@ public interface NetworkProvider
|
|||
* desired date for departing, mandatory
|
||||
* @param dep
|
||||
* date is departure date? {@code true} for departure, {@code false} for arrival
|
||||
* @param products TODO
|
||||
* @param walkSpeed
|
||||
* how fast can you walk?
|
||||
* @param products
|
||||
* products to take into account
|
||||
* @return result object that can contain alternatives to clear up ambiguousnesses, or contains possible connections
|
||||
* @throws IOException
|
||||
*/
|
||||
QueryConnectionsResult queryConnections(LocationType fromType, String from, LocationType viaType, String via, LocationType toType, String to,
|
||||
Date date, boolean dep, WalkSpeed walkSpeed) throws IOException;
|
||||
Date date, boolean dep, String products, WalkSpeed walkSpeed) throws IOException;
|
||||
|
||||
/**
|
||||
* Query more connections (e.g. earlier or later)
|
||||
|
|
|
@ -152,7 +152,8 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
private String connectionsQuery(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed) throws IOException
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final String products, final WalkSpeed walkSpeed)
|
||||
throws IOException
|
||||
{
|
||||
final DateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yy");
|
||||
final DateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm");
|
||||
|
@ -179,11 +180,30 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
uri.append("&REQ0JourneyTime=").append(ParserUtils.urlEncode(TIME_FORMAT.format(date)));
|
||||
uri.append("&REQ0HafasSearchForw=").append(dep ? "1" : "0");
|
||||
uri.append("&existHafasDemo3=yes");
|
||||
uri.append("&REQ0JourneyProduct_list=").append(ParserUtils.urlEncode("0:1111111111010000-000000"));
|
||||
uri.append("&REQ0JourneyDep_Foot_speed=").append(WALKSPEED_MAP.get(walkSpeed));
|
||||
uri.append("&existBikeEverywhere=yes");
|
||||
uri.append("&existHafasAttrInc=yes");
|
||||
|
||||
for (final char p : products.toCharArray())
|
||||
{
|
||||
if (p == 'I')
|
||||
uri.append("&REQ0JourneyProduct_prod_section_0_0=1&REQ0JourneyProduct_prod_section_0_1=1&REQ0JourneyProduct_prod_section_0_2");
|
||||
if (p == 'R')
|
||||
uri.append("&REQ0JourneyProduct_prod_section_0_3=1&REQ0JourneyProduct_prod_section_0_4=1");
|
||||
if (p == 'S')
|
||||
uri.append("&REQ0JourneyProduct_prod_section_0_5=1");
|
||||
if (p == 'U')
|
||||
uri.append("&REQ0JourneyProduct_prod_section_0_8=1");
|
||||
if (p == 'T')
|
||||
uri.append("&REQ0JourneyProduct_prod_section_0_9=1");
|
||||
if (p == 'B')
|
||||
uri.append("&REQ0JourneyProduct_prod_section_0_6=1&REQ0JourneyProduct_prod_section_0_11=1");
|
||||
if (p == 'F')
|
||||
uri.append("&REQ0JourneyProduct_prod_section_0_7=1");
|
||||
if (p == 'C')
|
||||
; // FIXME
|
||||
}
|
||||
|
||||
return uri.toString();
|
||||
}
|
||||
|
||||
|
@ -208,7 +228,8 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
private static final Pattern P_ADDRESSES = Pattern.compile("<option[^>]*>\\s*([^<\\[]*)(?:\\[[^\\[]*\\])?\\s*</option>", Pattern.DOTALL);
|
||||
|
||||
public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed) throws IOException
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final String products, final WalkSpeed walkSpeed)
|
||||
throws IOException
|
||||
{
|
||||
// get base url and cookies from form
|
||||
final CharSequence form = ParserUtils.scrape(QUERY_CONNECTIONS_FORM_URL, false, null, null, true);
|
||||
|
@ -218,7 +239,7 @@ public class OebbProvider extends AbstractHafasProvider
|
|||
final String baseUri = m.group(1);
|
||||
|
||||
// query
|
||||
final String query = connectionsQuery(fromType, from, viaType, via, toType, to, date, dep, walkSpeed);
|
||||
final String query = connectionsQuery(fromType, from, viaType, via, toType, to, date, dep, products, walkSpeed);
|
||||
final CharSequence page = ParserUtils.scrape(baseUri, true, query, null, true);
|
||||
|
||||
final Matcher mError = P_QUERY_CONNECTIONS_ERROR.matcher(page);
|
||||
|
|
|
@ -176,7 +176,7 @@ public class RmvProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
private String connectionsQueryUri(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed)
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final String products, final WalkSpeed walkSpeed)
|
||||
{
|
||||
final DateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yy");
|
||||
final DateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm");
|
||||
|
@ -197,6 +197,27 @@ public class RmvProvider extends AbstractHafasProvider
|
|||
uri.append("&REQ0JourneyStops1.0A=").append(locationType(viaType));
|
||||
}
|
||||
uri.append("&REQ0JourneyDep_Foot_speed=").append(WALKSPEED_MAP.get(walkSpeed));
|
||||
|
||||
for (final char p : products.toCharArray())
|
||||
{
|
||||
if (p == 'I')
|
||||
uri.append("&REQ0JourneyProduct_prod_list_1=1000000000000000");
|
||||
if (p == 'R')
|
||||
uri.append("&REQ0JourneyProduct_prod_list_2=0110000000100000");
|
||||
if (p == 'S')
|
||||
uri.append("&REQ0JourneyProduct_prod_list_3=0001000000000000");
|
||||
if (p == 'U')
|
||||
uri.append("&REQ0JourneyProduct_prod_list_4=0000100000000000");
|
||||
if (p == 'T')
|
||||
uri.append("&REQ0JourneyProduct_prod_list_5=0000010000000000");
|
||||
if (p == 'B')
|
||||
uri.append("&REQ0JourneyProduct_prod_list_6=0000001101000000");
|
||||
if (p == 'F')
|
||||
uri.append("&REQ0JourneyProduct_prod_list_7=0000000010000000");
|
||||
if (p == 'C')
|
||||
; // FIXME
|
||||
}
|
||||
|
||||
uri.append("&start=Suchen");
|
||||
|
||||
return uri.toString();
|
||||
|
@ -221,9 +242,10 @@ public class RmvProvider extends AbstractHafasProvider
|
|||
"(mehrfach vorhanden oder identisch)|(keine Verbindung gefunden werden)|(derzeit nur Auskünfte vom)", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed) throws IOException
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final String products, final WalkSpeed walkSpeed)
|
||||
throws IOException
|
||||
{
|
||||
final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep, walkSpeed);
|
||||
final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep, products, walkSpeed);
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page);
|
||||
|
|
|
@ -126,6 +126,9 @@ public class SbbProvider extends AbstractHafasProvider
|
|||
uri.append("&REQ0JourneyStopsZ0ID=");
|
||||
uri.append("&REQ0JourneyTime=").append(ParserUtils.urlEncode(TIME_FORMAT.format(date)));
|
||||
uri.append("&queryPageDisplayed=yes");
|
||||
|
||||
// TODO products
|
||||
|
||||
uri.append("&start=Suchen");
|
||||
|
||||
return uri.toString();
|
||||
|
@ -149,7 +152,8 @@ public class SbbProvider extends AbstractHafasProvider
|
|||
.compile("(mehrfach vorhanden oder identisch)|(keine Verbindung gefunden werden)|(liegt nach dem Ende der Fahrplanperiode|liegt vor Beginn der Fahrplanperiode)");
|
||||
|
||||
public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed) throws IOException
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final String products, final WalkSpeed walkSpeed)
|
||||
throws IOException
|
||||
{
|
||||
final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep);
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
@ -528,7 +532,7 @@ public class SbbProvider extends AbstractHafasProvider
|
|||
final char t = normalizeCommonTypes(ucType);
|
||||
if (t != 0)
|
||||
return t;
|
||||
|
||||
|
||||
if (ucType.equals("ICN")) // Intercity-Neigezug, Schweiz
|
||||
return 'I';
|
||||
if (ucType.equals("X")) // InterConnex
|
||||
|
|
|
@ -72,7 +72,8 @@ public class SncbProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed) throws IOException
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final String products, final WalkSpeed walkSpeed)
|
||||
throws IOException
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
|
|
@ -66,7 +66,8 @@ public class TflProvider implements NetworkProvider
|
|||
}
|
||||
|
||||
public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed) throws IOException
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final String products, final WalkSpeed walkSpeed)
|
||||
throws IOException
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ public final class VbbProvider implements NetworkProvider
|
|||
public static final String STATION_URL_CONNECTION = "http://mobil.bvg.de/Fahrinfo/bin/query.bin/dox";
|
||||
|
||||
private String connectionsQueryUri(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep)
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final String products)
|
||||
{
|
||||
final DateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yy");
|
||||
final DateFormat TIME_FORMAT = new SimpleDateFormat("HH:mm");
|
||||
|
@ -223,8 +223,28 @@ public final class VbbProvider implements NetworkProvider
|
|||
uri.append("&REQ0HafasSearchForw=").append(dep ? "1" : "0");
|
||||
uri.append("&REQ0JourneyDate=").append(ParserUtils.urlEncode(DATE_FORMAT.format(date)));
|
||||
uri.append("&REQ0JourneyTime=").append(ParserUtils.urlEncode(TIME_FORMAT.format(date)));
|
||||
uri.append("&start=Suchen");
|
||||
|
||||
for (final char p : products.toCharArray())
|
||||
{
|
||||
if (p == 'I')
|
||||
uri.append("&vw=5");
|
||||
if (p == 'R')
|
||||
uri.append("&vw=6");
|
||||
if (p == 'S')
|
||||
uri.append("&vw=0");
|
||||
if (p == 'U')
|
||||
uri.append("&vw=1");
|
||||
if (p == 'T')
|
||||
uri.append("&vw=2");
|
||||
if (p == 'B')
|
||||
uri.append("&vw=3");
|
||||
if (p == 'F')
|
||||
uri.append("&vw=7");
|
||||
if (p == 'C')
|
||||
; // FIXME
|
||||
}
|
||||
|
||||
uri.append("&start=Suchen");
|
||||
return uri.toString();
|
||||
}
|
||||
|
||||
|
@ -246,9 +266,10 @@ public final class VbbProvider implements NetworkProvider
|
|||
.compile("(zu dicht beieinander|mehrfach vorhanden oder identisch)|(keine Verbindung gefunden)|(derzeit nur Auskünfte vom)");
|
||||
|
||||
public QueryConnectionsResult queryConnections(final LocationType fromType, final String from, final LocationType viaType, final String via,
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, final WalkSpeed walkSpeed) throws IOException
|
||||
final LocationType toType, final String to, final Date date, final boolean dep, String products, final WalkSpeed walkSpeed)
|
||||
throws IOException
|
||||
{
|
||||
final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep);
|
||||
final String uri = connectionsQueryUri(fromType, from, viaType, via, toType, to, date, dep, products);
|
||||
final CharSequence page = ParserUtils.scrape(uri);
|
||||
|
||||
final Matcher mError = P_CHECK_CONNECTIONS_ERROR.matcher(page);
|
||||
|
|
|
@ -248,7 +248,7 @@ public class VgsProvider extends AbstractHafasProvider
|
|||
}
|
||||
|
||||
public QueryConnectionsResult queryConnections(LocationType fromType, String from, LocationType viaType, String via, LocationType toType,
|
||||
String to, Date date, boolean dep, WalkSpeed walkSpeed) throws IOException
|
||||
String to, Date date, boolean dep, String products, WalkSpeed walkSpeed) throws IOException
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ public class VrnProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
public QueryConnectionsResult queryConnections(LocationType fromType, String from, LocationType viaType, String via, LocationType toType,
|
||||
String to, Date date, boolean dep, WalkSpeed walkSpeed) throws IOException
|
||||
String to, Date date, boolean dep, String products, WalkSpeed walkSpeed) throws IOException
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ public class VrrProvider extends AbstractEfaProvider
|
|||
}
|
||||
|
||||
public QueryConnectionsResult queryConnections(LocationType fromType, String from, LocationType viaType, String via, LocationType toType,
|
||||
String to, Date date, boolean dep, WalkSpeed walkSpeed) throws IOException
|
||||
String to, Date date, boolean dep, String products, WalkSpeed walkSpeed) throws IOException
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue