parse lineLink for Germany

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@179 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach 2010-09-22 18:52:34 +00:00
parent 76026f46ce
commit 5812a35d67
6 changed files with 55 additions and 39 deletions

View file

@ -456,7 +456,7 @@ public final class BahnProvider implements NetworkProvider
, Pattern.DOTALL); , Pattern.DOTALL);
private static final Pattern P_DEPARTURES_COARSE = Pattern.compile("<div class=\"sqdetailsDep trow\">\n(.+?)</div>", Pattern.DOTALL); private static final Pattern P_DEPARTURES_COARSE = Pattern.compile("<div class=\"sqdetailsDep trow\">\n(.+?)</div>", Pattern.DOTALL);
static final Pattern P_DEPARTURES_FINE = Pattern.compile(".*?" // static final Pattern P_DEPARTURES_FINE = Pattern.compile(".*?" //
+ "<a href=\"http://mobile\\.bahn\\.de/bin/mobil/traininfo.exe/dox[^\"]*\">\n" // + "<a href=\"(http://mobile\\.bahn\\.de/bin/mobil/traininfo.exe/dox[^\"]*)\">\n" // lineLink
+ "<span class=\"bold\">(.*?)</span>\n" // line + "<span class=\"bold\">(.*?)</span>\n" // line
+ "</a>\n" // + "</a>\n" //
+ "&gt;&gt;\n" // + "&gt;&gt;\n" //
@ -504,14 +504,16 @@ public final class BahnProvider implements NetworkProvider
final Matcher mDepFine = P_DEPARTURES_FINE.matcher(mDepCoarse.group(1)); final Matcher mDepFine = P_DEPARTURES_FINE.matcher(mDepCoarse.group(1));
if (mDepFine.matches()) if (mDepFine.matches())
{ {
final String line = normalizeLine(ParserUtils.resolveEntities(mDepFine.group(1))); final String lineLink = ParserUtils.resolveEntities(mDepFine.group(1));
final String destination = ParserUtils.resolveEntities(mDepFine.group(2)); final String line = normalizeLine(ParserUtils.resolveEntities(mDepFine.group(2)));
final String destination = ParserUtils.resolveEntities(mDepFine.group(3));
final Calendar current = new GregorianCalendar(); final Calendar current = new GregorianCalendar();
current.setTime(currentTime); current.setTime(currentTime);
final Calendar parsed = new GregorianCalendar(); final Calendar parsed = new GregorianCalendar();
parsed.setTime(ParserUtils.parseTime(mDepFine.group(3))); parsed.setTime(ParserUtils.parseTime(mDepFine.group(4)));
parsed.set(Calendar.YEAR, current.get(Calendar.YEAR)); parsed.set(Calendar.YEAR, current.get(Calendar.YEAR));
parsed.set(Calendar.MONTH, current.get(Calendar.MONTH)); parsed.set(Calendar.MONTH, current.get(Calendar.MONTH));
parsed.set(Calendar.DAY_OF_MONTH, current.get(Calendar.DAY_OF_MONTH)); parsed.set(Calendar.DAY_OF_MONTH, current.get(Calendar.DAY_OF_MONTH));
@ -520,23 +522,23 @@ public final class BahnProvider implements NetworkProvider
final Date plannedTime = parsed.getTime(); final Date plannedTime = parsed.getTime();
Date predictedTime = null; Date predictedTime = null;
if (mDepFine.group(4) != null) if (mDepFine.group(5) != null)
{ {
predictedTime = plannedTime; predictedTime = plannedTime;
} }
else if (mDepFine.group(5) != null) else if (mDepFine.group(6) != null)
{ {
final int delay = Integer.parseInt(mDepFine.group(5)); final int delay = Integer.parseInt(mDepFine.group(6));
parsed.add(Calendar.MINUTE, delay); parsed.add(Calendar.MINUTE, delay);
predictedTime = parsed.getTime(); predictedTime = parsed.getTime();
} }
final String message = ParserUtils.resolveEntities(mDepFine.group(6)); final String message = ParserUtils.resolveEntities(mDepFine.group(7));
final String position = ParserUtils.resolveEntities(mDepFine.group(7)); final String position = ParserUtils.resolveEntities(mDepFine.group(8));
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, message); lineLink, position, 0, destination, message);
if (!departures.contains(dep)) if (!departures.contains(dep))
departures.add(dep); departures.add(dep);
} }

