From 7829f3a2fdd2af74f036e88c702f86bebebce38e Mon Sep 17 00:00:00 2001 From: rajnikant Date: Sat, 15 Sep 2018 04:15:16 +0530 Subject: [PATCH] fix average travel time graphs and created a new graph for others category --- .../analysis/plots/PersonTravelTimeStats.java | 46 +++++++++++++++++-- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/main/java/beam/analysis/plots/PersonTravelTimeStats.java b/src/main/java/beam/analysis/plots/PersonTravelTimeStats.java index da42a6da04d..86100cd5a3b 100755 --- a/src/main/java/beam/analysis/plots/PersonTravelTimeStats.java +++ b/src/main/java/beam/analysis/plots/PersonTravelTimeStats.java @@ -23,6 +23,7 @@ public class PersonTravelTimeStats implements IGraphStats { private static final int SECONDS_IN_MINUTE = 60; private static final String xAxisTitle = "Hour"; private static final String yAxisTitle = "Average Travel Time [min]"; + private static final String otherMode = "others"; private Map, PersonDepartureEvent>> personLastDepartureEvents = new HashMap<>(); private Map>> hourlyPersonTravelTimes = new HashMap<>(); @@ -52,7 +53,7 @@ private double[] buildAverageTimesDataset(Map> times) { int maxHour = hoursList.get(hoursList.size() - 1); double[] travelTimes = new double[maxHour + 1]; - for (int i = 0; i < maxHour; i++) { + for (int i = 0; i <= maxHour; i++) { List hourData = times.get(i); Double average = 0d; @@ -136,12 +137,12 @@ public void resetStats() { } private void processPersonArrivalEvent(Event event) { - String mode = ((PersonArrivalEvent) event).getLegMode(); + PersonArrivalEvent personArrivalEvent = (PersonArrivalEvent) event; + Id personId = personArrivalEvent.getPersonId(); + String mode = personArrivalEvent.getLegMode(); Map, PersonDepartureEvent> departureEvents = personLastDepartureEvents.get(mode); if (departureEvents != null) { - PersonArrivalEvent personArrivalEvent = (PersonArrivalEvent) event; - Id personId = personArrivalEvent.getPersonId(); PersonDepartureEvent personDepartureEvent = departureEvents.get(personId); if (personDepartureEvent != null) { int basketHour = GraphsStatsAgentSimEventsListener.getEventHour(personDepartureEvent.getTime()); @@ -166,6 +167,43 @@ private void processPersonArrivalEvent(Event event) { departureEvents.remove(personId); personLastDepartureEvents.put(mode, departureEvents); } + else { + Set modeSet = personLastDepartureEvents.keySet(); + String selectedMode = null; + //Modeset is very small list hence we can iterate them + for (String mayBeMode : modeSet) { + Map, PersonDepartureEvent> lastDepartureEvents = personLastDepartureEvents.get(mayBeMode); + if (lastDepartureEvents.get(personId) != null) { + personDepartureEvent = lastDepartureEvents.get(personId); + selectedMode = mayBeMode; + break; + } + } + if (personDepartureEvent != null) { + int basketHour = GraphsStatsAgentSimEventsListener.getEventHour(personDepartureEvent.getTime()); + Double travelTime = (personArrivalEvent.getTime() - personDepartureEvent.getTime()) / SECONDS_IN_MINUTE; + Map> hourlyPersonTravelTimesPerMode = hourlyPersonTravelTimes.get(otherMode); + if (hourlyPersonTravelTimesPerMode == null) { + hourlyPersonTravelTimesPerMode = new HashMap<>(); + List travelTimes = new ArrayList<>(); + travelTimes.add(travelTime); + hourlyPersonTravelTimesPerMode.put(basketHour, travelTimes); + } else { + List travelTimes = hourlyPersonTravelTimesPerMode.get(basketHour); + if (travelTimes == null) { + travelTimes = new ArrayList<>(); + travelTimes.add(travelTime); + } else { + travelTimes.add(travelTime); + } + hourlyPersonTravelTimesPerMode.put(basketHour, travelTimes); + } + hourlyPersonTravelTimes.put(otherMode, hourlyPersonTravelTimesPerMode); + Map, PersonDepartureEvent> departureEventsList = personLastDepartureEvents.get(selectedMode); + departureEventsList.remove(personId); + personLastDepartureEvents.put(selectedMode, departureEventsList); + } + } } }