live departures for Berlin

git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@140 0924bc21-9374-b0fa-ee44-9ff1593b38f0
This commit is contained in:
andreas.schildbach 2010-09-06 01:09:52 +00:00
parent 5301ed49e1
commit b9571a9399

View file

@ -530,9 +530,10 @@ public final class VbbProvider implements NetworkProvider
+ "<tr class=\"ivu_table_bg\\d\">\\s*((?:<td class=\"ivu_table_c_dep\">|<td>).+?)\\s*</tr>" // + "<tr class=\"ivu_table_bg\\d\">\\s*((?:<td class=\"ivu_table_c_dep\">|<td>).+?)\\s*</tr>" //
, Pattern.DOTALL); , Pattern.DOTALL);
private static final Pattern P_DEPARTURES_LIVE_FINE = Pattern.compile("" // private static final Pattern P_DEPARTURES_LIVE_FINE = Pattern.compile("" //
+ "<td class=\"ivu_table_c_dep\">\\s*(.*?)[\\s\\*]*</td>\\s*" // + "<td class=\"ivu_table_c_dep\">\\s*(\\d{1,2}:\\d{2})\\s*" // time
+ "<td class=\"ivu_table_c_line\">\\s*(.*?)\\s*</td>\\s*" // + "(\\*)?\\s*</td>\\s*" // planned
+ "<td>.*?<a.*?[^-]>\\s*(.*?)\\s*</a>.*?</td>" // + "<td class=\"ivu_table_c_line\">\\s*(.*?)\\s*</td>\\s*" // line
+ "<td>.*?<a.*?[^-]>\\s*(.*?)\\s*</a>.*?</td>" // destination
, Pattern.DOTALL); , Pattern.DOTALL);
private static final Pattern P_DEPARTURES_PLAN_FINE = Pattern.compile("" // private static final Pattern P_DEPARTURES_PLAN_FINE = Pattern.compile("" //
+ "<td><strong>(\\d{1,2}:\\d{2})</strong></td>.*?" // time + "<td><strong>(\\d{1,2}:\\d{2})</strong></td>.*?" // time
@ -572,7 +573,6 @@ public final class VbbProvider implements NetworkProvider
final Matcher mDepFine = (live ? P_DEPARTURES_LIVE_FINE : P_DEPARTURES_PLAN_FINE).matcher(mDepCoarse.group(1)); final Matcher mDepFine = (live ? P_DEPARTURES_LIVE_FINE : P_DEPARTURES_PLAN_FINE).matcher(mDepCoarse.group(1));
if (mDepFine.matches()) if (mDepFine.matches())
{ {
// time
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();
@ -583,20 +583,25 @@ public final class VbbProvider implements NetworkProvider
if (ParserUtils.timeDiff(parsed.getTime(), currentTime) < -PARSER_DAY_ROLLOVER_THRESHOLD_MS) if (ParserUtils.timeDiff(parsed.getTime(), currentTime) < -PARSER_DAY_ROLLOVER_THRESHOLD_MS)
parsed.add(Calendar.DAY_OF_MONTH, 1); parsed.add(Calendar.DAY_OF_MONTH, 1);
// line boolean isPlanned = live && mDepFine.group(2) != null;
final String line = normalizeLine(ParserUtils.resolveEntities(mDepFine.group(2)));
Date plannedTime = null;
Date predictedTime = null;
if (live && !isPlanned)
predictedTime = parsed.getTime();
else
plannedTime = parsed.getTime();
final String line = normalizeLine(ParserUtils.resolveEntities(mDepFine.group(live ? 3 : 2)));
// position
final String position = !live ? ParserUtils.resolveEntities(mDepFine.group(3)) : null; final String position = !live ? ParserUtils.resolveEntities(mDepFine.group(3)) : null;
// destinationId
final int destinationId = !live ? Integer.parseInt(mDepFine.group(4)) : 0; final int destinationId = !live ? Integer.parseInt(mDepFine.group(4)) : 0;
// destination final String destination = ParserUtils.resolveEntities(mDepFine.group(live ? 4 : 5));
final String destination = ParserUtils.resolveEntities(mDepFine.group(live ? 3 : 5));
final Departure dep = new Departure(parsed.getTime(), line, line != null ? LINES.get(line) : null, position, destinationId, final Departure dep = new Departure(plannedTime, predictedTime, line, line != null ? LINES.get(line) : null, position,
destination); destinationId, destination);
if (!departures.contains(dep)) if (!departures.contains(dep))
departures.add(dep); departures.add(dep);
} }