View file

@ -28,18 +28,20 @@ public final class Departure
final public Date predictedTime; final public Date predictedTime;
final public String line; final public String line;
final public int[] lineColors; final public int[] lineColors;
final public String lineLink;
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; 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 lineLink,
final int destinationId, final String destination, final String message) final String position, final int destinationId, final String destination, final String message)
{ {
this.plannedTime = plannedTime; this.plannedTime = plannedTime;
this.predictedTime = predictedTime; this.predictedTime = predictedTime;
this.line = line; this.line = line;
this.lineColors = lineColors; this.lineColors = lineColors;
this.lineLink = lineLink;
this.position = position; this.position = position;
this.destinationId = destinationId; this.destinationId = destinationId;
this.destination = destination; this.destination = destination;
@ -53,6 +55,7 @@ public final class Departure
this.predictedTime = null; this.predictedTime = null;
this.line = line; this.line = line;
this.lineColors = lineColors; this.lineColors = lineColors;
this.lineLink = null;
this.position = position; this.position = position;
this.destinationId = destinationId; this.destinationId = destinationId;
this.destination = destination; this.destination = destination;

View file

@ -572,7 +572,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, null,
position, destinationId, destination, null); position, destinationId, destination, null);
if (!departures.contains(dep)) if (!departures.contains(dep))

View file

@ -568,7 +568,7 @@ public class RmvProvider implements NetworkProvider
final String position = ParserUtils.resolveEntities(ParserUtils.selectNotNull(mDepFine.group(5), mDepFine.group(6))); 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, final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line.charAt(0)) : null, null,
position, 0, destination, null); position, 0, destination, null);
if (!departures.contains(dep)) if (!departures.contains(dep))

View file

@ -589,7 +589,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, null, position,
destinationId, destination, null); destinationId, destination, null);
if (!departures.contains(dep)) if (!departures.contains(dep))
departures.add(dep); departures.add(dep);

View file

