changeset 759:a05b70f307dd dev

added function to count vehicles per VISSIM link
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 04 Nov 2015 17:12:06 -0500
parents 61248f2cd459
children d72e4bcc1e36
files python/storage.py
diffstat 1 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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