Exemple #1
0
 /**
  * Similar to toString() but doesn't include scheduledTimesMap which can be quite verbose since it
  * often contains times for many stops.
  *
  * @return
  */
 public String toShortString() {
   return "Trip ["
       + "tripId="
       + tripId
       + ", tripShortName="
       + tripShortName
       + ", tripPatternId="
       + (tripPattern != null ? tripPattern.getId() : "null")
       + ", tripIndexInBlock="
       + getIndexInBlock()
       + ", startTime="
       + Time.timeOfDayStr(startTime)
       + ", endTime="
       + Time.timeOfDayStr(endTime)
       + (headsign != null ? ", headsign=\"" + headsign + "\"" : "")
       + ", directionId="
       + directionId
       + ", routeId="
       + routeId
       + ", routeShortName="
       + routeShortName
       + (noSchedule ? ", noSchedule=" + noSchedule : "")
       + (exactTimesHeadway ? ", exactTimesHeadway=" + exactTimesHeadway : "")
       + ", serviceId="
       + serviceId
       + ", blockId="
       + blockId
       + ", shapeId="
       + shapeId
       + "]";
 }
Exemple #2
0
 /**
  * Returns the elapsed time in msec as a string. If the time is below 1 minute then it is
  * displayed in seconds. If greater than 2 minutes then it is displayed in minutes. For both, 1
  * digit after the decimal point is displayed. The units, either " sec" or " msec" are appended.
  *
  * @param msec
  * @return
  */
 public static String elapsedTimeStr(long msec) {
   if (Math.abs(msec) < 2 * Time.MS_PER_MIN) {
     return Time.secondsStr(msec) + " sec";
   } else {
     return Time.minutesStr(msec) + " min";
   }
 }
Exemple #3
0
 public static void main(String args[]) {
   try {
     // TODO make this a unit test
     Time time = new Time("America/Los_Angeles");
     Date referenceDate = parse("11-23-2013 23:55:00");
     int secondsIntoDay = 24 * SEC_PER_HOUR - 60;
     long epochTime = time.getEpochTime(secondsIntoDay, referenceDate);
     System.out.println(new Date(epochTime));
   } catch (ParseException e) {
   }
 }
Exemple #4
0
  /* (non-Javadoc)
   * @see org.transitime.rmi.Hello#concat(java.lang.String, java.lang.String)
   */
  @Override
  public String concat(String s1, String s2) throws RemoteException {
    // Sleep for a bit to simulate server getting bogged down
    Time.sleep(2000);

    return getAgencyId() + ": " + s1 + s2;
  }
Exemple #5
0
 @Override
 public String toString() {
   return "IpcAvl [vehicleId="
       + vehicleId
       + ", time="
       + Time.dateTimeStr(time)
       + ", latitude="
       + latitude
       + ", longitude="
       + longitude
       + ", speed="
       + Geo.speedFormat(speed)
       + ", heading="
       + Geo.headingFormat(heading)
       + ", source="
       + source
       + ", assignmentId="
       + assignmentId
       + ", assignmentType="
       + assignmentType
       + ", driverId="
       + driverId
       + ", licensePlate="
       + licensePlate
       + ", passengerCount="
       + passengerCount
       + "]";
 }
Exemple #6
0
 /* (non-Javadoc)
  * @see java.lang.Object#toString()
  */
 @Override
 public String toString() {
   // Note: the '\n' at beginning is so that when output list of trips
   // each will be on new line
   return "\n    Trip ["
       + "configRev="
       + configRev
       + ", tripId="
       + tripId
       + ", tripShortName="
       + tripShortName
       + ", tripPatternId="
       + (tripPattern != null ? tripPattern.getId() : "null")
       + ", tripIndexInBlock="
       + getIndexInBlock()
       + ", startTime="
       + Time.timeOfDayStr(startTime)
       + ", endTime="
       + Time.timeOfDayStr(endTime)
       + (headsign != null ? ", headsign=\"" + headsign + "\"" : "")
       + ", directionId="
       + directionId
       + ", routeId="
       + routeId
       + ", routeShortName="
       + routeShortName
       + (noSchedule ? ", noSchedule=" + noSchedule : "")
       + (exactTimesHeadway ? ", exactTimesHeadway=" + exactTimesHeadway : "")
       + ", serviceId="
       + serviceId
       + ", blockId="
       + blockId
       + ", shapeId="
       + shapeId
       + ", scheduledTimesList="
       + scheduledTimesList
       + "]";
 }
Exemple #7
0
 @Override
 public String toString() {
   return "VehicleEvent ["
       + "time="
       + Time.dateTimeStrMsec(time)
       + ", rShortName="
       + routeShortName
       + ", stopId="
       + stopId
       + ", vehicleId="
       + vehicleId
       + ", eventType=\""
       + eventType
       + "\""
       + ", description=\""
       + description
       + "\""
       + ", location="
       + location
       + ", blockId="
       + blockId
       + ", serviceId="
       + serviceId
       + ", tripId="
       + tripId
       + ", routeId="
       + routeId
       + ", predictable="
       + predictable
       + ", becameUnpredictable="
       + becameUnpredictable
       + ", avlTime="
       + Time.dateTimeStrMsec(avlTime)
       + ", supervisor="
       + supervisor
       + "]";
 }
