Exemple #1
0
  /**
   * Returns map of Trip objects for the specified configRev. The map is keyed on the trip IDs.
   *
   * @param session
   * @param configRev
   * @return
   * @throws HibernateException
   */
  @SuppressWarnings("unchecked")
  public static Map<String, Trip> getTrips(Session session, int configRev)
      throws HibernateException {
    // Setup the query
    String hql = "FROM Trip " + "    WHERE configRev = :configRev";
    Query query = session.createQuery(hql);
    query.setInteger("configRev", configRev);

    // Actually perform the query
    List<Trip> tripsList = query.list();

    // Now put the Trips into a map and return it
    Map<String, Trip> tripsMap = new HashMap<String, Trip>();
    for (Trip trip : tripsList) {
      tripsMap.put(trip.getId(), trip);
    }
    return tripsMap;
  }
Exemple #2
0
  /**
   * Returns specified Trip object for the specified configRev and tripShortName.
   *
   * @param session
   * @param configRev
   * @param tripShortName
   * @return The Trip or null if no such trip
   * @throws HibernateException
   */
  public static Trip getTripByShortName(Session session, int configRev, String tripShortName)
      throws HibernateException {
    // Setup the query
    String hql =
        "FROM Trip "
            + "    WHERE configRev = :configRev"
            + "      AND tripShortName = :tripShortName";
    Query query = session.createQuery(hql);
    query.setInteger("configRev", configRev);
    query.setString("tripShortName", tripShortName);

    // Actually perform the query
    @SuppressWarnings("unchecked")
    List<Trip> trips = query.list();

    // If no results return null
    if (trips.size() == 0) return null;

    // If only a single trip matched then assume that the service ID is
    // correct so return it. This should usually be fine, and it means
    // then don't need to determine current service IDs, which is
    // somewhat expensive.
    if (trips.size() == 1) return trips.get(0);

    // There are results so use the Trip that corresponds to the current
    // service ID.
    Date now = Core.getInstance().getSystemDate();
    Collection<String> currentServiceIds = Core.getInstance().getServiceUtils().getServiceIds(now);
    for (Trip trip : trips) {
      for (String serviceId : currentServiceIds) {
        if (trip.getServiceId().equals(serviceId)) {
          // Found a service ID match so return this trip
          return trip;
        }
      }
    }

    // Didn't find a trip that matched a current service ID so return null
    return null;
  }
Exemple #3
0
  /**
   * Constructs a new Vehicle object from data in a VehicleState object.
   *
   * @param vs
   */
  public IpcVehicle(VehicleState vs) {
    this.blockAssignmentMethod = vs.getAssignmentMethod();
    this.avl = new IpcAvl(vs.getAvlReport());
    this.heading = vs.getHeading();
    this.routeId = vs.getRouteId();
    this.routeShortName = vs.getRouteShortName();
    Trip trip = vs.getTrip();
    if (trip != null) {
      this.blockId = vs.getBlock().getId();
      this.tripId = trip.getId();
      this.tripPatternId = trip.getTripPattern().getId();
      this.directionId = trip.getDirectionId();
      this.headsign = trip.getHeadsign();

      // Get the match. If match is just after a stop then adjust
      // it to just before the stop so that can determine proper
      // stop ID and such.
      SpatialMatch match = vs.getMatch().getMatchBeforeStopIfAtStop();

      // Determine if vehicle is at layover, and if so, what time it
      // should depart. The departure time isn't necessarily the
      // scheduled trip start time since if vehicle is late or if
      // driver supposed to get a break then vehicle will leave after
      // the scheduled time. Therefore use the predicted departure time
      // for layover.
      this.isLayover = match.isLayover();
      if (this.isLayover) {
        IpcPrediction predsForVehicle =
            PredictionDataCache.getInstance()
                .getPredictionForVehicle(
                    vs.getAvlReport().getVehicleId(),
                    vs.getRouteShortName(),
                    match.getStopPath().getStopId());
        this.layoverDepartureTime =
            predsForVehicle != null ? predsForVehicle.getPredictionTime() : 0;
      } else {
        // Not a layover so departure time not provided
        this.layoverDepartureTime = 0;
      }

      // If vehicle is at a stop then "next" stop will actually be
      // the current stop.
      this.nextStopId = match.getStopPath().getStopId();
      this.nextStopName = match.getStopPath().getStopName();

      this.vehicleType = match.getRoute().getType();
    } else {
      // Vehicle not assigned to trip so null out parameters
      this.blockId = null;
      this.tripId = null;
      this.tripPatternId = null;
      this.directionId = null;
      this.headsign = null;
      this.isLayover = false;
      this.layoverDepartureTime = 0;
      this.nextStopId = null;
      this.nextStopName = null;
      this.vehicleType = null;
    }
    this.predictable = vs.isPredictable();
    this.schedBasedPred = vs.isForSchedBasedPreds();
    this.realTimeSchedAdh = vs.getRealTimeSchedAdh();
    this.isDelayed = vs.isDelayed();
  }