Exemple #1
0
  /**
   * Returns the Block that the Trip is associated with. Only valid when running the core
   * application where can use Core.getInstance(). Otherwise returns null.
   *
   * @return
   */
  public Block getBlock() {
    // If not part of the core project where DbConfig is available
    // then just return null.
    Core core = Core.getInstance();
    if (core == null) return null;
    DbConfig dbConfig = core.getDbConfig();
    if (dbConfig == null) return null;

    // Part of core project so return the Block
    return dbConfig.getBlock(serviceId, blockId);
  }
Exemple #2
0
 /**
  * Returns the Route object for this trip. This object is determined and cached when first
  * accessed. Uses value read in from database using Core, which means that it won't be available
  * when processing GTFS data since that doesn't have core object.
  *
  * @return The route or null if no Core object available
  */
 public Route getRoute() {
   if (route == null) {
     if (Core.isCoreApplication()) {
       DbConfig dbConfig = Core.getInstance().getDbConfig();
       if (dbConfig == null) return null;
       route = dbConfig.getRouteById(routeId);
     } else {
       return null;
     }
   }
   return route;
 }
Exemple #3
0
  /**
   * A simpler way to create a VehicleEvent that gets a lot of its info from the avlReport and match
   * params. This also logs it and queues it to be stored in database. The match param can be null.
   *
   * @param avlReport
   * @param match
   * @param eventType
   * @param description
   * @param predictable
   * @param becameUnpredictable
   * @param supervisor
   * @return The VehicleEvent constructed
   */
  public static VehicleEvent create(
      AvlReport avlReport,
      TemporalMatch match,
      String eventType,
      String description,
      boolean predictable,
      boolean becameUnpredictable,
      String supervisor) {
    // Get a log of the info from the possibly null match param
    String routeId = match == null ? null : match.getTrip().getRouteId();
    String routeShortName = match == null ? null : match.getTrip().getRouteShortName();
    String blockId = match == null ? null : match.getBlock().getId();
    String serviceId = match == null ? null : match.getBlock().getServiceId();
    String tripId = match == null ? null : match.getTrip().getId();
    String stopId = match == null ? null : match.getStopPath().getStopId();

    // Create and return the VehicleEvent
    return create(
        Core.getInstance().getSystemDate(),
        avlReport.getDate(),
        avlReport.getVehicleId(),
        eventType,
        description,
        predictable,
        becameUnpredictable,
        supervisor,
        avlReport.getLocation(),
        routeId,
        routeShortName,
        blockId,
        serviceId,
        tripId,
        stopId);
  }
Exemple #4
0
 /**
  * Returns the Route object for this trip. This object is determined and cached when first
  * accessed. Uses value read in from database using Core, which means that it won't be available
  * when processing GTFS data since that doesn't have core object.
  *
  * @return The route or null if no Core object available
  */
 public Route getRoute() {
   if (route == null) {
     DbConfig dbConfig = Core.getInstance().getDbConfig();
     if (dbConfig == null) return null;
     route = dbConfig.getRouteById(routeId);
   }
   return route;
 }
Exemple #5
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 #6
0
 /**
  * Returns the ScheduleTime object for the stopPathIndex. Will return null if there are no
  * schedule times associated with that stop for this trip. Useful for determining schedule
  * adherence.
  *
  * @param stopPathIndex
  * @return
  */
 public ScheduleTime getScheduleTime(int stopPathIndex) {
   if (scheduledTimesList instanceof PersistentList) {
     // TODO this is an anti-pattern
     // instead find a way to manage sessions more consistently
     PersistentList persistentListTimes = (PersistentList) scheduledTimesList;
     SessionImplementor session = persistentListTimes.getSession();
     if (session == null) {
       Session globalLazyLoadSession = Core.getInstance().getDbConfig().getGlobalSession();
       globalLazyLoadSession.update(this);
     }
   }
   return scheduledTimesList.get(stopPathIndex);
 }
Exemple #7
0
  /**
   * Query how many travel times for trips entries exist for a given travelTimesRev. Used for
   * metrics.
   *
   * @param session
   * @param travelTimesRev
   * @return
   */
  public static Long countTravelTimesForTrips(Session session, int travelTimesRev) {
    String sql = "Select count(*) from TravelTimesForTrips where travelTimesRev=:rev";

    Query query = session.createSQLQuery(sql);
    query.setInteger("rev", travelTimesRev);
    Long count = null;
    try {
      BigInteger bcount = (BigInteger) query.uniqueResult();
      if (bcount != null) count = bcount.longValue();
    } catch (HibernateException e) {
      Core.getLogger().error("exception querying for metrics", e);
    }
    return count;
  }
Exemple #8
0
  /**
   * Constructs a vehicle event and logs it and queues it to be stored in database.
   *
   * @param time
   * @param avlTime
   * @param vehicleId
   * @param eventType
   * @param description
   * @param predictable
   * @param becameUnpredictable
   * @param supervisor
   * @param location
   * @param routeId
   * @param routeShortName
   * @param blockId
   * @param serviceId
   * @param tripId
   * @param stopId
   * @return The VehicleEvent constructed
   */
  public static VehicleEvent create(
      Date time,
      Date avlTime,
      String vehicleId,
      String eventType,
      String description,
      boolean predictable,
      boolean becameUnpredictable,
      String supervisor,
      Location location,
      String routeId,
      String routeShortName,
      String blockId,
      String serviceId,
      String tripId,
      String stopId) {
    VehicleEvent vehicleEvent =
        new VehicleEvent(
            time,
            avlTime,
            vehicleId,
            eventType,
            description,
            predictable,
            becameUnpredictable,
            supervisor,
            location,
            routeId,
            routeShortName,
            blockId,
            serviceId,
            tripId,
            stopId);

    // Log VehicleEvent in log file
    logger.info(vehicleEvent.toString());

    // Queue to write object to database
    Core.getInstance().getDbLogger().add(vehicleEvent);

    // Return new VehicleEvent
    return vehicleEvent;
  }