changeset 1067:092bd9c7deaf

corrected bug with multiprocessing and centiles
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 16 Jul 2018 01:24:26 -0400
parents 862b55a87e63
children e6b791ad7f85
files scripts/process.py trafficintelligence/processing.py
diffstat 2 files changed, 5 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/process.py	Mon Jul 16 01:14:37 2018 -0400
+++ b/scripts/process.py	Mon Jul 16 01:24:26 2018 -0400
@@ -254,9 +254,9 @@
     headers.extend(tmpheaders)
     if args.nProcesses == 1:
         for vs in videoSequences:
-            data.extend(processing.extractVideoSequenceSpeeds(str(parentPath/vs.getDatabaseFilename()), vs.cameraView.site.name, args.nObjects, vs.startTime, vs.cameraView.cameraType.frameRate, args.minUserDuration, aggFunctions))
+            data.extend(processing.extractVideoSequenceSpeeds(str(parentPath/vs.getDatabaseFilename()), vs.cameraView.site.name, args.nObjects, vs.startTime, vs.cameraView.cameraType.frameRate, args.minUserDuration, args.aggMethods, args.aggCentiles))
     else:
-        jobs = [pool.apply_async(processing.extractVideoSequenceSpeeds, args = (str(parentPath/vs.getDatabaseFilename()), vs.cameraView.site.name, args.nObjects, vs.startTime, vs.cameraView.cameraType.frameRate, args.minUserDuration, aggFunctions)) for vs in videoSequences]
+        jobs = [pool.apply_async(processing.extractVideoSequenceSpeeds, args = (str(parentPath/vs.getDatabaseFilename()), vs.cameraView.site.name, args.nObjects, vs.startTime, vs.cameraView.cameraType.frameRate, args.minUserDuration, args.aggMethods, args.aggCentiles)) for vs in videoSequences]
         for job in jobs:
             data.extend(job.get())
         pool.close()
--- a/trafficintelligence/processing.py	Mon Jul 16 01:14:37 2018 -0400
+++ b/trafficintelligence/processing.py	Mon Jul 16 01:24:26 2018 -0400
@@ -18,12 +18,13 @@
             objectsNotInZone.append(o)
     return speeds, objectsNotInZone
 
-def extractVideoSequenceSpeeds(dbFilename, siteName, nObjects, startTime, frameRate, minUserDurationSeconds, aggFunctions):
+def extractVideoSequenceSpeeds(dbFilename, siteName, nObjects, startTime, frameRate, minUserDurationSeconds, aggMethods, aggCentiles):
     data = []
     d = startTime.date()
     t1 = startTime.time()
     minUserDuration = minUserDurationSeconds*frameRate
     print('Extracting speed from '+dbFilename)
+    aggFunctions, tmpheaders = utils.aggregationMethods(aggMethods, aggCentiles)
     objects = storage.loadTrajectoriesFromSqlite(dbFilename, 'object', nObjects)
     for o in objects:
         if o.length() > minUserDuration:
@@ -32,7 +33,7 @@
             for method,func in aggFunctions.items():
                 aggSpeeds = frameRate*3.6*func(tmp)
                 if method == 'centile':
-                    row += aggSpeeds.tolist()
+                    row.extend(aggSpeeds.tolist())
                 else:
                     row.append(aggSpeeds)
         data.append(row)