diff scripts/process.py @ 1058:16575ca4537d

work in progress
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 10 Jul 2018 17:16:38 -0400
parents 9d4a06f49cb8
children a87b3072bd26
line wrap: on
line diff
--- a/scripts/process.py	Mon Jul 09 16:21:03 2018 -0400
+++ b/scripts/process.py	Tue Jul 10 17:16:38 2018 -0400
@@ -23,7 +23,7 @@
 parser.add_argument('--delete', dest = 'delete', help = 'data to delete', choices = ['feature', 'object', 'classification', 'interaction'])
 parser.add_argument('--process', dest = 'process', help = 'data to process', choices = ['feature', 'object', 'classification', 'prototype', 'interaction'])
 parser.add_argument('--display', dest = 'display', help = 'data to display (replay over video)', choices = ['feature', 'object', 'classification', 'interaction'])
-parser.add_argument('--analyze', dest = 'analyze', help = 'data to analyze (results)', choices = ['feature', 'object', 'classification', 'interaction'])
+parser.add_argument('--analyze', dest = 'analyze', help = 'data to analyze (results)', choices = ['feature', 'object', 'classification', 'interaction', 'event'])
 
 # common options
 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file')
@@ -61,8 +61,9 @@
 parser.add_argument('--output', dest = 'output', help = 'kind of output to produce (interval means)', choices = ['figure', 'interval', 'event'])
 parser.add_argument('--min-user-duration', dest = 'minUserDuration', help = 'mininum duration we have to see the user to take into account in the analysis (s)', type = float, default = 0.1)
 parser.add_argument('--interval-duration', dest = 'intervalDuration', help = 'length of time interval to aggregate data (min)', type = float, default = 15.)
-parser.add_argument('--aggregation', dest = 'aggMethod', help = 'aggregation method per user/interaction and per interval', choices = ['mean', 'median', 'centile'], nargs = '*', default = ['median'])
+parser.add_argument('--aggregation', dest = 'aggMethods', help = 'aggregation method per user/interaction and per interval', choices = ['mean', 'median', 'centile'], nargs = '*', default = ['median'])
 parser.add_argument('--aggregation-centile', dest = 'aggCentiles', help = 'centile(s) to compute from the observations', nargs = '*', type = int)
+parser.add_argument('--event-filename', dest = 'eventFilename', help = 'filename of the event data')
 dpi = 150
 # unit of analysis: site - camera-view
 
@@ -213,15 +214,8 @@
     # aggregation per site
     data = [] # list of observation per site-user with time
     headers = ['sites', 'date', 'time', 'user_type']
-    aggFunctions = {}
-    for method in args.aggMethod:
-        if method == 'centile':
-            aggFunctions[method] = utils.aggregationFunction(method, args.aggCentiles)
-            for c in args.aggCentiles:
-                headers.append('{}{}'.format(method,c))
-        else:
-            aggFunctions[method] = utils.aggregationFunction(method)
-            headers.append(method)
+    aggFunctions, tmpheaders = utils.aggregationMethods(arg.aggMethods, args.aggCentiles)
+    headers.extend(tmpheaders)
     for vs in videoSequences:
         d = vs.startTime.date()
         t1 = vs.startTime.time()
@@ -281,3 +275,11 @@
         plt.ylabel(events.Interaction.indicatorNames[i]+' ('+events.Interaction.indicatorUnits[i]+')')
         plt.savefig(events.Interaction.indicatorNames[i]+'.png', dpi=150)
         plt.close()
+
+if args.analyze == 'event': # aggregate event data by 15 min interval (arg.intervalDuration)
+    data = pd.read_csv(arg.eventFilename)
+    # create time for end of each 15 min, then group by, using the agg method for each data column
+    headers = ['sites', 'date', 'intervalend15']
+    # add n road users (by type?)
+    aggFunctions, tmpheaders = utils.aggregationMethods(arg.aggMethods, args.aggCentiles)
+    headers.extend(tmpheaders)