# HG changeset patch # User Nicolas Saunier # Date 1446675126 18000 # Node ID a05b70f307ddf1a614af3faca04290a312f8ec40 # Parent 61248f2cd4592b6d4c1d055704ac4b70d2ad4b1c added function to count vehicles per VISSIM link diff -r 61248f2cd459 -r a05b70f307dd python/storage.py --- a/python/storage.py Tue Nov 03 13:48:28 2015 -0500 +++ b/python/storage.py Wed Nov 04 17:12:06 2015 -0500 @@ -761,6 +761,16 @@ except sqlite3.OperationalError as error: printDBError(error) +def getNObjectsInLinkFromVissimFile(filename, linkIds): + '''Returns the number of objects that traveled through the link ids''' + connection = sqlite3.connect(filename) + cursor = connection.cursor() + queryStatement = 'SELECT link_id, COUNT(DISTINCT trajectory_id) FROM curvilinear_positions where link_id IN ('+','.join([str(id) for id in linkIds])+') GROUP BY link_id' + try: + cursor.execute(queryStatement) + return {row[0]:row[1] for row in cursor} + except sqlite3.OperationalError as error: + printDBError(error) def loadTrajectoriesFromVissimFile(filename, simulationStepsPerTimeUnit, objectNumbers = None, warmUpLastInstant = None, usePandas = False, nDecimals = 2, lowMemory = True): '''Reads data from VISSIM .fzp trajectory file