fixed footways for Switzerland

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@103 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach 2010-08-24 22:30:14 +00:00
parent 6e764348fb
commit 672f13519f
3 changed files with 87 additions and 31 deletions

View file

@ -103,16 +103,16 @@ public class SbbProvider implements NetworkProvider
uri.append("&REQ0HafasSkipLongChanges=1");
uri.append("&REQ0JourneyDate=").append(ParserUtils.urlEncode(DATE_FORMAT.format(date)));
uri.append("&REQ0JourneyStopsS0G=").append(ParserUtils.urlEncode(from));
uri.append("&REQ0JourneyStopsS0A=1");
uri.append("&REQ0JourneyStopsS0A=7"); // any
uri.append("&REQ0JourneyStopsS0ID=");
if (via != null)
{
uri.append("&REQ0JourneyStops1.0G=").append(ParserUtils.urlEncode(via));
uri.append("&REQ0JourneyStops1.0A=1");
uri.append("&REQ0JourneyStops1.0A=7"); // any
uri.append("&REQ0JourneyStops1.0ID=");
}
uri.append("&REQ0JourneyStopsZ0G=").append(ParserUtils.urlEncode(to));
uri.append("&REQ0JourneyStopsZ0A=1");
uri.append("&REQ0JourneyStopsZ0A=7"); // any
uri.append("&REQ0JourneyStopsZ0ID=");
uri.append("&REQ0JourneyTime=").append(ParserUtils.urlEncode(TIME_FORMAT.format(date)));
uri.append("&queryPageDisplayed=yes");
@ -202,18 +202,21 @@ public class SbbProvider implements NetworkProvider
private static final Pattern P_CONNECTION_DETAILS_COARSE = Pattern.compile("<tr>(.*?class=\"stop-station-icon\".*?)</tr>\n?" //
+ "<tr>(.*?class=\"stop-station-icon last\".*?)</tr>", Pattern.DOTALL);
static final Pattern P_CONNECTION_DETAILS_FINE = Pattern.compile(".*?" //
+ "<a href=\"http://fahrplan\\.sbb\\.ch/bin/bhftafel\\.exe/dn.*?input=(\\d+)&.*?\" .*?>" // departureId
+ "(.*?)</a>.*?" // departure
+ "<td .*?class=\"date.*?>\n?(?:.., (\\d{2}\\.\\d{2}\\.\\d{2})\n?)?</td>.*?" // departureDate
+ "<td .*?class=\"time.*?>(?:(\\d{2}:\\d{2})|&nbsp;)</td>.*?" // departureTime
+ "<td .*?class=\"platform.*?>\n?\\s*(.+?)?\\s*\n?</td>.*?" // departurePosition
+ "<img src=\"/img/2/products/(\\w+?)_pic.gif\" .*? alt=\"(.*?)\" .*?><br />.*?" // line
+ "(?:<td .*?class=\"remarks.*?>\n?(\\d+) Min\\..*?</td>.*?)?" // min
+ "<a href=\"http://fahrplan\\.sbb\\.ch/bin/bhftafel\\.exe/dn.*?input=(\\d+)&.*?\" .*?>" // arrivalId,
+ "(.*?)</a>.*?" // arrival
+ "<td .*?class=\"date.*?>\n?(?:.., (\\d{2}\\.\\d{2}\\.\\d{2})\n?)?</td>.*?" // arrivalDate
+ "<td .*?class=\"time.*?>(?:(\\d{2}:\\d{2})|&nbsp;)</td>.*?" // arrivalTime
+ "<td .*?class=\"platform.*?>\n?\\s*(.+?)?\\s*\n?</td>.*?" // arrivalPosition
+ "<td headers=\"stops-\\d+\" class=\"stop-station\">\n" //
+ "(?:<a href=\"http://fahrplan\\.sbb\\.ch/bin/bhftafel\\.exe/dn.*?input=(\\d+)&.*?>)?" // departureId
+ "([^\n<]*?)<.*?" // departure
+ "<td headers=\"date-\\d+\"[^>]*>\n(?:.., (\\d{2}\\.\\d{2}\\.\\d{2})\n)?</td>.*?" // departureDate
+ "<td headers=\"time-\\d+\"[^>]*>(?:(\\d{2}:\\d{2})|&nbsp;)</td>.*?" // departureTime
+ "<td headers=\"platform-\\d+\"[^>]*>\\s*(.+?)?\\s*</td>.*?" // departurePosition
+ "<img src=\"/img/2/products/(\\w+?)_pic.gif\".*?" // lineType
+ "(?:<a href=\"http://fahrplan\\.sbb\\.ch/bin/traininfo\\.exe/dn.*?>\\s*(.*?)\\s*</a>|" // line
+ "\n(\\d+) Min\\.).*?" // min
+ "<td headers=\"stops-\\d+\" class=\"stop-station last\">\n" //
+ "(?:<a href=\"http://fahrplan\\.sbb\\.ch/bin/bhftafel\\.exe/dn.*?input=(\\d+)&.*?>)?" // arrivalId
+ "([^\n<]*?)<.*?" // arrival
+ "<td headers=\"date-\\d+\"[^>]*>\n(?:.., (\\d{2}\\.\\d{2}\\.\\d{2})\n)?</td>.*?" // arrivalDate
+ "<td headers=\"time-\\d+\"[^>]*>(?:(\\d{2}:\\d{2})|&nbsp;)</td>.*?" // arrivalTime
+ "<td headers=\"platform-\\d+\"[^>]*>\\s*(.+?)?\\s*</td>.*?" // arrivalPosition
, Pattern.DOTALL);
private QueryConnectionsResult queryConnections(final String uri, final CharSequence page) throws IOException
@ -269,23 +272,27 @@ public class SbbProvider implements NetworkProvider
final Matcher mDetFine = P_CONNECTION_DETAILS_FINE.matcher(set);
if (mDetFine.matches())
{
final int departureId = Integer.parseInt(mDetFine.group(1));
final String departure = ParserUtils.resolveEntities(mDetFine.group(2));
Date departureDate = mDetFine.group(3) != null ? ParserUtils.parseDate(mDetFine.group(3)) : null;
if (departureDate != null)
lastDate = departureDate;
else
departureDate = lastDate;
final String lineType = mDetFine.group(6);
final int arrivalId = Integer.parseInt(mDetFine.group(9));
final String arrival = ParserUtils.resolveEntities(mDetFine.group(10));
Date arrivalDate = mDetFine.group(11) != null ? ParserUtils.parseDate(mDetFine.group(11)) : null;
if (arrivalDate != null)
lastDate = arrivalDate;
else
arrivalDate = lastDate;
if (!lineType.equals("fuss") && !lineType.equals("transfer"))
{
Date departureDate = mDetFine.group(3) != null ? ParserUtils.parseDate(mDetFine.group(3)) : null;
if (departureDate != null)
lastDate = departureDate;
else
departureDate = lastDate;
final int departureId = Integer.parseInt(mDetFine.group(1));
final Date departureTime = ParserUtils.joinDateTime(departureDate, ParserUtils.parseTime(mDetFine.group(4)));
@ -293,11 +300,7 @@ public class SbbProvider implements NetworkProvider
final String line = normalizeLine(lineType, ParserUtils.resolveEntities(mDetFine.group(7)));
Date arrivalDate = mDetFine.group(11) != null ? ParserUtils.parseDate(mDetFine.group(11)) : null;
if (arrivalDate != null)
lastDate = arrivalDate;
else
arrivalDate = lastDate;
final int arrivalId = Integer.parseInt(mDetFine.group(9));
final Date arrivalTime = ParserUtils.joinDateTime(arrivalDate, ParserUtils.parseTime(mDetFine.group(12)));
@ -330,7 +333,7 @@ public class SbbProvider implements NetworkProvider
}
}
private Connection findConnection(List<Connection> connections, String id)
private Connection findConnection(final List<Connection> connections, final String id)
{
for (final Connection connection : connections)
if (connection.id.equals(id))

View file

@ -18,6 +18,7 @@
package de.schildbach.pte;
import static junit.framework.Assert.assertTrue;
import static junit.framework.Assert.assertNotNull;
import java.util.regex.Matcher;
@ -113,7 +114,7 @@ public class SbbProviderTest
}
@Test
public void footway()
public void footwayFromStationToStation()
{
assertFineConnectionDetails("\n" //
+ "<td headers=\"stops-0\" class=\"stop-station-icon\" valign=\"top\">\n" //
@ -150,10 +151,52 @@ public class SbbProviderTest
+ "</td>\n");
}
@Test
public void footwayFromStationToAddress()
{
assertFineConnectionDetails("\n" //
+ "<td headers=\"stops-0\" class=\"stop-station-icon\" valign=\"top\">\n" //
+ "<a href=\"http://fahrplan.sbb.ch/bin/query.exe/dn?ld=&i=0y.01800219.1282687338&n=1&uscid=30\"><img src=\"/img/2/icon_map_location.gif\" width=\"12\" height=\"12\" border=\"0\" alt=\"Umgebungskarte: Einsiedeln, Birchli/Garage\" hspace=\"3\" style=\"vertical-align:middle;margin-right:4px;\" /></a>\n" //
+ "</td>\n" //
+ "<td headers=\"stops-0\" class=\"stop-station\">\n" //
+ "<a href=\"http://fahrplan.sbb.ch/bin/bhftafel.exe/dn?seqnr=1&ident=0y.01800219.1282687338&input=8580858&boardType=dep&time=08:09\" title=\"Haltestelleninformation: Einsiedeln, Birchli/Garage\">Einsiedeln, Birchli/Garage</a></td>\n" //
+ "<td headers=\"date-0\" class=\"date\" align=\"left\">\n" //
+ "</td>\n" //
+ "<td headers=\"time-0\" class=\"time prefix timeLeft\" align=\"left\" nowrap=\"nowrap\">&nbsp;</td><td headers=\"time-0\" class=\"time timeRight\" align=\"left\" nowrap=\"nowrap\">&nbsp;</td><td headers=\"platform-0\" class=\"platform\" align=\"left\">\n" //
+ "</td>\n" //
+ "<td headers=\"products-0\" class=\"products last\" style=\"white-space:nowrap;\" rowspan=\"2\" valign=\"top\">\n" //
+ "<img src=\"/img/2/products/fuss_pic.gif\" width=\"18\" height=\"18\" border=\"0\" vspace=\"2\" alt=\"Fussweg\" /><br />\n" //
+ "<a href=\"http://fahrplan.sbb.ch/bin/query.exe/dn?ld=&i=0y.01800219.1282687338&n=1&uscid=31\">Fussweg</a>\n" //
+ "</td>\n" //
+ "<td headers=\"capacity-0\" class=\"capacity last\" style=\"white-space:nowrap;\" rowspan=\"2\" valign=\"top\">\n" //
+ "<div style=\"width:65px;height:15px;line-height:15px;\">\n" //
+ "<div style=\"float:left;width:30px;height:15px;line-height:15px;\">\n" //
+ "</div>\n" //
+ "<div style=\"float:left;width:30px;height:15px;line-height:15px;margin-left:4px;\">\n" //
+ "</div>\n" //
+ "</div>\n" //
+ "</td>\n" //
+ "<td headers=\"remarks-0\" class=\"remarks last\" rowspan=\"2\" valign=\"top\">\n" //
+ "9 Min. </td>\n" //
+ "\n" //
+ "<td headers=\"stops-0\" class=\"stop-station-icon last\" valign=\"top\">\n" //
+ "<a href=\"http://fahrplan.sbb.ch/bin/query.exe/dn?ld=&i=0y.01800219.1282687338&n=1&uscid=32\"><img src=\"/img/2/icon_map_location.gif\" width=\"12\" height=\"12\" border=\"0\" alt=\"Umgebungskarte: 8840 Einsiedeln, Erlenmoosweg 24\" hspace=\"3\" style=\"vertical-align:middle;margin-right:4px;\" /></a></td>\n" //
+ "<td headers=\"stops-0\" class=\"stop-station last\">\n" //
+ "8840 Einsiedeln, Erlenmoosweg 24</td>\n" //
+ "<td headers=\"date-0\" class=\"date last\" align=\"left\">\n" //
+ "</td>\n" //
+ "<td headers=\"time-0\" class=\"time prefix last timeLeft\" align=\"left\" nowrap=\"nowrap\">&nbsp;</td><td headers=\"time-0\" class=\"time last timeRight\" align=\"left\" nowrap=\"nowrap\">&nbsp;</td><td headers=\"platform-0\" class=\"platform last\" align=\"left\">\n" //
+ "</td>\n");
}
private void assertFineConnectionDetails(String s)
{
Matcher m = SbbProvider.P_CONNECTION_DETAILS_FINE.matcher(s);
assertTrue(m.matches());
// ParserUtils.printGroups(m);
assertNotNull(m.group(2)); // departure
assertNotNull(m.group(10)); // arrival
}
}

View file

@ -51,4 +51,14 @@ public class SbbProviderLiveTest
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.linkLater);
System.out.println(moreResult);
}
@Test
public void connectionWithFootway() throws Exception
{
final QueryConnectionsResult result = provider.queryConnections(LocationType.ANY, "Spiez, Seestraße 62", null, null, LocationType.ANY,
"Einsiedeln, Erlenmoosweg 24", new Date(), true);
System.out.println(result);
final QueryConnectionsResult moreResult = provider.queryMoreConnections(result.linkLater);
System.out.println(moreResult);
}
}