Mercurial Hosting > traffic-intelligence
diff scripts/process.py @ 1065:d4d052a05337
added progress report functionality
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 16 Jul 2018 00:05:17 -0400 |
parents | cbc026dacf0b |
children | 862b55a87e63 |
line wrap: on
line diff
--- a/scripts/process.py Sun Jul 15 22:52:26 2018 -0400 +++ b/scripts/process.py Mon Jul 16 00:05:17 2018 -0400 @@ -89,6 +89,7 @@ videoSequences.extend([session.query(VideoSequence).get(i) for i in moving.TimeInterval.parse(videoId)]) else: videoSequences.append(session.query(VideoSequence).get(int(videoId))) + videoSequences = [vs for vs in videoSequences if vs is not None] sites = set([vs.cameraView.site for vs in videoSequences]) elif args.siteIds is not None: for siteId in args.siteIds: @@ -96,11 +97,12 @@ sites.extend([session.query(Site).get(i) for i in moving.TimeInterval.parse(siteId)]) else: sites.append(session.query(Site).get(int(siteId))) + sites = [s for s in sites if s is not None] for site in sites: videoSequences.extend(getSiteVideoSequences(site)) else: print('No video/site to process') -sys.exit() + if args.nProcesses > 1: pool = Pool(args.nProcesses) @@ -109,6 +111,28 @@ ################################# if args.progress: print('Providing information on data progress') + headers = ['site', 'vs', 'features', 'objects', 'interactions'] # todo add prototypes and object classification + data = [] + for site in sites: + unprocessedVideoSequences = [] + for vs in getSiteVideoSequences(site): + if (parentPath/vs.getDatabaseFilename()).is_file(): + tableNames = storage.tableNames(str(parentPath.absolute()/vs.getDatabaseFilename())) + data.append([site.name, vs.idx, 'positions' in tableNames, 'objects' in tableNames, 'interactions' in tableNames]) + else: + unprocessedVideoSequences.append(vs) + data.append([site.name, vs.idx, False, False, False]) + #if len(unprocessedVideoSequences): + # print('Site {} ({}) has {} completely unprocessed video sequences'.format (site.name, site.idx, len(unprocessedVideoSequences))) + data = pd.DataFrame(data, columns = headers) + print('-'*80) + print('\t'+' '.join(headers[2:])) + print('-'*80) + for name, group in data.groupby(['site']): #.agg({'vs': 'count'})) + n = group.vs.count() + print('{}: {} % / {} % / {} % ({})'.format(name, 100*group.features.sum()/float(n), 100*group.objects.sum()/float(n), 100*group.interactions.sum()/float(n), n)) + print('-'*80) + print(data) ################################# # Delete @@ -131,7 +155,7 @@ if args.process in ['feature', 'object']: # tracking if args.nProcesses == 1: for vs in videoSequences: - if not (parentPath/vs.getDatabaseFilename()).exists() or args.process == 'object': + if not (parentPath/vs.getDatabaseFilename()).is_file() or args.process == 'object': if args.configFilename is None: configFilename = str(parentPath/vs.cameraView.getTrackingConfigurationFilename()) else: @@ -144,7 +168,7 @@ print('SQLite already exists: {}'.format(parentPath/vs.getDatabaseFilename())) else: for vs in videoSequences: - if not (parentPath/vs.getDatabaseFilename()).exists() or args.process == 'object': + if not (parentPath/vs.getDatabaseFilename()).is_file() or args.process == 'object': if args.configFilename is None: configFilename = str(parentPath/vs.cameraView.getTrackingConfigurationFilename()) else: