arrival times and predicted times for intermediate stops

This commit is contained in:
Andreas Schildbach 2012-08-01 12:29:31 +02:00
parent afc4b4b096
commit b37c63c333
4 changed files with 76 additions and 15 deletions

View file

@ -2042,10 +2042,11 @@ public abstract class AbstractEfaProvider extends AbstractNetworkProvider
XmlPullUtil.require(pp, "itdDateTime");
final boolean success1 = processItdDateTime(pp, time);
final boolean success2 = XmlPullUtil.test(pp, "itdDateTime") ? processItdDateTime(pp, time) : false;
final Date stopTime = time.getTime(); // TODO arrival/departure, planned/predicted?
XmlPullUtil.exit(pp, "itdPoint");
if (success1 || success2)
intermediateStops.add(new Stop(stopLocation, stopPosition, time.getTime()));
intermediateStops.add(new Stop(stopLocation, stopPosition, null, null, stopTime, null));
}
XmlPullUtil.exit(pp, "itdStopSeq");

View file

@ -1159,19 +1159,33 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
final Location location = parseLocation(pp);
if (location.id != sectionDeparture.id)
{
Date stopArrivalTime = null;
Date stopDepartureTime = null;
String stopPosition = null;
if (XmlPullUtil.test(pp, "Arr"))
XmlPullUtil.next(pp);
{
XmlPullUtil.enter(pp, "Arr");
XmlPullUtil.require(pp, "Time");
time.setTimeInMillis(currentDate.getTimeInMillis());
parseTime(time, XmlPullUtil.text(pp));
stopArrivalTime = time.getTime();
stopPosition = parsePlatform(pp);
XmlPullUtil.exit(pp, "Arr");
}
if (XmlPullUtil.test(pp, "Dep"))
{
XmlPullUtil.enter(pp, "Dep");
XmlPullUtil.require(pp, "Time");
time.setTimeInMillis(currentDate.getTimeInMillis());
parseTime(time, XmlPullUtil.text(pp));
final String position = parsePlatform(pp);
stopDepartureTime = time.getTime();
stopPosition = parsePlatform(pp);
XmlPullUtil.exit(pp, "Dep");
intermediateStops.add(new Stop(location, position, time.getTime()));
}
intermediateStops.add(new Stop(location, stopPosition, stopArrivalTime, null, stopDepartureTime, null));
}
XmlPullUtil.exit(pp, "BasicStop");
}
@ -1763,14 +1777,18 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
for (int iStop = 0; iStop < numStops; iStop++)
{
final long plannedStopDepartureTime = time(is, resDate, connectionDayOffset);
/* final long plannedStopArrivalTime = */time(is, resDate, connectionDayOffset);
final Date plannedStopDepartureDate = plannedStopDepartureTime != 0 ? new Date(plannedStopDepartureTime) : null;
final long plannedStopArrivalTime = time(is, resDate, connectionDayOffset);
final Date plannedStopArrivalDate = plannedStopArrivalTime != 0 ? new Date(plannedStopArrivalTime) : null;
final String plannedStopDeparturePosition = normalizePosition(strings.read(is));
/* final String plannedStopArrivalPosition = */normalizePosition(strings.read(is));
is.readInt();
/* final long predictedStopDepartureTime = */time(is, resDate, connectionDayOffset);
/* final long predictedStopArrivalTime = */time(is, resDate, connectionDayOffset);
final long predictedStopDepartureTime = time(is, resDate, connectionDayOffset);
final Date predictedStopDepartureDate = predictedStopDepartureTime != 0 ? new Date(predictedStopDepartureTime) : null;
final long predictedStopArrivalTime = time(is, resDate, connectionDayOffset);
final Date predictedStopArrivalDate = predictedStopArrivalTime != 0 ? new Date(predictedStopArrivalTime) : null;
/* final String predictedStopDeparturePosition = */normalizePosition(strings.read(is));
/* final String predictedStopArrivalPosition = */normalizePosition(strings.read(is));
@ -1778,8 +1796,8 @@ public abstract class AbstractHafasProvider extends AbstractNetworkProvider
final Location stopLocation = stations.read(is);
final Stop stop = new Stop(stopLocation, plannedStopDeparturePosition, plannedStopDepartureTime != 0 ? new Date(
plannedStopDepartureTime) : null);
final Stop stop = new Stop(stopLocation, plannedStopDeparturePosition, plannedStopArrivalDate, predictedStopArrivalDate,
plannedStopDepartureDate, predictedStopDepartureDate);
intermediateStops.add(stop);
}

View file

@ -31,7 +31,6 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.schildbach.pte.NetworkProvider.Option;
import de.schildbach.pte.dto.Connection;
import de.schildbach.pte.dto.Departure;
import de.schildbach.pte.dto.Line;
@ -794,7 +793,7 @@ public final class BvgProvider extends AbstractHafasProvider
if (lastTime != null && time.getTime().before(lastTime))
time.add(Calendar.DAY_OF_YEAR, 1);
lastTime = time.getTime();
intermediateStops.add(new Stop(location(tStop), null, time.getTime()));
intermediateStops.add(new Stop(location(tStop), null, null, null, time.getTime(), null));
}
final Location arrival = location(tArr);

View file

@ -27,13 +27,50 @@ public final class Stop implements Serializable
{
public final Location location;
public final String position;
public final Date time;
public final Date plannedArrivalTime;
public final Date predictedArrivalTime;
public final Date time; // TODO rename to plannedDepartureTime
public final Date predictedDepartureTime;
public Stop(final Location location, final String position, final Date time)
public Stop(final Location location, final String position, final Date plannedArrivalTime, final Date predictedArrivalTime,
final Date plannedDepartureTime, final Date predictedDepartureTime)
{
this.location = location;
this.position = position;
this.time = time;
this.plannedArrivalTime = plannedArrivalTime;
this.predictedArrivalTime = predictedArrivalTime;
this.time = plannedDepartureTime;
this.predictedDepartureTime = predictedDepartureTime;
}
public Date getArrivalTime()
{
if (predictedArrivalTime != null)
return predictedArrivalTime;
else if (plannedArrivalTime != null)
return plannedArrivalTime;
else
return null;
}
public boolean isArrivalTimePredicted()
{
return predictedArrivalTime != null;
}
public Date getDepartureTime()
{
if (predictedDepartureTime != null)
return predictedDepartureTime;
else if (time != null)
return time;
else
return null;
}
public boolean isDepartureTimePredicted()
{
return predictedDepartureTime != null;
}
@Override
@ -44,7 +81,13 @@ public final class Stop implements Serializable
builder.append(",");
builder.append(position != null ? position : "null");
builder.append(",");
builder.append(plannedArrivalTime != null ? plannedArrivalTime : "null");
builder.append(",");
builder.append(predictedArrivalTime != null ? predictedArrivalTime : "null");
builder.append(",");
builder.append(time != null ? time : "null");
builder.append(",");
builder.append(predictedDepartureTime != null ? predictedDepartureTime : "null");
builder.append(")");
return builder.toString();
}