Mercurial > hg > nsaunier > traffic-intelligence
comparison trafficintelligence/storage.py @ 1040:20799ac9524e
integrating code of learn-motion-patterns in storage.py
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Wed, 04 Jul 2018 15:37:04 -0400 |
| parents | 5621e4ad2428 |
| children | fc7c0f38e8a6 |
comparison
equal
deleted
inserted
replaced
| 1039:5621e4ad2428 | 1040:20799ac9524e |
|---|---|
| 238 userTypes = {} | 238 userTypes = {} |
| 239 for row in cursor: | 239 for row in cursor: |
| 240 userTypes[row[0]] = row[1] | 240 userTypes[row[0]] = row[1] |
| 241 return userTypes | 241 return userTypes |
| 242 | 242 |
| 243 def loadTrajectoriesFromSqlite(filename, trajectoryType, objectNumbers = None, withFeatures = False, timeStep = None): | 243 def loadTrajectoriesFromSqlite(filename, trajectoryType, objectNumbers = None, withFeatures = False, timeStep = None, maxNObjectFeatures = 1): |
| 244 '''Loads the trajectories (in the general sense, | 244 '''Loads the trajectories (in the general sense, |
| 245 either features, objects (feature groups) or bounding box series) | 245 either features, objects (feature groups), longest features per object, or bounding box series) |
| 246 | |
| 246 The number loaded is either the first objectNumbers objects, | 247 The number loaded is either the first objectNumbers objects, |
| 247 or the indices in objectNumbers from the database''' | 248 or the indices in objectNumbers from the database''' |
| 248 objects = [] | 249 objects = [] |
| 249 with sqlite3.connect(filename) as connection: | 250 with sqlite3.connect(filename) as connection: |
| 250 objects = loadTrajectoriesFromTable(connection, 'positions', trajectoryType, objectNumbers, timeStep) | 251 if trajectoryType == 'objectfeature': |
| 251 objectVelocities = loadTrajectoriesFromTable(connection, 'velocities', trajectoryType, objectNumbers, timeStep) | 252 objectFeatureNumbers = loadObjectFeatureFrameNumbers(filename, objectNumbers) |
| 253 featureNumbers = [] | |
| 254 for numbers in objectFeatureNumbers.values(): | |
| 255 featureNumbers += numbers[:min(len(numbers), maxNObjectFeatures)] | |
| 256 objects = loadTrajectoriesFromTable(connection, 'positions', 'feature', featureNumbers, timeStep) | |
| 257 objectVelocities = loadTrajectoriesFromTable(connection, 'velocities', 'feature', featureNumbers, timeStep) | |
| 258 else: | |
| 259 objects = loadTrajectoriesFromTable(connection, 'positions', trajectoryType, objectNumbers, timeStep) | |
| 260 objectVelocities = loadTrajectoriesFromTable(connection, 'velocities', trajectoryType, objectNumbers, timeStep) | |
| 252 | 261 |
| 253 if len(objectVelocities) > 0: | 262 if len(objectVelocities) > 0: |
| 254 for o,v in zip(objects, objectVelocities): | 263 for o,v in zip(objects, objectVelocities): |
| 255 if o.getNum() == v.getNum(): | 264 if o.getNum() == v.getNum(): |
| 256 o.velocities = v.positions | 265 o.velocities = v.positions |
| 417 Either feature positions (and velocities if they exist) | 426 Either feature positions (and velocities if they exist) |
| 418 or curvilinear positions will be saved at a time''' | 427 or curvilinear positions will be saved at a time''' |
| 419 | 428 |
| 420 with sqlite3.connect(outputFilename) as connection: | 429 with sqlite3.connect(outputFilename) as connection: |
| 421 try: | 430 try: |
| 422 saveTrajectoriesToTable(connection, objects, trajectoryType, None) | 431 saveTrajectoriesToTable(connection, objects, trajectoryType) |
| 423 except sqlite3.OperationalError as error: | 432 except sqlite3.OperationalError as error: |
| 424 printDBError(error) | 433 printDBError(error) |
| 425 | 434 |
| 426 def setRoadUserTypes(filename, objects): | 435 def setRoadUserTypes(filename, objects): |
| 427 '''Saves the user types of the objects in the sqlite database stored in filename | 436 '''Saves the user types of the objects in the sqlite database stored in filename |
