Skip to content

Commit

Permalink
fix: personMoney event reference lookup missing in EventsReader (mats…
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrawley-moia authored May 7, 2024
1 parent 791f39b commit bdf2182
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 37 deletions.
34 changes: 17 additions & 17 deletions matsim/src/main/java/org/matsim/core/events/EventsReaderXMLv1.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,25 @@ private void startEvent(final Attributes atts) {

// === material related to wait2link below here ===
if (LinkLeaveEvent.EVENT_TYPE.equals(eventType)) {
this.events.processEvent(new LinkLeaveEvent(time,
Id.create(atts.getValue(LinkLeaveEvent.ATTRIBUTE_VEHICLE), Vehicle.class),
this.events.processEvent(new LinkLeaveEvent(time,
Id.create(atts.getValue(LinkLeaveEvent.ATTRIBUTE_VEHICLE), Vehicle.class),
Id.create(atts.getValue(LinkLeaveEvent.ATTRIBUTE_LINK), Link.class)
// had driver id in previous version
));
} else if (LinkEnterEvent.EVENT_TYPE.equals(eventType)) {
this.events.processEvent(new LinkEnterEvent(time,
Id.create(atts.getValue(LinkEnterEvent.ATTRIBUTE_VEHICLE), Vehicle.class),
this.events.processEvent(new LinkEnterEvent(time,
Id.create(atts.getValue(LinkEnterEvent.ATTRIBUTE_VEHICLE), Vehicle.class),
Id.create(atts.getValue(LinkEnterEvent.ATTRIBUTE_LINK), Link.class)
// had driver id in previous version
));
} else if (VehicleEntersTrafficEvent.EVENT_TYPE.equals(eventType) ) {
// (this is the new version, marked by the new events name)

this.events.processEvent(new VehicleEntersTrafficEvent(time,
this.events.processEvent(new VehicleEntersTrafficEvent(time,
Id.create(atts.getValue(HasPersonId.ATTRIBUTE_PERSON), Person.class),
Id.create(atts.getValue(VehicleEntersTrafficEvent.ATTRIBUTE_LINK), Link.class),
Id.create(atts.getValue(VehicleEntersTrafficEvent.ATTRIBUTE_LINK), Link.class),
Id.create(atts.getValue(VehicleEntersTrafficEvent.ATTRIBUTE_VEHICLE), Vehicle.class),
atts.getValue(VehicleEntersTrafficEvent.ATTRIBUTE_NETWORKMODE),
atts.getValue(VehicleEntersTrafficEvent.ATTRIBUTE_NETWORKMODE),
Double.parseDouble( atts.getValue( VehicleEntersTrafficEvent.ATTRIBUTE_POSITION) )
));
} else if ( "wait2link".equals(eventType) ) {
Expand All @@ -140,19 +140,19 @@ private void startEvent(final Attributes atts) {
} else {
position = 1.0 ;
}
this.events.processEvent(new VehicleEntersTrafficEvent(time,
this.events.processEvent(new VehicleEntersTrafficEvent(time,
Id.create(atts.getValue(HasPersonId.ATTRIBUTE_PERSON), Person.class),
Id.create(atts.getValue(VehicleEntersTrafficEvent.ATTRIBUTE_LINK), Link.class),
Id.create(atts.getValue(VehicleEntersTrafficEvent.ATTRIBUTE_LINK), Link.class),
vehicleId,
atts.getValue(VehicleEntersTrafficEvent.ATTRIBUTE_NETWORKMODE),
atts.getValue(VehicleEntersTrafficEvent.ATTRIBUTE_NETWORKMODE),
position
));
} else if (VehicleLeavesTrafficEvent.EVENT_TYPE.equals(eventType)) {
this.events.processEvent(new VehicleLeavesTrafficEvent(time,
Id.create(atts.getValue(VehicleLeavesTrafficEvent.ATTRIBUTE_DRIVER), Person.class),
Id.create(atts.getValue(VehicleLeavesTrafficEvent.ATTRIBUTE_LINK), Link.class),
atts.getValue(VehicleLeavesTrafficEvent.ATTRIBUTE_VEHICLE) == null ? null : Id.create(atts.getValue(VehicleLeavesTrafficEvent.ATTRIBUTE_VEHICLE), Vehicle.class),
atts.getValue(VehicleLeavesTrafficEvent.ATTRIBUTE_NETWORKMODE),
this.events.processEvent(new VehicleLeavesTrafficEvent(time,
Id.create(atts.getValue(VehicleLeavesTrafficEvent.ATTRIBUTE_DRIVER), Person.class),
Id.create(atts.getValue(VehicleLeavesTrafficEvent.ATTRIBUTE_LINK), Link.class),
atts.getValue(VehicleLeavesTrafficEvent.ATTRIBUTE_VEHICLE) == null ? null : Id.create(atts.getValue(VehicleLeavesTrafficEvent.ATTRIBUTE_VEHICLE), Vehicle.class),
atts.getValue(VehicleLeavesTrafficEvent.ATTRIBUTE_NETWORKMODE),
Double.parseDouble( atts.getValue( VehicleLeavesTrafficEvent.ATTRIBUTE_POSITION) )
));
}
Expand All @@ -165,7 +165,7 @@ else if (ActivityEndEvent.EVENT_TYPE.equals(eventType)) {
coord = new Coord( xx, yy ) ;
}
this.events.processEvent(new ActivityEndEvent(
time,
time,
Id.create(atts.getValue(HasPersonId.ATTRIBUTE_PERSON), Person.class),
Id.create(atts.getValue(HasLinkId.ATTRIBUTE_LINK), Link.class),
atts.getValue(HasFacilityId.ATTRIBUTE_FACILITY) == null ? null : Id.create(atts.getValue(HasFacilityId.ATTRIBUTE_FACILITY),
Expand Down Expand Up @@ -208,7 +208,7 @@ else if (ActivityEndEvent.EVENT_TYPE.equals(eventType)) {
Id<Link> linkId = linkIdString == null ? null : Id.create(linkIdString, Link.class);
this.events.processEvent(new VehicleAbortsEvent(time, Id.create(atts.getValue(VehicleAbortsEvent.ATTRIBUTE_VEHICLE), Vehicle.class), linkId));
} else if (PersonMoneyEvent.EVENT_TYPE.equals(eventType) || "agentMoney".equals(eventType)) {
this.events.processEvent(new PersonMoneyEvent(time, Id.create(atts.getValue(PersonMoneyEvent.ATTRIBUTE_PERSON), Person.class), Double.parseDouble(atts.getValue(PersonMoneyEvent.ATTRIBUTE_AMOUNT)), atts.getValue(PersonMoneyEvent.ATTRIBUTE_PURPOSE), atts.getValue(PersonMoneyEvent.ATTRIBUTE_TRANSACTION_PARTNER)));
this.events.processEvent(new PersonMoneyEvent(time, Id.create(atts.getValue(PersonMoneyEvent.ATTRIBUTE_PERSON), Person.class), Double.parseDouble(atts.getValue(PersonMoneyEvent.ATTRIBUTE_AMOUNT)), atts.getValue(PersonMoneyEvent.ATTRIBUTE_PURPOSE), atts.getValue(PersonMoneyEvent.ATTRIBUTE_TRANSACTION_PARTNER), atts.getValue(PersonMoneyEvent.ATTRIBUTE_REFERENCE)));
} else if (PersonScoreEvent.EVENT_TYPE.equals(eventType) || "personScore".equals(eventType)) {
this.events.processEvent(new PersonScoreEvent(time, Id.create(atts.getValue(PersonScoreEvent.ATTRIBUTE_PERSON), Person.class), Double.parseDouble(atts.getValue(PersonScoreEvent.ATTRIBUTE_AMOUNT)), atts.getValue(PersonScoreEvent.ATTRIBUTE_KIND)));
} else if (PersonEntersVehicleEvent.EVENT_TYPE.equals(eventType)) {
Expand Down
36 changes: 17 additions & 19 deletions matsim/src/test/java/org/matsim/core/events/EventsReadersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,9 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.events.ActivityEndEvent;
import org.matsim.api.core.v01.events.ActivityStartEvent;
import org.matsim.api.core.v01.events.LinkEnterEvent;
import org.matsim.api.core.v01.events.LinkLeaveEvent;
import org.matsim.api.core.v01.events.PersonArrivalEvent;
import org.matsim.api.core.v01.events.PersonDepartureEvent;
import org.matsim.api.core.v01.events.PersonStuckEvent;
import org.matsim.api.core.v01.events.VehicleEntersTrafficEvent;
import org.matsim.api.core.v01.events.handler.ActivityEndEventHandler;
import org.matsim.api.core.v01.events.handler.ActivityStartEventHandler;
import org.matsim.api.core.v01.events.handler.LinkEnterEventHandler;
import org.matsim.api.core.v01.events.handler.LinkLeaveEventHandler;
import org.matsim.api.core.v01.events.handler.PersonArrivalEventHandler;
import org.matsim.api.core.v01.events.handler.PersonDepartureEventHandler;
import org.matsim.api.core.v01.events.handler.PersonStuckEventHandler;
import org.matsim.api.core.v01.events.handler.VehicleEntersTrafficEventHandler;
import org.matsim.api.core.v01.TransportMode;
import org.matsim.api.core.v01.events.*;
import org.matsim.api.core.v01.events.handler.*;
import org.matsim.api.core.v01.network.Link;
import org.matsim.core.api.experimental.events.EventsManager;
import org.matsim.testcases.MatsimTestUtils;
Expand All @@ -60,7 +47,7 @@ public class EventsReadersTest {

static class TestHandler implements ActivityEndEventHandler, PersonDepartureEventHandler, VehicleEntersTrafficEventHandler,
LinkLeaveEventHandler, LinkEnterEventHandler, PersonArrivalEventHandler, ActivityStartEventHandler,
PersonStuckEventHandler {
PersonStuckEventHandler, PersonMoneyEventHandler {

public int eventCounter = 0;

Expand Down Expand Up @@ -141,6 +128,17 @@ public void handleEvent(final PersonStuckEvent event) {
assertEquals("9", event.getLinkId().toString());
}

@Override
public void handleEvent(final PersonMoneyEvent event) {
this.eventCounter++;
assertEquals(9, this.eventCounter, "expected personMoney-Event to be event #9");
assertEquals(21690.0, event.getTime(), 0.0);
assertEquals("9", event.getPersonId().toString());
assertEquals("drtFare", event.getPurpose());
assertEquals(TransportMode.drt, event.getTransactionPartner());
assertEquals(-1.0, event.getAmount(), 0.0);
assertEquals("drt_0", event.getReference());
}
}

@Test
Expand All @@ -152,7 +150,7 @@ final void testXmlReader() throws SAXException, ParserConfigurationException, IO
EventsReaderXMLv1 reader = new EventsReaderXMLv1(events);
reader.readFile(utils.getClassInputDirectory() + "events.xml");
events.finishProcessing();
assertEquals(8, handler.eventCounter, "number of read events");
assertEquals(9, handler.eventCounter, "number of read events");
}

@Test
Expand All @@ -164,6 +162,6 @@ final void testAutoFormatReaderXml() {
MatsimEventsReader reader = new MatsimEventsReader(events);
reader.readFile(utils.getClassInputDirectory() + "events.xml");
events.finishProcessing();
assertEquals(8, handler.eventCounter, "number of read events");
assertEquals(9, handler.eventCounter, "number of read events");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
<event time="21660" person="6" link="7" type="arrival" />
<event time="21670" person="7" link="8" actType="" type="actstart" />
<event time="21680" person="8" link="9" type="stuckAndAbort" />
</events>
<event time="21690" person="9" type="personMoney" amount="-1.0" purpose="drtFare" transactionPartner="drt" reference="drt_0" />
</events>

0 comments on commit bdf2182

Please sign in to comment.