@ -51,7 +51,8 @@ public class BahnProviderTest
+ "<br />\n" // + "<br />\n" //
+ "<span class=\"bold\">10:42</span>Gl. 1"); + "<span class=\"bold\">10:42</span>Gl. 1");
assertNotNull(m.group(7)); // position assertNotNull(m.group(1)); // lineLink
assertNotNull(m.group(8)); // position
} }
@Test @Test
@ -66,8 +67,9 @@ public class BahnProviderTest
+ "<br />\n" // + "<br />\n" //
+ "<span class=\"bold\">21:58</span>&nbsp;<span class=\"green bold\">p&#252;nktl.</span>,&nbsp;Gl. 13"); + "<span class=\"bold\">21:58</span>&nbsp;<span class=\"green bold\">p&#252;nktl.</span>,&nbsp;Gl. 13");
assertNotNull(m.group(4)); // onTime assertNotNull(m.group(1)); // lineLink
assertNotNull(m.group(7)); // position assertNotNull(m.group(5)); // onTime
assertNotNull(m.group(8)); // position
} }
@Test @Test
@ -82,9 +84,10 @@ public class BahnProviderTest
+ "<br />\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"); + "<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");
assertNotNull(m.group(5)); // delay assertNotNull(m.group(1)); // lineLink
assertNotNull(m.group(6)); // message assertNotNull(m.group(6)); // delay
assertNotNull(m.group(7)); // position assertNotNull(m.group(7)); // message
assertNotNull(m.group(8)); // position
} }
@Test @Test
@ -99,8 +102,9 @@ public class BahnProviderTest
+ "<br />\n" // + "<br />\n" //
+ "<span class=\"bold\">17:10</span>&nbsp;<span class=\"green bold\">p&#252;nktl.</span>,&nbsp;<span class=\"red\">heute Gl. 7 </span>"); + "<span class=\"bold\">17:10</span>&nbsp;<span class=\"green bold\">p&#252;nktl.</span>,&nbsp;<span class=\"red\">heute Gl. 7 </span>");
assertNotNull(m.group(4)); // onTime assertNotNull(m.group(1)); // lineLink
assertNotNull(m.group(7)); // position assertNotNull(m.group(5)); // onTime
assertNotNull(m.group(8)); // position
} }
@Test @Test
@ -115,9 +119,10 @@ public class BahnProviderTest
+ "<br />\n" // + "<br />\n" //
+ "<span class=\"bold\">19:57</span>&nbsp;<span class=\"green bold\">p&#252;nktl.</span>, <span class=\"red\">&#196;nderung im Zuglauf!</span>,&nbsp;<span class=\"red\">heute Gl. 7 </span>"); + "<span class=\"bold\">19:57</span>&nbsp;<span class=\"green bold\">p&#252;nktl.</span>, <span class=\"red\">&#196;nderung im Zuglauf!</span>,&nbsp;<span class=\"red\">heute Gl. 7 </span>");
assertNotNull(m.group(4)); // onTime assertNotNull(m.group(1)); // lineLink
assertNotNull(m.group(6)); // message assertNotNull(m.group(5)); // onTime
assertNotNull(m.group(7)); // position assertNotNull(m.group(7)); // message
assertNotNull(m.group(8)); // position
} }
@Test @Test
@ -132,7 +137,8 @@ public class BahnProviderTest
+ "<br />\n" // + "<br />\n" //
+ "<span class=\"bold\">04:52</span>&nbsp;k.A.,&nbsp;Gl. 3"); + "<span class=\"bold\">04:52</span>&nbsp;k.A.,&nbsp;Gl. 3");
assertNotNull(m.group(7)); // position assertNotNull(m.group(1)); // lineLink
assertNotNull(m.group(8)); // position
} }
@Test @Test
@ -147,8 +153,9 @@ public class BahnProviderTest
+ "<br />\n" // + "<br />\n" //
+ "<span class=\"bold\">14:49</span>&nbsp;<span class=\"green bold\">p&#252;nktl.</span>,&nbsp;Gl. 1,<br/><span class=\"red\">Ersatzzug f&#252;r<a class=\"red underline\" href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/611619/369020/735680/163967/80?ld=96159&amp;rt=1&amp;use_realtime_filter=1&amp;date=10.09.10&amp;time=14:49&amp;station_evaId=8000220&amp;station_type=dep&amp;\">RB 5416</a></span>"); + "<span class=\"bold\">14:49</span>&nbsp;<span class=\"green bold\">p&#252;nktl.</span>,&nbsp;Gl. 1,<br/><span class=\"red\">Ersatzzug f&#252;r<a class=\"red underline\" href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/611619/369020/735680/163967/80?ld=96159&amp;rt=1&amp;use_realtime_filter=1&amp;date=10.09.10&amp;time=14:49&amp;station_evaId=8000220&amp;station_type=dep&amp;\">RB 5416</a></span>");
assertNotNull(m.group(4)); // onTime assertNotNull(m.group(1)); // lineLink
assertNotNull(m.group(7)); // position assertNotNull(m.group(5)); // onTime
assertNotNull(m.group(8)); // position
} }
@Test @Test
@ -163,7 +170,8 @@ public class BahnProviderTest
+ "<br />\n" // + "<br />\n" //
+ "<span class=\"bold\">10:27</span>, <span class=\"red\">Zug f&#228;llt aus</span>,<br/><a class=\"red underline\" href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/144627/793698/280606/92094/80?ld=96159&amp;rt=1&amp;use_realtime_filter=1&amp;date=08.09.10&amp;time=10:27&amp;station_evaId=8001647&amp;station_type=dep&amp;\"><span class=\"red\">Ersatzzug&nbsp;S </a></span>"); + "<span class=\"bold\">10:27</span>, <span class=\"red\">Zug f&#228;llt aus</span>,<br/><a class=\"red underline\" href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/144627/793698/280606/92094/80?ld=96159&amp;rt=1&amp;use_realtime_filter=1&amp;date=08.09.10&amp;time=10:27&amp;station_evaId=8001647&amp;station_type=dep&amp;\"><span class=\"red\">Ersatzzug&nbsp;S </a></span>");
assertNotNull(m.group(6)); // message assertNotNull(m.group(1)); // lineLink
assertNotNull(m.group(7)); // message
} }
@Test @Test
@ -178,8 +186,9 @@ public class BahnProviderTest
+ "<br />\n" // + "<br />\n" //
+ "<span class=\"bold\">00:18</span>, <span class=\"red\">Zug f&#228;llt aus</span>,&nbsp;Gl. 4,<br/><a class=\"red underline\" href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/843399/1026627/462944/49661/80?ld=96159&amp;rt=1&amp;use_realtime_filter=1&amp;date=09.09.10&amp;time=00:18&amp;station_evaId=8001844&amp;station_type=dep&amp;\"><span class=\"red\">Ersatzzug&nbsp;RB 30535</a></span>"); + "<span class=\"bold\">00:18</span>, <span class=\"red\">Zug f&#228;llt aus</span>,&nbsp;Gl. 4,<br/><a class=\"red underline\" href=\"http://mobile.bahn.de/bin/mobil/traininfo.exe/dox/843399/1026627/462944/49661/80?ld=96159&amp;rt=1&amp;use_realtime_filter=1&amp;date=09.09.10&amp;time=00:18&amp;station_evaId=8001844&amp;station_type=dep&amp;\"><span class=\"red\">Ersatzzug&nbsp;RB 30535</a></span>");
assertNotNull(m.group(6)); // message assertNotNull(m.group(1)); // lineLink
assertNotNull(m.group(7)); // position assertNotNull(m.group(7)); // message
assertNotNull(m.group(8)); // position
} }
@Test @Test
@ -194,8 +203,9 @@ public class BahnProviderTest
+ "<br />\n" // + "<br />\n" //
+ "<span class=\"bold\">10:59</span>&nbsp;<span class=\"green bold\">p&#252;nktl.</span>, <span class=\"red\">&#196;nderung im Zuglauf!</span>, <span class=\"red\">F&#228;hrt heute nur bis&nbsp;K&#246;ln-Dellbr&#252;ck</span>,&nbsp;Gl. 1"); + "<span class=\"bold\">10:59</span>&nbsp;<span class=\"green bold\">p&#252;nktl.</span>, <span class=\"red\">&#196;nderung im Zuglauf!</span>, <span class=\"red\">F&#228;hrt heute nur bis&nbsp;K&#246;ln-Dellbr&#252;ck</span>,&nbsp;Gl. 1");
assertNotNull(m.group(4)); // onTime assertNotNull(m.group(1)); // lineLink
assertNotNull(m.group(6)); // message assertNotNull(m.group(5)); // onTime
assertNotNull(m.group(7)); // message
assertNotNull(m.group(7)); // position assertNotNull(m.group(7)); // position
} }
@ -211,8 +221,9 @@ public class BahnProviderTest
+ "<br />\n" // + "<br />\n" //
+ "<span class=\"bold\">22:58</span>&nbsp;<span class=\"green bold\">p&#252;nktl.</span>,&nbsp;Gl. 2,<br/>&nbsp;<span class=\"red\">Sonderzug</span>"); + "<span class=\"bold\">22:58</span>&nbsp;<span class=\"green bold\">p&#252;nktl.</span>,&nbsp;Gl. 2,<br/>&nbsp;<span class=\"red\">Sonderzug</span>");
assertNotNull(m.group(4)); // onTime assertNotNull(m.group(1)); // lineLink
assertNotNull(m.group(7)); // position assertNotNull(m.group(5)); // onTime
assertNotNull(m.group(8)); // position
} }
private void assertFineConnectionDetails(String s) private void assertFineConnectionDetails(String s)
@ -230,9 +241,9 @@ public class BahnProviderTest
// ParserUtils.printGroups(m); // ParserUtils.printGroups(m);
assertNotNull(m.group(1)); // line assertNotNull(m.group(2)); // line
assertNotNull(m.group(2)); // destination assertNotNull(m.group(3)); // destination
assertNotNull(m.group(3)); // time assertNotNull(m.group(4)); // time
return m; return m;
} }