Mercurial > hg > nsaunier > traffic-intelligence
comparison python/storage.py @ 585:aab2242ea88c
minor modification of objectNumbers to None
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Thu, 04 Dec 2014 17:04:56 -0500 |
| parents | 5bda87ac0a69 |
| children | ff4f0ce46ca6 |
comparison
equal
deleted
inserted
replaced
| 584:5bda87ac0a69 | 585:aab2242ea88c |
|---|---|
| 251 elif trajectoryType == 'object': | 251 elif trajectoryType == 'object': |
| 252 statementBeginning = 'and OF.object_id ' | 252 statementBeginning = 'and OF.object_id ' |
| 253 else: | 253 else: |
| 254 print('no trajectory type was chosen') | 254 print('no trajectory type was chosen') |
| 255 | 255 |
| 256 if type(objectNumbers) == int: | 256 if objectNumbers is None: |
| 257 if objectNumbers == -1: | 257 query = '' |
| 258 query = '' | 258 elif type(objectNumbers) == int: |
| 259 else: | 259 query = statementBeginning+'between 0 and {0} '.format(objectNumbers) |
| 260 query = statementBeginning+'between 0 and {0} '.format(objectNumbers) | |
| 261 elif type(objectNumbers) == list: | 260 elif type(objectNumbers) == list: |
| 262 query = statementBeginning+'in ('+', '.join([str(n) for n in objectNumbers])+') ' | 261 query = statementBeginning+'in ('+', '.join([str(n) for n in objectNumbers])+') ' |
| 263 return query | 262 return query |
| 264 | 263 |
| 265 def loadTrajectoriesFromTable(connection, tableName, trajectoryType, objectNumbers = -1): | 264 def loadTrajectoriesFromTable(connection, tableName, trajectoryType, objectNumbers = None): |
| 266 '''Loads trajectories (in the general sense) from the given table | 265 '''Loads trajectories (in the general sense) from the given table |
| 267 can be positions or velocities | 266 can be positions or velocities |
| 268 | 267 |
| 269 returns a moving object''' | 268 returns a moving object''' |
| 270 cursor = connection.cursor() | 269 cursor = connection.cursor() |
| 302 if obj: | 301 if obj: |
| 303 objects.append(obj) | 302 objects.append(obj) |
| 304 | 303 |
| 305 return objects | 304 return objects |
| 306 | 305 |
| 307 def loadTrajectoriesFromSqlite(filename, trajectoryType, objectNumbers = -1): | 306 def loadTrajectoriesFromSqlite(filename, trajectoryType, objectNumbers = None): |
| 308 '''Loads nObjects or the indices in objectNumbers from the database''' | 307 '''Loads the first objectNumbers objects or the indices in objectNumbers from the database''' |
| 309 connection = sqlite3.connect(filename) # add test if it open | 308 connection = sqlite3.connect(filename) # add test if it open |
| 310 | 309 |
| 311 objects = loadTrajectoriesFromTable(connection, 'positions', trajectoryType, objectNumbers) | 310 objects = loadTrajectoriesFromTable(connection, 'positions', trajectoryType, objectNumbers) |
| 312 objectVelocities = loadTrajectoriesFromTable(connection, 'velocities', trajectoryType, objectNumbers) | 311 objectVelocities = loadTrajectoriesFromTable(connection, 'velocities', trajectoryType, objectNumbers) |
| 313 | 312 |
