parse departure message for Germany

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@141 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach 2010-09-06 09:54:17 +00:00
parent b9571a9399
commit fc12d20236
6 changed files with 40 additions and 10 deletions

View file

@ -450,6 +450,7 @@ public final class BahnProvider implements NetworkProvider
+ "&gt;&gt;\n\\s*(.+?)\\s*\n<br />\n" // destination
+ "<span class=\"bold\">(\\d{1,2}:\\d{2})</span>" // time
+ "(?:&nbsp;<span class=\"[\\w ]*\">(?:(p&#252;nktl\\.)|ca. \\+(\\d+))</span>)?" // ontime, delay
+ "(?:, <span class=\"red\">([^<]*)</span>)?" // (message)
+ "(?:(?:,&nbsp;)?(Gl\\. " + ParserUtils.P_PLATFORM + "))?" // position
, Pattern.DOTALL);
private static final Pattern P_DEPARTURES_URI_STATION_ID = Pattern.compile("input=(\\d+)");
@ -508,10 +509,12 @@ public final class BahnProvider implements NetworkProvider
predictedTime = parsed.getTime();
}
final String position = ParserUtils.resolveEntities(mDepFine.group(6));
final String message = ParserUtils.resolveEntities(mDepFine.group(6));
final String position = ParserUtils.resolveEntities(mDepFine.group(7));
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line.charAt(0)) : null,
position, 0, destination);
position, 0, destination, message);
if (!departures.contains(dep))
departures.add(dep);
}

View file

@ -31,9 +31,10 @@ public final class Departure
final public String position;
final public int destinationId;
final public String destination;
final public String message;
public Departure(final Date plannedTime, final Date predictedTime, final String line, final int[] lineColors, final String position,
final int destinationId, final String destination)
final int destinationId, final String destination, final String message)
{
this.plannedTime = plannedTime;
this.predictedTime = predictedTime;
@ -42,6 +43,7 @@ public final class Departure
this.position = position;
this.destinationId = destinationId;
this.destination = destination;
this.message = message;
}
public Departure(final Date plannedTime, final String line, final int[] lineColors, final String position, final int destinationId,
@ -54,6 +56,7 @@ public final class Departure
this.position = position;
this.destinationId = destinationId;
this.destination = destination;
this.message = null;
}
@Override

View file

@ -481,7 +481,7 @@ public class OebbProvider implements NetworkProvider
final String position = mDepFine.group(7) != null ? "Gl. " + ParserUtils.resolveEntities(mDepFine.group(7)) : null;
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line.charAt(0)) : null,
position, destinationId, destination);
position, destinationId, destination, null);
if (!departures.contains(dep))
departures.add(dep);

View file

@ -522,7 +522,7 @@ public class RmvProvider implements NetworkProvider
final String position = ParserUtils.resolveEntities(mDepFine.group(5));
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line.charAt(0)) : null,
position, 0, destination);
position, 0, destination, null);
if (!departures.contains(dep))
departures.add(dep);

View file

@ -601,7 +601,7 @@ public final class VbbProvider implements NetworkProvider
final String destination = ParserUtils.resolveEntities(mDepFine.group(live ? 4 : 5));
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line) : null, position,
destinationId, destination);
destinationId, destination, null);
if (!departures.contains(dep))
departures.add(dep);
}

View file

@ -17,6 +17,7 @@
package de.schildbach.pte;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import java.util.regex.Matcher;
@ -31,7 +32,8 @@ public class BahnProviderTest
@Test
public void connectionUebergang()
{
assertFineConnectionDetails("<span class=\"bold\">Berlin Hbf</span><br />\n" //
assertFineConnectionDetails("" //
+ "<span class=\"bold\">Berlin Hbf</span><br />\n" //
+ "&#220;bergang\n" //
+ "<br />\n" //
+ "<span class=\"bold\">Berlin-Lichtenberg</span><br />");
@ -40,7 +42,8 @@ public class BahnProviderTest
@Test
public void departureWithPlatform()
{
assertFineDepartures("<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/731061/244203/590672/51649/80/si=8100352&amp;bt=dep&amp;ti=10:42&amp;pt=10:42&amp;p=1111111111&amp;date=01.09.10&amp;max=10&amp;rt=1&amp;&amp;\">\n" //
assertFineDepartures("" //
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/731061/244203/590672/51649/80/si=8100352&amp;bt=dep&amp;ti=10:42&amp;pt=10:42&amp;p=1111111111&amp;date=01.09.10&amp;max=10&amp;rt=1&amp;&amp;\">\n" //
+ "<span class=\"bold\">S 1</span>\n" //
+ "</a>\n" //
+ "&gt;&gt;\n" //
@ -52,7 +55,8 @@ public class BahnProviderTest
@Test
public void departureWithOnTime()
{
assertFineDepartures("<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/438441/245165/958/145668/80/si=8011160&amp;bt=dep&amp;ti=21:47&amp;pt=21:47&amp;p=1111101&amp;date=05.09.10&amp;max=10&amp;rt=1&amp;&amp;\">\n" //
assertFineDepartures("" //
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/438441/245165/958/145668/80/si=8011160&amp;bt=dep&amp;ti=21:47&amp;pt=21:47&amp;p=1111101&amp;date=05.09.10&amp;max=10&amp;rt=1&amp;&amp;\">\n" //
+ "<span class=\"bold\">RE 38148</span>\n" //
+ "</a>\n" //
+ "&gt;&gt;\n" //
@ -61,10 +65,24 @@ public class BahnProviderTest
+ "<span class=\"bold\">21:58</span>&nbsp;<span class=\"green bold\">p&#252;nktl.</span>,&nbsp;Gl. 13");
}
@Test
public void departureWithMessage()
{
assertFineDepartures("" //
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/551037/330609/12448/177455/80/si=405341&amp;bt=dep&amp;ti=07:08&amp;pt=07:08&amp;p=1111111111&amp;date=06.09.10&amp;max=10&amp;rt=1&amp;&amp;\">\n" //
+ "<span class=\"bold\">ICE 824</span>\n" //
+ "</a>\n" //
+ "&gt;&gt;\n" //
+ "Dortmund Hbf\n" //
+ "<br />\n" //
+ "<span class=\"bold\">07:02</span>&nbsp;<span class=\"red\">ca. +5</span>, <span class=\"red\">F&#228;hrt heute nur bis&nbsp;D&#252;sseldorf Hbf</span>,&nbsp;Gl. 10");
}
private void assertFineConnectionDetails(String s)
{
Matcher m = BahnProvider.P_CONNECTION_DETAILS_FINE.matcher(s);
assertTrue(m.matches());
// ParserUtils.printGroups(m);
}
@ -72,6 +90,12 @@ public class BahnProviderTest
{
Matcher m = BahnProvider.P_DEPARTURES_FINE.matcher(s);
assertTrue(m.matches());
// ParserUtils.printGroups(m);
ParserUtils.printGroups(m);
assertNotNull(m.group(1)); // line
assertNotNull(m.group(2)); // destination
assertNotNull(m.group(3)); // time
assertNotNull(m.group(6)); // departure
}
}