mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-07 22:08:49 +00:00
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:
parent
b9571a9399
commit
fc12d20236
6 changed files with 40 additions and 10 deletions
|
@ -450,6 +450,7 @@ public final class BahnProvider implements NetworkProvider
|
||||||
+ ">>\n\\s*(.+?)\\s*\n<br />\n" // destination
|
+ ">>\n\\s*(.+?)\\s*\n<br />\n" // destination
|
||||||
+ "<span class=\"bold\">(\\d{1,2}:\\d{2})</span>" // time
|
+ "<span class=\"bold\">(\\d{1,2}:\\d{2})</span>" // time
|
||||||
+ "(?: <span class=\"[\\w ]*\">(?:(pünktl\\.)|ca. \\+(\\d+))</span>)?" // ontime, delay
|
+ "(?: <span class=\"[\\w ]*\">(?:(pünktl\\.)|ca. \\+(\\d+))</span>)?" // ontime, delay
|
||||||
|
+ "(?:, <span class=\"red\">([^<]*)</span>)?" // (message)
|
||||||
+ "(?:(?:, )?(Gl\\. " + ParserUtils.P_PLATFORM + "))?" // position
|
+ "(?:(?:, )?(Gl\\. " + ParserUtils.P_PLATFORM + "))?" // position
|
||||||
, Pattern.DOTALL);
|
, Pattern.DOTALL);
|
||||||
private static final Pattern P_DEPARTURES_URI_STATION_ID = Pattern.compile("input=(\\d+)");
|
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();
|
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,
|
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))
|
if (!departures.contains(dep))
|
||||||
departures.add(dep);
|
departures.add(dep);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,9 +31,10 @@ public final class Departure
|
||||||
final public String position;
|
final public String position;
|
||||||
final public int destinationId;
|
final public int destinationId;
|
||||||
final public String destination;
|
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,
|
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.plannedTime = plannedTime;
|
||||||
this.predictedTime = predictedTime;
|
this.predictedTime = predictedTime;
|
||||||
|
@ -42,6 +43,7 @@ public final class Departure
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.destinationId = destinationId;
|
this.destinationId = destinationId;
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Departure(final Date plannedTime, final String line, final int[] lineColors, final String position, final int destinationId,
|
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.position = position;
|
||||||
this.destinationId = destinationId;
|
this.destinationId = destinationId;
|
||||||
this.destination = destination;
|
this.destination = destination;
|
||||||
|
this.message = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -481,7 +481,7 @@ public class OebbProvider implements NetworkProvider
|
||||||
final String position = mDepFine.group(7) != null ? "Gl. " + ParserUtils.resolveEntities(mDepFine.group(7)) : null;
|
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,
|
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))
|
if (!departures.contains(dep))
|
||||||
departures.add(dep);
|
departures.add(dep);
|
||||||
|
|
|
@ -522,7 +522,7 @@ public class RmvProvider implements NetworkProvider
|
||||||
final String position = ParserUtils.resolveEntities(mDepFine.group(5));
|
final String position = ParserUtils.resolveEntities(mDepFine.group(5));
|
||||||
|
|
||||||
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line.charAt(0)) : null,
|
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))
|
if (!departures.contains(dep))
|
||||||
departures.add(dep);
|
departures.add(dep);
|
||||||
|
|
|
@ -601,7 +601,7 @@ public final class VbbProvider implements NetworkProvider
|
||||||
final String destination = ParserUtils.resolveEntities(mDepFine.group(live ? 4 : 5));
|
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,
|
final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line) : null, position,
|
||||||
destinationId, destination);
|
destinationId, destination, null);
|
||||||
if (!departures.contains(dep))
|
if (!departures.contains(dep))
|
||||||
departures.add(dep);
|
departures.add(dep);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
|
|
||||||
package de.schildbach.pte;
|
package de.schildbach.pte;
|
||||||
|
|
||||||
|
import static junit.framework.Assert.assertNotNull;
|
||||||
import static junit.framework.Assert.assertTrue;
|
import static junit.framework.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
@ -31,7 +32,8 @@ public class BahnProviderTest
|
||||||
@Test
|
@Test
|
||||||
public void connectionUebergang()
|
public void connectionUebergang()
|
||||||
{
|
{
|
||||||
assertFineConnectionDetails("<span class=\"bold\">Berlin Hbf</span><br />\n" //
|
assertFineConnectionDetails("" //
|
||||||
|
+ "<span class=\"bold\">Berlin Hbf</span><br />\n" //
|
||||||
+ "Übergang\n" //
|
+ "Übergang\n" //
|
||||||
+ "<br />\n" //
|
+ "<br />\n" //
|
||||||
+ "<span class=\"bold\">Berlin-Lichtenberg</span><br />");
|
+ "<span class=\"bold\">Berlin-Lichtenberg</span><br />");
|
||||||
|
@ -40,7 +42,8 @@ public class BahnProviderTest
|
||||||
@Test
|
@Test
|
||||||
public void departureWithPlatform()
|
public void departureWithPlatform()
|
||||||
{
|
{
|
||||||
assertFineDepartures("<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/731061/244203/590672/51649/80/si=8100352&bt=dep&ti=10:42&pt=10:42&p=1111111111&date=01.09.10&max=10&rt=1&&\">\n" //
|
assertFineDepartures("" //
|
||||||
|
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/731061/244203/590672/51649/80/si=8100352&bt=dep&ti=10:42&pt=10:42&p=1111111111&date=01.09.10&max=10&rt=1&&\">\n" //
|
||||||
+ "<span class=\"bold\">S 1</span>\n" //
|
+ "<span class=\"bold\">S 1</span>\n" //
|
||||||
+ "</a>\n" //
|
+ "</a>\n" //
|
||||||
+ ">>\n" //
|
+ ">>\n" //
|
||||||
|
@ -52,7 +55,8 @@ public class BahnProviderTest
|
||||||
@Test
|
@Test
|
||||||
public void departureWithOnTime()
|
public void departureWithOnTime()
|
||||||
{
|
{
|
||||||
assertFineDepartures("<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/438441/245165/958/145668/80/si=8011160&bt=dep&ti=21:47&pt=21:47&p=1111101&date=05.09.10&max=10&rt=1&&\">\n" //
|
assertFineDepartures("" //
|
||||||
|
+ "<a href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/438441/245165/958/145668/80/si=8011160&bt=dep&ti=21:47&pt=21:47&p=1111101&date=05.09.10&max=10&rt=1&&\">\n" //
|
||||||
+ "<span class=\"bold\">RE 38148</span>\n" //
|
+ "<span class=\"bold\">RE 38148</span>\n" //
|
||||||
+ "</a>\n" //
|
+ "</a>\n" //
|
||||||
+ ">>\n" //
|
+ ">>\n" //
|
||||||
|
@ -61,10 +65,24 @@ public class BahnProviderTest
|
||||||
+ "<span class=\"bold\">21:58</span> <span class=\"green bold\">pünktl.</span>, Gl. 13");
|
+ "<span class=\"bold\">21:58</span> <span class=\"green bold\">pünktl.</span>, 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&bt=dep&ti=07:08&pt=07:08&p=1111111111&date=06.09.10&max=10&rt=1&&\">\n" //
|
||||||
|
+ "<span class=\"bold\">ICE 824</span>\n" //
|
||||||
|
+ "</a>\n" //
|
||||||
|
+ ">>\n" //
|
||||||
|
+ "Dortmund Hbf\n" //
|
||||||
|
+ "<br />\n" //
|
||||||
|
+ "<span class=\"bold\">07:02</span> <span class=\"red\">ca. +5</span>, <span class=\"red\">Fährt heute nur bis Düsseldorf Hbf</span>, Gl. 10");
|
||||||
|
}
|
||||||
|
|
||||||
private void assertFineConnectionDetails(String s)
|
private void assertFineConnectionDetails(String s)
|
||||||
{
|
{
|
||||||
Matcher m = BahnProvider.P_CONNECTION_DETAILS_FINE.matcher(s);
|
Matcher m = BahnProvider.P_CONNECTION_DETAILS_FINE.matcher(s);
|
||||||
assertTrue(m.matches());
|
assertTrue(m.matches());
|
||||||
|
|
||||||
// ParserUtils.printGroups(m);
|
// ParserUtils.printGroups(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,6 +90,12 @@ public class BahnProviderTest
|
||||||
{
|
{
|
||||||
Matcher m = BahnProvider.P_DEPARTURES_FINE.matcher(s);
|
Matcher m = BahnProvider.P_DEPARTURES_FINE.matcher(s);
|
||||||
assertTrue(m.matches());
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue