diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/DrtShiftEfficiencyModeModule.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/DrtShiftEfficiencyModeModule.java index e339db2fb30..d8f4db9f33e 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/DrtShiftEfficiencyModeModule.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/DrtShiftEfficiencyModeModule.java @@ -31,7 +31,7 @@ public DrtShiftEfficiencyModeModule(DrtConfigGroup drtConfigGroup) { @Override public void install() { bindModal(ShiftEfficiencyTracker.class).toProvider(modalProvider(getter -> - new ShiftEfficiencyTracker())).asEagerSingleton(); + new ShiftEfficiencyTracker(getMode()))).asEagerSingleton(); addEventHandlerBinding().to(modalKey(ShiftEfficiencyTracker.class)); bindModal(ShiftEfficiencyAnalysisControlerListener.class).toProvider(modalProvider(getter -> new ShiftEfficiencyAnalysisControlerListener(drtConfigGroup, diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/ShiftEfficiencyTracker.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/ShiftEfficiencyTracker.java index 7ccb1edbbfc..c7963f13ca5 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/ShiftEfficiencyTracker.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/ShiftEfficiencyTracker.java @@ -37,6 +37,7 @@ public final class ShiftEfficiencyTracker implements PersonMoneyEventHandler, PassengerDroppedOffEventHandler, DrtShiftStartedEventHandler, DrtShiftEndedEventHandler { + private final String mode; private Map, Double> revenueByShift; private Map, Id> shiftByRequest; @@ -63,8 +64,9 @@ public Map, Id> getFinishedShifts() { } } - public ShiftEfficiencyTracker() { - this.revenueByShift = new HashMap<>(); + public ShiftEfficiencyTracker(String mode) { + this.mode = mode; + this.revenueByShift = new HashMap<>(); this.shiftByRequest = new HashMap<>(); this.finishedShifts = new HashMap<>(); this.currentRecord = new Record(revenueByShift, shiftByRequest, finishedShifts); @@ -72,35 +74,43 @@ public ShiftEfficiencyTracker() { @Override public void handleEvent(PersonMoneyEvent personMoneyEvent) { - if (DrtFareHandler.PERSON_MONEY_EVENT_PURPOSE_DRT_FARE.equals(personMoneyEvent.getPurpose())) { - Id key = shiftByRequest.get(Id.create(personMoneyEvent.getReference(), DrtRequest.class)); - if(key != null) { - revenueByShift.merge(key, -personMoneyEvent.getAmount(), Double::sum); + if(personMoneyEvent.getTransactionPartner().equals(mode)) { + if (DrtFareHandler.PERSON_MONEY_EVENT_PURPOSE_DRT_FARE.equals(personMoneyEvent.getPurpose())) { + Id key = shiftByRequest.get(Id.create(personMoneyEvent.getReference(), DrtRequest.class)); + if (key != null) { + revenueByShift.merge(key, -personMoneyEvent.getAmount(), Double::sum); + } } } } @Override public void handleEvent(PassengerDroppedOffEvent event) { - Id vehicleId = event.getVehicleId(); - Gbl.assertIf(activeShifts.containsKey(vehicleId)); - Id drtShiftId = activeShifts.get(vehicleId); - shiftByRequest.put(event.getRequestId(), drtShiftId); + if(event.getMode().equals(mode)) { + Id vehicleId = event.getVehicleId(); + Gbl.assertIf(activeShifts.containsKey(vehicleId)); + Id drtShiftId = activeShifts.get(vehicleId); + shiftByRequest.put(event.getRequestId(), drtShiftId); + } } @Override public void handleEvent(DrtShiftStartedEvent event) { - revenueByShift.put(event.getShiftId(), 0.); - if(activeShifts.containsKey(event.getVehicleId())) { - throw new RuntimeException("Vehicle is already registered for another shift"); + if(event.getMode().equals(mode)) { + revenueByShift.put(event.getShiftId(), 0.); + if (activeShifts.containsKey(event.getVehicleId())) { + throw new RuntimeException("Vehicle is already registered for another shift"); + } + activeShifts.put(event.getVehicleId(), event.getShiftId()); } - activeShifts.put(event.getVehicleId(), event.getShiftId()); } @Override public void handleEvent(DrtShiftEndedEvent event) { - activeShifts.remove(event.getVehicleId()); - finishedShifts.put(event.getShiftId(), event.getVehicleId()); + if(event.getMode().equals(mode)) { + activeShifts.remove(event.getVehicleId()); + finishedShifts.put(event.getShiftId(), event.getVehicleId()); + } } @Override diff --git a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/ShiftEfficiencyTest.java b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/ShiftEfficiencyTest.java index c1e3a5c41e0..0679adaefb8 100644 --- a/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/ShiftEfficiencyTest.java +++ b/contribs/drt-extensions/src/test/java/org/matsim/contrib/drt/extension/operations/shifts/analysis/efficiency/ShiftEfficiencyTest.java @@ -41,7 +41,7 @@ public class ShiftEfficiencyTest { void testDrtShiftEfficiency() { EventsManager events = new EventsManagerImpl(); - ShiftEfficiencyTracker shiftEfficiencyTracker = new ShiftEfficiencyTracker(); + ShiftEfficiencyTracker shiftEfficiencyTracker = new ShiftEfficiencyTracker("drt"); events.addHandler(shiftEfficiencyTracker); events.initProcessing();