Mercurial Hosting > traffic-intelligence
comparison 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 |
comparison
equal
deleted
inserted
replaced
1057:a7ada64b8214 | 1058:16575ca4537d |
---|---|
21 | 21 |
22 # main function | 22 # main function |
23 parser.add_argument('--delete', dest = 'delete', help = 'data to delete', choices = ['feature', 'object', 'classification', 'interaction']) | 23 parser.add_argument('--delete', dest = 'delete', help = 'data to delete', choices = ['feature', 'object', 'classification', 'interaction']) |
24 parser.add_argument('--process', dest = 'process', help = 'data to process', choices = ['feature', 'object', 'classification', 'prototype', 'interaction']) | 24 parser.add_argument('--process', dest = 'process', help = 'data to process', choices = ['feature', 'object', 'classification', 'prototype', 'interaction']) |
25 parser.add_argument('--display', dest = 'display', help = 'data to display (replay over video)', choices = ['feature', 'object', 'classification', 'interaction']) | 25 parser.add_argument('--display', dest = 'display', help = 'data to display (replay over video)', choices = ['feature', 'object', 'classification', 'interaction']) |
26 parser.add_argument('--analyze', dest = 'analyze', help = 'data to analyze (results)', choices = ['feature', 'object', 'classification', 'interaction']) | 26 parser.add_argument('--analyze', dest = 'analyze', help = 'data to analyze (results)', choices = ['feature', 'object', 'classification', 'interaction', 'event']) |
27 | 27 |
28 # common options | 28 # common options |
29 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file') | 29 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file') |
30 parser.add_argument('-n', dest = 'nObjects', help = 'number of objects/interactions to process', type = int) | 30 parser.add_argument('-n', dest = 'nObjects', help = 'number of objects/interactions to process', type = int) |
31 parser.add_argument('-t', dest = 'trajectoryType', help = 'type of trajectories', choices = ['feature', 'object'], default = 'feature') | 31 parser.add_argument('-t', dest = 'trajectoryType', help = 'type of trajectories', choices = ['feature', 'object'], default = 'feature') |
59 | 59 |
60 # analysis options | 60 # analysis options |
61 parser.add_argument('--output', dest = 'output', help = 'kind of output to produce (interval means)', choices = ['figure', 'interval', 'event']) | 61 parser.add_argument('--output', dest = 'output', help = 'kind of output to produce (interval means)', choices = ['figure', 'interval', 'event']) |
62 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) | 62 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) |
63 parser.add_argument('--interval-duration', dest = 'intervalDuration', help = 'length of time interval to aggregate data (min)', type = float, default = 15.) | 63 parser.add_argument('--interval-duration', dest = 'intervalDuration', help = 'length of time interval to aggregate data (min)', type = float, default = 15.) |
64 parser.add_argument('--aggregation', dest = 'aggMethod', help = 'aggregation method per user/interaction and per interval', choices = ['mean', 'median', 'centile'], nargs = '*', default = ['median']) | 64 parser.add_argument('--aggregation', dest = 'aggMethods', help = 'aggregation method per user/interaction and per interval', choices = ['mean', 'median', 'centile'], nargs = '*', default = ['median']) |
65 parser.add_argument('--aggregation-centile', dest = 'aggCentiles', help = 'centile(s) to compute from the observations', nargs = '*', type = int) | 65 parser.add_argument('--aggregation-centile', dest = 'aggCentiles', help = 'centile(s) to compute from the observations', nargs = '*', type = int) |
66 parser.add_argument('--event-filename', dest = 'eventFilename', help = 'filename of the event data') | |
66 dpi = 150 | 67 dpi = 150 |
67 # unit of analysis: site - camera-view | 68 # unit of analysis: site - camera-view |
68 | 69 |
69 # need way of selecting sites as similar as possible to sql alchemy syntax | 70 # need way of selecting sites as similar as possible to sql alchemy syntax |
70 # override tracking.cfg from db | 71 # override tracking.cfg from db |
211 if args.analyze == 'object': | 212 if args.analyze == 'object': |
212 # user speeds, accelerations | 213 # user speeds, accelerations |
213 # aggregation per site | 214 # aggregation per site |
214 data = [] # list of observation per site-user with time | 215 data = [] # list of observation per site-user with time |
215 headers = ['sites', 'date', 'time', 'user_type'] | 216 headers = ['sites', 'date', 'time', 'user_type'] |
216 aggFunctions = {} | 217 aggFunctions, tmpheaders = utils.aggregationMethods(arg.aggMethods, args.aggCentiles) |
217 for method in args.aggMethod: | 218 headers.extend(tmpheaders) |
218 if method == 'centile': | |
219 aggFunctions[method] = utils.aggregationFunction(method, args.aggCentiles) | |
220 for c in args.aggCentiles: | |
221 headers.append('{}{}'.format(method,c)) | |
222 else: | |
223 aggFunctions[method] = utils.aggregationFunction(method) | |
224 headers.append(method) | |
225 for vs in videoSequences: | 219 for vs in videoSequences: |
226 d = vs.startTime.date() | 220 d = vs.startTime.date() |
227 t1 = vs.startTime.time() | 221 t1 = vs.startTime.time() |
228 minUserDuration = args.minUserDuration*vs.cameraView.cameraType.frameRate | 222 minUserDuration = args.minUserDuration*vs.cameraView.cameraType.frameRate |
229 print('Extracting speed from '+vs.getDatabaseFilename()) | 223 print('Extracting speed from '+vs.getDatabaseFilename()) |
279 plt.figure() | 273 plt.figure() |
280 plt.boxplot(tmp, labels = [session.query(Site).get(siteId).name for siteId in indicators]) | 274 plt.boxplot(tmp, labels = [session.query(Site).get(siteId).name for siteId in indicators]) |
281 plt.ylabel(events.Interaction.indicatorNames[i]+' ('+events.Interaction.indicatorUnits[i]+')') | 275 plt.ylabel(events.Interaction.indicatorNames[i]+' ('+events.Interaction.indicatorUnits[i]+')') |
282 plt.savefig(events.Interaction.indicatorNames[i]+'.png', dpi=150) | 276 plt.savefig(events.Interaction.indicatorNames[i]+'.png', dpi=150) |
283 plt.close() | 277 plt.close() |
278 | |
279 if args.analyze == 'event': # aggregate event data by 15 min interval (arg.intervalDuration) | |
280 data = pd.read_csv(arg.eventFilename) | |
281 # create time for end of each 15 min, then group by, using the agg method for each data column | |
282 headers = ['sites', 'date', 'intervalend15'] | |
283 # add n road users (by type?) | |
284 aggFunctions, tmpheaders = utils.aggregationMethods(arg.aggMethods, args.aggCentiles) | |
285 headers.extend(tmpheaders) |