@Override
 public void handleEvent(PersonDepartureEvent event) {
   if (event.getLegMode().equals(TransportMode.pt)) {
     AgentCountBox acb = new AgentCountBox(event.getPersonId());
     acb.waitingTime = event.getTime();
     this.departedMap.put(event.getPersonId(), acb);
   }
 }
 @Override
 public void handleEvent(PersonEntersVehicleEvent event) {
   if (event.getVehicleId().toString().equalsIgnoreCase(this.vehId)) {
     if (event.getTime() >= this.startTime && event.getTime() < this.stopTime) {
       AgentCountBox acb = this.departedMap.get(event.getPersonId());
       acb.waitingTime = event.getTime() - acb.waitingTime;
       acb.travelTimeInVehicle = event.getTime();
       this.enteredMap.put(event.getPersonId(), acb);
       this.departedMap.remove(event.getPersonId());
     }
   }
 }
  @Override
  public void handleEvent(PersonLeavesVehicleEvent event) {
    if (event.getVehicleId().toString().equalsIgnoreCase(this.vehId)) {
      if (event.getTime() >= this.startTime && event.getTime() < this.stopTime) {
        AgentCountBox acb = this.enteredMap.get(event.getPersonId());
        acb.travelTimeInVehicle = event.getTime() - acb.travelTimeInVehicle;
        this.completeAgents.add(acb);
        this.enteredMap.remove(event.getPersonId());

        if (this.debug.containsKey(event.getPersonId())) {
          //					log.warn("Agent " + event.getPersonId() + " counted twice");
          this.numberOfAdditionalTripsPerformed++;
        } else {
          this.debug.put(event.getPersonId(), "");
        }
      }
    }
  }
  @Override
  public String printResults() {

    double averageWaitingTime = 0.0;
    double averageTravelTime = 0.0;

    double sumWaitingTime = 0.0;
    double sumTravelTime = 0.0;

    int numberOfAgentsCountedSoFar = 0;

    for (AgentCountBox agentCountBox : this.completeAgents) {
      averageWaitingTime =
          (numberOfAgentsCountedSoFar * averageWaitingTime + agentCountBox.getWaitingTime())
              / (numberOfAgentsCountedSoFar + 1);
      averageTravelTime =
          (numberOfAgentsCountedSoFar * averageTravelTime + agentCountBox.getTravelTimeInVehicle())
              / (numberOfAgentsCountedSoFar + 1);

      sumWaitingTime += agentCountBox.getWaitingTime();
      sumTravelTime += agentCountBox.getTravelTimeInVehicle();

      numberOfAgentsCountedSoFar++;
    }

    log.info(
        "Veh "
            + this.vehId
            + " from "
            + Time.writeTime(this.startTime)
            + " to "
            + Time.writeTime(this.stopTime)
            + " counted "
            + numberOfAgentsCountedSoFar
            + " agents who (in average) had to wait for "
            + ((int) averageWaitingTime)
            + "s and travelled "
            + ((int) averageTravelTime)
            + "s - sumWaiting "
            + ((int) sumWaitingTime)
            + "s, sumTT "
            + ((int) sumTravelTime)
            + "s, "
            + this.numberOfAdditionalTripsPerformed
            + " agents drive a bus stop ahead resulting in additional trips");

    return this.vehId
        + ", "
        + Time.writeTime(this.startTime)
        + ", "
        + Time.writeTime(this.stopTime)
        + ", "
        + numberOfAgentsCountedSoFar
        + ", "
        + ((int) averageWaitingTime)
        + ", "
        + ((int) averageTravelTime)
        + ", "
        + ((int) sumWaitingTime)
        + ", "
        + ((int) sumTravelTime)
        + ", "
        + this.numberOfAdditionalTripsPerformed;
  }