Exemple #8
0
 @Override
 public String toString() {
   return "IpcVehicle ["
       + "vehicleId="
       + avl.getVehicleId()
       + ", blockId="
       + blockId
       + ", blockAssignmentMethod="
       + blockAssignmentMethod
       + ", routeId="
       + routeId
       + ", routeShortName="
       + routeShortName
       + ", tripId="
       + tripId
       + ", tripPatternId="
       + tripPatternId
       + ", directionId="
       + directionId
       + ", headsign="
       + headsign
       + ", predictable="
       + predictable
       + ", schedBasedPred="
       + schedBasedPred
       + ", realTimeSchedAdh="
       + realTimeSchedAdh
       + ", isDelayed="
       + isDelayed
       + ", isLayover="
       + isLayover
       + ", layoverDepartureTime="
       + Time.timeStrNoTimeZone(layoverDepartureTime)
       + ", nextStopId="
       + nextStopId
       + ", nextStopName="
       + nextStopName
       + ", avl="
       + avl
       + ", heading="
       + heading
       + ", vehicleType="
       + vehicleType
       + "]";
 }
Exemple #9
0
  /**
   * Creates a copy of the Trip object but adjusts the startTime, endTime, and scheduledTimesMap
   * according to the frequenciesBasedStartTime. This is used when the frequencies.txt file
   * specifies exact_times for a trip.
   *
   * @param tripFromStopTimes
   * @param frequenciesBasedStartTime
   */
  public Trip(Trip tripFromStopTimes, int frequenciesBasedStartTime) {
    this.configRev = tripFromStopTimes.configRev;
    this.tripId = tripFromStopTimes.tripId;
    this.tripShortName = tripFromStopTimes.tripShortName;
    this.directionId = tripFromStopTimes.directionId;
    this.routeId = tripFromStopTimes.routeId;
    this.routeShortName = tripFromStopTimes.routeShortName;
    this.serviceId = tripFromStopTimes.serviceId;
    this.headsign = tripFromStopTimes.headsign;
    this.shapeId = tripFromStopTimes.shapeId;
    this.tripPattern = tripFromStopTimes.tripPattern;
    this.travelTimes = tripFromStopTimes.travelTimes;

    // Set the updated start and end times by using the frequencies
    // based start time.
    this.startTime = tripFromStopTimes.startTime + frequenciesBasedStartTime;
    this.endTime = tripFromStopTimes.endTime + frequenciesBasedStartTime;

    // Since frequencies being used for configuration we will have multiple
    // trips with the same ID. But need a different block ID for each one.
    // Therefore use the original trip's block ID but then append the
    // start time as a string to make it unique.
    this.blockId = tripFromStopTimes.blockId + "_" + Time.timeOfDayStr(this.startTime);

    // Set the scheduledTimesMap by using the frequencies based start time
    for (ScheduleTime schedTimeFromStopTimes : tripFromStopTimes.scheduledTimesList) {
      Integer arrivalTime = null;
      if (schedTimeFromStopTimes.getArrivalTime() != null)
        arrivalTime = schedTimeFromStopTimes.getArrivalTime() + frequenciesBasedStartTime;
      Integer departureTime = null;
      if (schedTimeFromStopTimes.getDepartureTime() != null)
        departureTime = schedTimeFromStopTimes.getDepartureTime() + frequenciesBasedStartTime;

      ScheduleTime schedTimeFromFrequency = new ScheduleTime(arrivalTime, departureTime);
      this.scheduledTimesList.add(schedTimeFromFrequency);
    }

    // Since this constructor is only for frequency based trips where
    // exact_times is true set the corresponding members to indicate such
    this.noSchedule = false;
    this.exactTimesHeadway = true;
  }
  /**
   * Initiates a real-time amigocloud feed. If there is a JSONException while starting connection
   * then will try again every 10 seconds until successful.
   */
  public void startRealtimeWebsockets() {
    logger.info("Starting amigocloud AVL feed");

    int numberOfExceptions = 0;
    boolean exceptionOccurred = false;
    do {
      try {
        // Actually make the connection
        AmigoWebsockets socket =
            new AmigoWebsockets(
                userId.getValue(),
                projectId.getValue(),
                datasetId.getValue(),
                feedUrl.toString(),
                new MyAmigoWebsocketListener(this));
        socket.connect();
        exceptionOccurred = false;
      } catch (JSONException e) {
        ++numberOfExceptions;
        exceptionOccurred = true;

        // If exception has occurred several times then send e-mail to
        // indicate there is an ongoing problem
        if (numberOfExceptions == 3) {
          logger.error(
              Markers.email(),
              "For agencyId={} exception when starting up "
                  + "AmigoCloudAvlModule. {}. numberOfExceptions={}",
              AgencyConfig.getAgencyId(),
              e.getMessage(),
              numberOfExceptions,
              e);
        }

        // Sleep 10 seconds before trying again
        Time.sleep(10 * Time.MS_PER_SEC);
      }
    } while (exceptionOccurred);
  }