changeset 283:dbe7e53334d7

added function to create interactions
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 21 Dec 2012 18:20:12 -0500
parents abbd4bc13dac
children f2cf16ad798f
files python/event.py
diffstat 1 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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