"""
apply runSeeds to a list of tests and compute statistics
use case: tweaking the lane change model and then seeing the result of a
gazillion tests with reduced noise
"""
import os
import sys
import glob
from subprocess import call
tests, prefix, apps = sys.argv[1:]
SEEDS = "0:100"
THREADS = "16"
EXTRACT = os.path.join(os.environ['SUMO_HOME'], 'tools', 'extractTest.py')
RUNSEEDS = os.path.join(os.environ['SUMO_HOME'], 'tools', 'runSeeds.py')
ASTATS = os.path.join(os.environ['SUMO_HOME'], 'tools', 'output', 'attributeStats.py')
ADIFF = os.path.join(os.environ['SUMO_HOME'], 'tools', 'output', 'attributeDiff.py')
applist = apps.split(',')
appdirs = [a + "_0" for a in applist]
tDirs = []
for test in open(tests).readlines()[1:]:
test = test.strip()
fullpath = os.path.join(prefix, test)
call([EXTRACT, fullpath])
tdir = '_' + test.replace('/', '_')
tDirs.append(tdir)
os.chdir(tdir)
rsargs = [RUNSEEDS,
'-k', 'test.sumocfg',
'-a', apps,
'--seeds', SEEDS,
'--threads', THREADS,
'--no-warnings',
'--statistic-output', 'stats.xml']
call(rsargs)
outf = open('compare.txt', 'w')
outf.close()
outf = open('compare.txt', 'a')
statFiles = []
for app, ad in zip(applist, appdirs):
files = glob.glob(os.path.join(ad, '*.stats.xml'))
sFile = '%s_allStats.xml' % app
statFiles.append(sFile)
args = [ASTATS, '-x', sFile, '-b', '0'] + files
call(args, stdout=outf)
outf.close()
call([ADIFF, '-o', 'statsDiff.xml'] + statFiles)
os.chdir('..')
differences = [os.path.join(d, 'statsDiff.xml') for d in tDirs]
args = [ASTATS, '-x', 'globalStats.xml', '-b', '0'] + differences
call(args)