Mercurial Hosting > traffic-intelligence
comparison scripts/process.py @ 1064:cbc026dacf0b
changed interval string representation
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Sun, 15 Jul 2018 22:52:26 -0400 |
parents | 3c37d8d20e97 |
children | d4d052a05337 |
comparison
equal
deleted
inserted
replaced
1063:3c37d8d20e97 | 1064:cbc026dacf0b |
---|---|
14 from trafficintelligence.metadata import * | 14 from trafficintelligence.metadata import * |
15 | 15 |
16 parser = argparse.ArgumentParser(description='This program manages the processing of several files based on a description of the sites and video data in an SQLite database following the metadata module.') | 16 parser = argparse.ArgumentParser(description='This program manages the processing of several files based on a description of the sites and video data in an SQLite database following the metadata module.') |
17 # input | 17 # input |
18 parser.add_argument('--db', dest = 'metadataFilename', help = 'name of the metadata file', required = True) | 18 parser.add_argument('--db', dest = 'metadataFilename', help = 'name of the metadata file', required = True) |
19 parser.add_argument('--videos', dest = 'videoIds', help = 'indices of the video sequences', nargs = '*', type = int) | 19 parser.add_argument('--videos', dest = 'videoIds', help = 'indices of the video sequences', nargs = '*') |
20 parser.add_argument('--sites', dest = 'siteIds', help = 'indices of the video sequences', nargs = '*') | 20 parser.add_argument('--sites', dest = 'siteIds', help = 'indices of the video sequences', nargs = '*') |
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']) |
82 session = connectDatabase(args.metadataFilename) | 82 session = connectDatabase(args.metadataFilename) |
83 parentPath = Path(args.metadataFilename).parent # files are relative to metadata location | 83 parentPath = Path(args.metadataFilename).parent # files are relative to metadata location |
84 videoSequences = [] | 84 videoSequences = [] |
85 sites = [] | 85 sites = [] |
86 if args.videoIds is not None: | 86 if args.videoIds is not None: |
87 videoSequences = [session.query(VideoSequence).get(videoId) for videoId in args.videoIds] | 87 for videoId in args.videoIds: |
88 siteIds = set([vs.cameraView.siteIdx for vs in videoSequences]) | 88 if '-' in videoId: |
89 videoSequences.extend([session.query(VideoSequence).get(i) for i in moving.TimeInterval.parse(videoId)]) | |
90 else: | |
91 videoSequences.append(session.query(VideoSequence).get(int(videoId))) | |
92 sites = set([vs.cameraView.site for vs in videoSequences]) | |
89 elif args.siteIds is not None: | 93 elif args.siteIds is not None: |
90 siteIds = set(args.siteIds) | 94 for siteId in args.siteIds: |
91 for siteId in siteIds: | 95 if '-' in siteId: |
92 tmpsites = getSite(session, siteId) | 96 sites.extend([session.query(Site).get(i) for i in moving.TimeInterval.parse(siteId)]) |
93 sites.extend(tmpsites) | 97 else: |
94 for site in tmpsites: | 98 sites.append(session.query(Site).get(int(siteId))) |
95 videoSequences.extend(getSiteVideoSequences(site)) | 99 for site in sites: |
100 videoSequences.extend(getSiteVideoSequences(site)) | |
96 else: | 101 else: |
97 print('No video/site to process') | 102 print('No video/site to process') |
98 | 103 sys.exit() |
99 if args.nProcesses > 1: | 104 if args.nProcesses > 1: |
100 pool = Pool(args.nProcesses) | 105 pool = Pool(args.nProcesses) |
101 | 106 |
102 ################################# | 107 ################################# |
103 # Delete | 108 # Report progress in the processing |
104 ################################# | 109 ################################# |
105 if args.progress: | 110 if args.progress: |
106 print('Providing information on data progress') | 111 print('Providing information on data progress') |
107 print('TODO') | |
108 | 112 |
109 ################################# | 113 ################################# |
110 # Delete | 114 # Delete |
111 ################################# | 115 ################################# |
112 if args.delete is not None: | 116 if args.delete is not None: |
243 data.append(row) | 247 data.append(row) |
244 data = pd.DataFrame(data, columns = headers) | 248 data = pd.DataFrame(data, columns = headers) |
245 if args.output == 'figure': | 249 if args.output == 'figure': |
246 for name in headers[4:]: | 250 for name in headers[4:]: |
247 plt.ioff() | 251 plt.ioff() |
248 plt.figure() | 252 plt.figure() # siteids does not exist |
249 plt.boxplot([data.loc[data['sites']==siteId, name] for siteId in siteIds], labels = [session.query(Site).get(siteId).name for siteId in siteIds]) | 253 plt.boxplot([data.loc[data['site']==site.name, name] for site in sites], labels = [site.name for site in sites]) |
250 plt.ylabel(name+' Speeds (km/h)') | 254 plt.ylabel(name+' Speeds (km/h)') |
251 plt.savefig(name.lower()+'-speeds.png', dpi=dpi) | 255 plt.savefig(name.lower()+'-speeds.png', dpi=dpi) |
252 plt.close() | 256 plt.close() |
253 elif args.output == 'event': | 257 elif args.output == 'event': |
254 data.to_csv(args.eventFilename, index = False) | 258 data.to_csv(args.eventFilename, index = False) |