Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix all average travel time graphs and create new graph for others #586

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions src/main/java/beam/analysis/plots/PersonTravelTimeStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Map<Id<Person>, PersonDepartureEvent>> personLastDepartureEvents = new HashMap<>();
private Map<String, Map<Integer, List<Double>>> hourlyPersonTravelTimes = new HashMap<>();

Expand Down Expand Up @@ -52,7 +53,7 @@ private double[] buildAverageTimesDataset(Map<Integer, List<Double>> 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<Double> hourData = times.get(i);
Double average = 0d;
Expand Down Expand Up @@ -136,12 +137,12 @@ public void resetStats() {
}

private void processPersonArrivalEvent(Event event) {
String mode = ((PersonArrivalEvent) event).getLegMode();
PersonArrivalEvent personArrivalEvent = (PersonArrivalEvent) event;
Id<Person> personId = personArrivalEvent.getPersonId();
String mode = personArrivalEvent.getLegMode();

Map<Id<Person>, PersonDepartureEvent> departureEvents = personLastDepartureEvents.get(mode);
if (departureEvents != null) {
PersonArrivalEvent personArrivalEvent = (PersonArrivalEvent) event;
Id<Person> personId = personArrivalEvent.getPersonId();
PersonDepartureEvent personDepartureEvent = departureEvents.get(personId);
if (personDepartureEvent != null) {
int basketHour = GraphsStatsAgentSimEventsListener.getEventHour(personDepartureEvent.getTime());
Expand All @@ -166,6 +167,43 @@ private void processPersonArrivalEvent(Event event) {
departureEvents.remove(personId);
personLastDepartureEvents.put(mode, departureEvents);
}
else {
Set<String> modeSet = personLastDepartureEvents.keySet();
String selectedMode = null;
//Modeset is very small list hence we can iterate them
for (String mayBeMode : modeSet) {
Map<Id<Person>, 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<Integer, List<Double>> hourlyPersonTravelTimesPerMode = hourlyPersonTravelTimes.get(otherMode);
if (hourlyPersonTravelTimesPerMode == null) {
hourlyPersonTravelTimesPerMode = new HashMap<>();
List<Double> travelTimes = new ArrayList<>();
travelTimes.add(travelTime);
hourlyPersonTravelTimesPerMode.put(basketHour, travelTimes);
} else {
List<Double> 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<Id<Person>, PersonDepartureEvent> departureEventsList = personLastDepartureEvents.get(selectedMode);
departureEventsList.remove(personId);
personLastDepartureEvents.put(selectedMode, departureEventsList);
}
}
}
}

Expand Down