tvaLib
Functions | Variables
reportcompiler Namespace Reference

Functions

def main ()
 main() More...
 

Variables

string version = 'R2.3.0 u. 2017-03-22'
 

Function Documentation

◆ main()

def reportcompiler.main ( )

main()

Definition at line 15 of file reportcompiler.py.

15 def main():
16  try:
17 
18 
22  import os, logging, subprocess, time
23  from site import addsitedir
24  #Add parent library
25  if(os.path.isfile(os.path.join(os.getcwd(), os.pardir, 'main.py'))):
26  addsitedir(os.path.join(os.getcwd(), os.pardir))
27  os.chdir(os.path.join(os.getcwd(), os.pardir))
28 
29  import include.config as tvaConfig
30  import include.local as tvaLocal
31 
32 
33 
36  commands = tvaConfig.commands()
37  config = tvaConfig.Config()
38  if(config.debug): logging.basicConfig(level=logging.DEBUG, format='[%(levelname)s] (%(threadName)-10s) %(message)s')
39 
40 
43  try: #Colorama, optional, required for Windows if coloured text is desired
44  from colorama import init as colorama_init
45  colorama_init(strip=False)
46  from colorama import Fore, Back, Style
47  except ImportError:
48  Fore = tvaConfig.Fore()
49  Back = tvaConfig.Back()
50  Style = tvaConfig.Style()
51  if(commands.logging or config.disable_colour):
52  config.disable_colour = True
53  Fore = tvaConfig.Fore(forceOff=True)
54  Back = tvaConfig.Back(forceOff=True)
55  Style = tvaConfig.Style(forceOff=True)
56 
57  import lib.hli_cg as tvaHLI
58  import lib.scene as tvaScene
59  import lib.tools as tvaLib
60  import include.runtime as tvaRuntime
61 
62 
65  if(commands.dir): config.dir = commands.dir
66  if(commands.dbn): config.dbn = commands.dbn
67  if(commands.language): config.language = commands.language
68  local = tvaLocal.Local(config.language)
69  #Override module colour options
70  tvaLib.Fore = Fore;tvaLib.Back = Back;tvaLib.Style = Style
71 
72  sites = tvaScene.Sites(config)
73  site_analyses = tvaScene.SiteAnalyses(config, sites=sites)
74  report_name = 'compiled_report'
75  move_source = True
76  report_source_files = [os.path.join(tvaHLI.hli_results_folder, 'report.tex'),
77  os.path.join(tvaHLI.hli_results_folder, 'Gap acceptance CDF.pdf'),
78  os.path.join(tvaHLI.hli_results_folder, 'Speed profiles.pdf'),
79  os.path.join(tvaHLI.hli_results_folder, 'Speed Boxplots.pdf'),
80  os.path.join('Vehicle Trajectories (Satellite).jpg'),
81  os.path.join('Speed Vector Map.pdf'),
82  os.path.join('TTC cdf_Curvilinear Motion Pattern.pdf'),
83  os.path.join('CP Map TTC lt 1.5s_Curvilinear Motion Pattern.pdf')
84  ]
85  config.version = tvaLib.Parse.versionFromHgCommit(version)
86  print('Running report compiler, version '+config.version+'.')
87 
88 
92  markup = r'''\documentclass[a4paper]{article}
93 \usepackage{pdfpages}
94 \begin{document}
95 '''
96 
97 
98  if(commands.interactive): commands = tvaRuntime.interactiveSiteAnalysisSelection(commands, config, site_analyses, sites, local)
99  saIxs = site_analyses.interpret(commands.s_analysis)
100  if(commands.verbose == 1): prog = tvaLib.ProgressBar(0, len(saIxs), 77)
101  for saIx in saIxs:
102  if(commands.verbose == 1): prog.updateAmount(saIx)
103  elif(commands.verbose >= 2): print site_analyses[saIx].name
104 
108  if(os.path.exists(os.path.join(site_analyses[saIx].getFullResultsFolder(config.output_folder, customSubPath=tvaHLI.hli_results_folder), 'report.pdf'))):
109  markup += r'\includepdf[pages=-, scale=1.0]{'+os.path.join(site_analyses[saIx].getFullResultsFolder(config.output_folder, customSubPath=tvaHLI.hli_results_folder), 'report.pdf').replace('\\', '/')+'}\n'
110  if(move_source and os.path.exists(os.path.join(site_analyses[saIx].getFullResultsFolder(config.output_folder, customSubPath=tvaHLI.hli_results_folder), 'report.tex'))):
111  for source_file in report_source_files:
112  try: print(os.path.join(site_analyses[saIx].getFullResultsFolder(), source_file))#shutil.copyfile()
113  except: pass
114 
115 
118  markup += r'\end{document}'
119  print markup
120 
121  with open(os.path.join(config.dir, report_name+'.tex'),'w') as f:
122  f.write(markup)
123 
124 
125  cwd = os.getcwd()
126  os.chdir(config.dir)
127  if(commands.verbose <=2):
128  FNULL = open(os.devnull, 'w')
129  subprocess.call(['pdflatex', '-interaction', 'nonstopmode', report_name+'.tex'], stdout=FNULL, stderr=subprocess.STDOUT)
130  else:
131  subprocess.call(['pdflatex', '-interaction', 'nonstopmode', report_name+'.tex'])
132  os.chdir(cwd)
133 
134 
135  if(os.path.isfile(os.path.join(config.dir, report_name+'.tex'))): os.unlink(os.path.join(config.dir, report_name+'.tex'))
136  if(os.path.isfile(os.path.join(config.dir, report_name+'.log'))): os.unlink(os.path.join(config.dir, report_name+'.log'))
137  if(os.path.isfile(os.path.join(config.dir, report_name+'.aux'))): os.unlink(os.path.join(config.dir, report_name+'.aux'))
138 
139  raise Exception, [0003, 'Batch processing complete.']
140 
141 
142 
146  except KeyboardInterrupt:
147  if(commands.verbose): print(Back.GREEN+'==User exited== [0000]'+Back.RESET+'\nRuntime: {0}'.format(round(time.clock())))
148 
149  except SystemExit, e:
150  try:
151  if(commands.verbose): print(Back.GREEN+'==Execution finished== [0001]'+Back.RESET+'\nRuntime: {0}'.format(round(time.clock())))
152  except UnboundLocalError: pass
153 
154  except Exception, e:
155  if('commands' in dir()): verbose = commands.verbose
156  else: verbose = 1
157  if('config' in dir()): debug = config.debug
158  else: debug = True
159  from include.runtime import debug as tvaRuntime_debug
160  tvaRuntime_debug(e, time, logging=logging, verbose=verbose, force=debug)
161 
def main()
main()

Variable Documentation

◆ version

string reportcompiler.version = 'R2.3.0 u. 2017-03-22'

Definition at line 5 of file reportcompiler.py.