Mercurial > hg > nsaunier > traffic-intelligence
comparison python/events.py @ 706:e395bffe1412 dev
cleaned unused code (up to date in Paul St-Aubin PVC code)
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Wed, 22 Jul 2015 14:15:33 -0400 |
| parents | 0ceee3b1a96d |
| children | 4e89341edd29 |
comparison
equal
deleted
inserted
replaced
| 705:0ceee3b1a96d | 706:e395bffe1412 |
|---|---|
| 336 if any interaction indicator time series is different enough (<minSimilarity), | 336 if any interaction indicator time series is different enough (<minSimilarity), |
| 337 it will become a new prototype. | 337 it will become a new prototype. |
| 338 Non-prototype interactions will be assigned to an existing prototype if all indicators are similar enough''' | 338 Non-prototype interactions will be assigned to an existing prototype if all indicators are similar enough''' |
| 339 pass | 339 pass |
| 340 | 340 |
| 341 # TODO: | |
| 342 #http://stackoverflow.com/questions/3288595/multiprocessing-using-pool-map-on-a-function-defined-in-a-class | |
| 343 #http://www.rueckstiess.net/research/snippets/show/ca1d7d90 | |
| 344 def calculateIndicatorPipe(pairs, predParam, timeHorizon=75,collisionDistanceThreshold=1.8): | |
| 345 collisionPoints, crossingZones = prediction.computeCrossingsCollisions(pairs.roadUser1, pairs.roadUser2, predParam, collisionDistanceThreshold, timeHorizon) | |
| 346 #print pairs.num | |
| 347 # Ignore empty collision points | |
| 348 empty = 1 | |
| 349 for i in collisionPoints: | |
| 350 if(collisionPoints[i] != []): | |
| 351 empty = 0 | |
| 352 if(empty == 1): | |
| 353 pairs.hasCP = 0 | |
| 354 else: | |
| 355 pairs.hasCP = 1 | |
| 356 pairs.CP = collisionPoints | |
| 357 | |
| 358 # Ignore empty crossing zones | |
| 359 empty = 1 | |
| 360 for i in crossingZones: | |
| 361 if(crossingZones[i] != []): | |
| 362 empty = 0 | |
| 363 if(empty == 1): | |
| 364 pairs.hasCZ = 0 | |
| 365 else: | |
| 366 pairs.hasCZ = 1 | |
| 367 pairs.CZ = crossingZones | |
| 368 return pairs | |
| 369 | |
| 370 def calculateIndicatorPipe_star(a_b): | |
| 371 """Convert `f([1,2])` to `f(1,2)` call.""" | |
| 372 return calculateIndicatorPipe(*a_b) | |
| 373 | |
| 374 class VehPairs(): | |
| 375 '''Create a veh-pairs object from objects list''' | |
| 376 def __init__(self,objects): | |
| 377 self.pairs = createInteractions(objects) | |
| 378 self.interactionCount = 0 | |
| 379 self.CPcount = 0 | |
| 380 self.CZcount = 0 | |
| 381 | |
| 382 # Process indicator calculation with support for multi-threading | |
| 383 def calculateIndicators(self,predParam,threads=1,timeHorizon=75,collisionDistanceThreshold=1.8): | |
| 384 if(threads > 1): | |
| 385 pool = multiprocessing.Pool(threads) | |
| 386 self.pairs = pool.map(calculateIndicatorPipe_star, itertools.izip(self.pairs, itertools.repeat(predParam))) | |
| 387 pool.close() | |
| 388 else: | |
| 389 #prog = Tools.ProgressBar(0, len(self.pairs), 77) #Removed in traffic-intelligenc port | |
| 390 for j in xrange(len(self.pairs)): | |
| 391 #prog.updateAmount(j) #Removed in traffic-intelligenc port | |
| 392 collisionPoints, crossingZones = prediction.computeCrossingsCollisions(self.pairs[j].roadUser1, self.pairs[j].roadUser2, predParam, collisionDistanceThreshold, timeHorizon) | |
| 393 | |
| 394 # Ignore empty collision points | |
| 395 empty = 1 | |
| 396 for i in collisionPoints: | |
| 397 if(collisionPoints[i] != []): | |
| 398 empty = 0 | |
| 399 if(empty == 1): | |
| 400 self.pairs[j].hasCP = 0 | |
| 401 else: | |
| 402 self.pairs[j].hasCP = 1 | |
| 403 self.pairs[j].CP = collisionPoints | |
| 404 | |
| 405 # Ignore empty crossing zones | |
| 406 empty = 1 | |
| 407 for i in crossingZones: | |
| 408 if(crossingZones[i] != []): | |
| 409 empty = 0 | |
| 410 if(empty == 1): | |
| 411 self.pairs[j].hasCZ = 0 | |
| 412 else: | |
| 413 self.pairs[j].hasCZ = 1 | |
| 414 self.pairs[j].CZ = crossingZones | |
| 415 | |
| 416 for j in self.pairs: | |
| 417 self.interactionCount = self.interactionCount + len(j.CP) | |
| 418 self.CPcount = len(self.getCPlist()) | |
| 419 self.Czcount = len(self.getCZlist()) | |
| 420 | |
| 421 | |
| 422 def getPairsWCP(self): | |
| 423 lists = [] | |
| 424 for j in self.pairs: | |
| 425 if(j.hasCP): | |
| 426 lists.append(j.num) | |
| 427 return lists | |
| 428 | |
| 429 def getPairsWCZ(self): | |
| 430 lists = [] | |
| 431 for j in self.pairs: | |
| 432 if(j.hasCZ): | |
| 433 lists.append(j.num) | |
| 434 return lists | |
| 435 | |
| 436 def getCPlist(self,indicatorThreshold=float('Inf')): | |
| 437 lists = [] | |
| 438 for j in self.pairs: | |
| 439 if(j.hasCP): | |
| 440 for k in j.CP: | |
| 441 if(j.CP[k] != [] and j.CP[k][0].indicator < indicatorThreshold): | |
| 442 lists.append([k,j.CP[k][0]]) | |
| 443 return lists | |
| 444 | |
| 445 def getCZlist(self,indicatorThreshold=float('Inf')): | |
| 446 lists = [] | |
| 447 for j in self.pairs: | |
| 448 if(j.hasCZ): | |
| 449 for k in j.CZ: | |
| 450 if(j.CZ[k] != [] and j.CZ[k][0].indicator < indicatorThreshold): | |
| 451 lists.append([k,j.CZ[k][0]]) | |
| 452 return lists | |
| 453 | |
| 454 def genIndicatorHistogram(self, CPlist=False, bins=range(0,100,1)): | |
| 455 if(not CPlist): | |
| 456 CPlist = self.getCPlist() | |
| 457 if(not CPlist): | |
| 458 return False | |
| 459 TTC_list = [] | |
| 460 for i in CPlist: | |
| 461 TTC_list.append(i[1].indicator) | |
| 462 histo = np.histogram(TTC_list,bins=bins) | |
| 463 histo += (histo[0].astype(float)/np.sum(histo[0]),) | |
| 464 return histo | |
| 465 | 341 |
| 466 class Crossing(moving.STObject): | 342 class Crossing(moving.STObject): |
| 467 '''Class for the event of a street crossing | 343 '''Class for the event of a street crossing |
| 468 | 344 |
| 469 TODO: detecter passage sur la chaussee | 345 TODO: detecter passage sur la chaussee |
