Mercurial Hosting > traffic-intelligence
comparison python/events.py @ 998:933670761a57
updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Sun, 27 May 2018 23:22:48 -0400 |
parents | 030b16ab4f64 |
children |
comparison
equal
deleted
inserted
replaced
997:4f3387a242a1 | 998:933670761a57 |
---|---|
19 else: | 19 else: |
20 prototypesRoutes=[x for x in sorted(prototypes.keys())] | 20 prototypesRoutes=[x for x in sorted(prototypes.keys())] |
21 routeSim={} | 21 routeSim={} |
22 lcss = utils.LCSS(similarityFunc=lambda x,y: (distanceForLCSS(x,y) <= spatialThreshold),delta=delta) | 22 lcss = utils.LCSS(similarityFunc=lambda x,y: (distanceForLCSS(x,y) <= spatialThreshold),delta=delta) |
23 for y in prototypesRoutes: | 23 for y in prototypesRoutes: |
24 if y in prototypes.keys(): | 24 if y in prototypes: |
25 prototypesIDs=prototypes[y] | 25 prototypesIDs=prototypes[y] |
26 similarity=[] | 26 similarity=[] |
27 for x in prototypesIDs: | 27 for x in prototypesIDs: |
28 s=lcss.computeNormalized(objects[j].positions, objects[x].positions) | 28 s=lcss.computeNormalized(objects[j].positions, objects[x].positions) |
29 similarity.append(s) | 29 similarity.append(s) |
35 return i | 35 return i |
36 | 36 |
37 def getRoute(obj,prototypes,objects,noiseEntryNums,noiseExitNums,useDestination=True): | 37 def getRoute(obj,prototypes,objects,noiseEntryNums,noiseExitNums,useDestination=True): |
38 route=(obj.startRouteID,obj.endRouteID) | 38 route=(obj.startRouteID,obj.endRouteID) |
39 if useDestination: | 39 if useDestination: |
40 if route not in prototypes.keys(): | 40 if route not in prototypes: |
41 route= findRoute(prototypes,objects,route,obj.getNum(),noiseEntryNums,noiseExitNums) | 41 route= findRoute(prototypes,objects,route,obj.getNum(),noiseEntryNums,noiseExitNums) |
42 return route | 42 return route |
43 | 43 |
44 class Interaction(moving.STObject, VideoFilenameAddable): | 44 class Interaction(moving.STObject, VideoFilenameAddable): |
45 '''Class for an interaction between two road users | 45 '''Class for an interaction between two road users |
151 | 151 |
152 def getIndicatorValuesAtInstant(self, instant): | 152 def getIndicatorValuesAtInstant(self, instant): |
153 '''Returns list of indicator values at instant | 153 '''Returns list of indicator values at instant |
154 as dict (with keys from indicators dict)''' | 154 as dict (with keys from indicators dict)''' |
155 values = {} | 155 values = {} |
156 for k, indicator in self.indicators.iteritems(): | 156 for k, indicator in self.indicators.items(): |
157 values[k] = indicator[instant] | 157 values[k] = indicator[instant] |
158 return values | 158 return values |
159 | 159 |
160 def plot(self, options = '', withOrigin = False, timeStep = 1, withFeatures = False, **kwargs): | 160 def plot(self, options = '', withOrigin = False, timeStep = 1, withFeatures = False, **kwargs): |
161 self.roadUser1.plot(options, withOrigin, timeStep, withFeatures, **kwargs) | 161 self.roadUser1.plot(options, withOrigin, timeStep, withFeatures, **kwargs) |
223 if timeInterval is not None: | 223 if timeInterval is not None: |
224 commonTimeInterval = timeInterval | 224 commonTimeInterval = timeInterval |
225 else: | 225 else: |
226 commonTimeInterval = self.timeInterval | 226 commonTimeInterval = self.timeInterval |
227 self.collisionPoints, crossingZones = predictionParameters.computeCrossingsCollisions(self.roadUser1, self.roadUser2, collisionDistanceThreshold, timeHorizon, computeCZ, debug, commonTimeInterval) | 227 self.collisionPoints, crossingZones = predictionParameters.computeCrossingsCollisions(self.roadUser1, self.roadUser2, collisionDistanceThreshold, timeHorizon, computeCZ, debug, commonTimeInterval) |
228 for i, cps in self.collisionPoints.iteritems(): | 228 for i, cps in self.collisionPoints.items(): |
229 TTCs[i] = prediction.SafetyPoint.computeExpectedIndicator(cps) | 229 TTCs[i] = prediction.SafetyPoint.computeExpectedIndicator(cps) |
230 collisionProbabilities[i] = sum([p.probability for p in cps]) | 230 collisionProbabilities[i] = sum([p.probability for p in cps]) |
231 if len(TTCs) > 0: | 231 if len(TTCs) > 0: |
232 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[7], TTCs, mostSevereIsMax=False)) | 232 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[7], TTCs, mostSevereIsMax=False)) |
233 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[6], collisionProbabilities)) | 233 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[6], collisionProbabilities)) |
234 | 234 |
235 # crossing zones and pPET | 235 # crossing zones and pPET |
236 if computeCZ: | 236 if computeCZ: |
237 self.crossingZones = crossingZones | 237 self.crossingZones = crossingZones |
238 pPETs = {} | 238 pPETs = {} |
239 for i, cz in self.crossingZones.iteritems(): | 239 for i, cz in self.crossingZones.items(): |
240 pPETs[i] = prediction.SafetyPoint.computeExpectedIndicator(cz) | 240 pPETs[i] = prediction.SafetyPoint.computeExpectedIndicator(cz) |
241 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[9], pPETs, mostSevereIsMax=False)) | 241 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[9], pPETs, mostSevereIsMax=False)) |
242 # TODO add probability of collision, and probability of successful evasive action | 242 # TODO add probability of collision, and probability of successful evasive action |
243 | 243 |
244 def computePET(self, collisionDistanceThreshold): | 244 def computePET(self, collisionDistanceThreshold): |
267 if _others is not None: | 267 if _others is not None: |
268 others = _others | 268 others = _others |
269 | 269 |
270 interactions = [] | 270 interactions = [] |
271 num = 0 | 271 num = 0 |
272 for i in xrange(len(objects)): | 272 for i in range(len(objects)): |
273 if _others is None: | 273 if _others is None: |
274 others = objects[:i] | 274 others = objects[:i] |
275 for j in xrange(len(others)): | 275 for j in range(len(others)): |
276 commonTimeInterval = objects[i].commonTimeInterval(others[j]) | 276 commonTimeInterval = objects[i].commonTimeInterval(others[j]) |
277 if not commonTimeInterval.empty(): | 277 if not commonTimeInterval.empty(): |
278 interactions.append(Interaction(num, commonTimeInterval, objects[i].num, others[j].num, objects[i], others[j])) | 278 interactions.append(Interaction(num, commonTimeInterval, objects[i].num, others[j].num, objects[i], others[j])) |
279 num += 1 | 279 num += 1 |
280 return interactions | 280 return interactions |