# HG changeset patch # User Nicolas Saunier # Date 1356132012 18000 # Node ID dbe7e53334d712b24bc7d3557e920793ebcb6dc9 # Parent abbd4bc13dac9e1695b3675af381f3ca987f4bac added function to create interactions diff -r abbd4bc13dac -r dbe7e53334d7 python/event.py --- a/python/event.py Fri Dec 21 17:50:10 2012 -0500 +++ b/python/event.py Fri Dec 21 18:20:12 2012 -0500 @@ -21,8 +21,7 @@ def __init__(self, num = None, timeInterval = None, roaduserNum1 = None, roaduserNum2 = None, movingObject1 = None, movingObject2 = None, categoryNum = None): moving.STObject.__init__(self, num, timeInterval) - self.roaduserNum1 = roaduserNum1 - self.roaduserNum2 = roaduserNum2 + self.roaduserNumbers = set([roaduserNum1, roaduserNum2]) self.movingObject1 = movingObject1 self.movingObject2 = movingObject2 self.categoryNum = categoryNum @@ -51,6 +50,20 @@ moving.SeverityIndicator('Distances', distances, self.timeInterval), moving.SeverityIndicator('Collision Course Cosine', collisionCourseCosine)] +def createInteractions(objects): + '''Create all interactions of two co-existing road users + + todo add test to compute categories?''' + interactions = [] + num = 0 + for i in xrange(len(objects)): + for j in xrange(i): + commonTimeInterval = objects[i].commonTimeInterval(objects[j]) + if not commonTimeInterval.empty(): + interactions.append(Interaction(num, commonTimeInterval, objects[i].num, objects[j].num, objects[i], objects[j])) + num += 1 + return interactions + class Crossing(moving.STObject): '''Class for the event of a street crossing