# HG changeset patch # User Nicolas Saunier # Date 1593615772 14400 # Node ID 658f87232536288002fd9b54503618303503d6d6 # Parent 14140b55e580ca71550dd40d3159ba8f97ea583d extended creation of interactions to non simultaneous objects for PET calculations diff -r 14140b55e580 -r 658f87232536 trafficintelligence/events.py --- a/trafficintelligence/events.py Thu May 28 01:03:45 2020 -0400 +++ b/trafficintelligence/events.py Wed Jul 01 11:02:52 2020 -0400 @@ -295,7 +295,7 @@ def getCrossingZones(self): return self.crossingZones -def createInteractions(objects, _others = None): +def createInteractions(objects, _others = None, maxDurationApart = 0): '''Create all interactions of two co-existing road users''' if _others is not None: others = _others @@ -307,7 +307,7 @@ others = objects[:i] for j in range(len(others)): commonTimeInterval = objects[i].commonTimeInterval(others[j]) - if not commonTimeInterval.empty(): + if not commonTimeInterval.empty() or (maxDurationApart > 0 and objects[i].getTimeInterval().distance(objects[j].getTimeInterval()) < maxDurationApart): interactions.append(Interaction(num, commonTimeInterval, objects[i].num, others[j].num, objects[i], others[j])) num += 1 return interactions diff -r 14140b55e580 -r 658f87232536 trafficintelligence/tests/events.txt --- a/trafficintelligence/tests/events.txt Thu May 28 01:03:45 2020 -0400 +++ b/trafficintelligence/tests/events.txt Wed Jul 01 11:02:52 2020 -0400 @@ -6,10 +6,21 @@ >>> interactions = createInteractions(objects) >>> len([i for i in interactions if len(i.roadUserNumbers) == 1]) 0 +>>> len(interactions) +45 >>> objects2 = [MovingObject(num = i, timeInterval = TimeInterval(0,10)) for i in range(100, 110)] >>> interactions = createInteractions(objects, objects2) >>> len([i for i in interactions if len(i.roadUserNumbers) == 1]) 0 +>>> objects3 = [MovingObject(num = i, timeInterval = TimeInterval(12,22)) for i in range(100, 110)] +>>> interactions = createInteractions(objects, objects3) +>>> len(interactions) +0 +>>> interactions = createInteractions(objects, objects3, 3) +>>> len(interactions) +100 +>>> interactions[0].getTimeInterval().empty() +True >>> o1 = MovingObject.generate(1, Point(-5.,0.), Point(0.,0.), TimeInterval(0,10)) >>> o2 = MovingObject.generate(2, Point(0.,-5.), Point(0.,1.), TimeInterval(0,10))