tvaLib
pool-sa-results.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # tvaLib Copyright (c) 2012-2016 Paul G. St-Aubin
3 # Ecole Polytechnique de Montreal, McGill University
4 # Python 2.7; (dt) Spyder Windows 10 64-bit; ipython Ubuntu 15.04 64-bit
5 version = 'R2.3.0 u. 2017-03-22'
6 
7 ''' Dev stuff
8 Pool output of specific files into one common folder for quick inspection
9 
10 targetFile = r'roundaboutHLI/Speed profiles.png'
11 '''
12 
13 
14 
17 def main():
18  try:
19 
20 
24  import os, logging, time
25  from site import addsitedir
26  from time import clock
27  from shutil import copy as shutil_copy
28  #Add parent library
29  if(os.path.isfile(os.path.join(os.getcwd(), os.pardir, 'main.py'))):
30  addsitedir(os.path.join(os.getcwd(), os.pardir))
31  os.chdir(os.path.join(os.getcwd(), os.pardir))
32 
33  import include.config as tvaConfig
34  import include.local as tvaLocal
35 
36 
39  commands = tvaConfig.commands()
40  config = tvaConfig.Config(readonly=False) #Set this to true if the script is running independantly of the main program
41 
42 
43 
46  try: #Colorama, optional, required for Windows if coloured text is desired
47  from colorama import init as colorama_init
48  colorama_init(strip=False)
49  from colorama import Fore, Back, Style
50  except ImportError:
51  Fore = tvaConfig.Fore()
52  Back = tvaConfig.Back()
53  Style = tvaConfig.Style()
54  if(commands.logging or config.disable_colour):
55  config.disable_colour = True
56  Fore = tvaConfig.Fore(forceOff=True)
57  Back = tvaConfig.Back(forceOff=True)
58  Style = tvaConfig.Style(forceOff=True)
59 
60  import lib.scene as tvaScene
61  import lib.tools as tvaLib
62  import include.runtime as tvaRuntime
63 
64 
67  if(config.debug): logging.basicConfig(level=logging.DEBUG, format='[%(levelname)s] (%(threadName)-10s) %(message)s')
68  if(commands.dir): config.dir = commands.dir
69  if(commands.dbn): config.dbn = commands.dbn
70  if(commands.language): config.language = commands.language
71  local = tvaLocal.Local(config.language)
72  sites = tvaScene.Sites(config)
73  site_analyses = tvaScene.SiteAnalyses(config, sites=sites)
74  analyses = tvaScene.Analyses(config)
75  summaryFolderPrefix = 'POOL'
76  summaryFolder = summaryFolderPrefix+'_'+commands.opt1.split('.')[0].replace('/','_').replace('\\','_').replace(' ','_')
77  ext = os.path.splitext(commands.opt1)[1]
78 
79 
80 
83  print('Running results pooling worker, version '+version+'.')
84  if(not os.path.exists(os.path.join(config.dir, config.output_folder, summaryFolder))):
85  os.mkdir(os.path.join(config.dir, config.output_folder, summaryFolder))
86 
87 
88 
92  saIxs = site_analyses.interpret(commands.s_analysis)
93  if(commands.verbose == 1): prog = tvaLib.ProgressBar(0, len(saIxs), 77)
94  for saIx in saIxs:
95  if(commands.verbose == 1): prog.updateAmount(saIx)
96  elif(commands.verbose >= 2): print site_analyses[saIx].name
97 
98  if(os.path.exists(os.path.join(site_analyses[saIx].getFullResultsFolder(), commands.opt1))):
99  shutil_copy(os.path.join(site_analyses[saIx].getFullResultsFolder(), commands.opt1), os.path.join(config.dir, config.output_folder, summaryFolder, str(site_analyses[saIx].idx)+'_'+tvaLib.Parse.clean_file_name(site_analyses[saIx].name)+ext))
100 
101 
102 
103 
106 
107  raise Exception, [0003, 'Results pooling complete.']
108 
109 
110 
114  except KeyboardInterrupt:
115  if(commands.verbose): print(Back.GREEN+'==User exited== [0000]'+Back.RESET+'\nRuntime: {0}'.format(round(clock())))
116 
117  except SystemExit, e:
118  try:
119  if(commands.verbose): print(Back.GREEN+'==Execution finished== [0001'+Back.RESET+'\nRuntime: {0}'.format(round(clock())))
120  except UnboundLocalError: pass
121 
122  except Exception, e:
123  if('commands' in dir()): verbose = commands.verbose
124  else: verbose = 1
125  if('config' in dir()): debug = config.debug
126  else: debug = True
127  from include.runtime import debug as tvaRuntime_debug
128  tvaRuntime_debug(e, time, logging=logging, verbose=verbose, force=debug)
129 
130 
133 if __name__ == '__main__':
134  main()
def main()
main()
Definition: main.py:1