diff options
Diffstat (limited to 'plot_exps.py')
| -rwxr-xr-x | plot_exps.py | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/plot_exps.py b/plot_exps.py index 76e7396..15c54d0 100755 --- a/plot_exps.py +++ b/plot_exps.py | |||
| @@ -6,7 +6,9 @@ import os | |||
| 6 | import shutil as sh | 6 | import shutil as sh |
| 7 | import sys | 7 | import sys |
| 8 | import traceback | 8 | import traceback |
| 9 | |||
| 9 | from collections import namedtuple | 10 | from collections import namedtuple |
| 11 | from config.config import DEFAULTS | ||
| 10 | from multiprocessing import Pool, cpu_count | 12 | from multiprocessing import Pool, cpu_count |
| 11 | from optparse import OptionParser | 13 | from optparse import OptionParser |
| 12 | from parse.col_map import ColMap,ColMapBuilder | 14 | from parse.col_map import ColMap,ColMapBuilder |
| @@ -17,7 +19,8 @@ def parse_args(): | |||
| 17 | parser = OptionParser("usage: %prog [options] [csv_dir]...") | 19 | parser = OptionParser("usage: %prog [options] [csv_dir]...") |
| 18 | 20 | ||
| 19 | parser.add_option('-o', '--out-dir', dest='out_dir', | 21 | parser.add_option('-o', '--out-dir', dest='out_dir', |
| 20 | help='directory for plot output', default='plot-data') | 22 | help='directory for plot output', |
| 23 | default=DEFAULTS['out-plot']) | ||
| 21 | parser.add_option('-f', '--force', action='store_true', default=False, | 24 | parser.add_option('-f', '--force', action='store_true', default=False, |
| 22 | dest='force', help='overwrite existing data') | 25 | dest='force', help='overwrite existing data') |
| 23 | parser.add_option('-p', '--processors', default=max(cpu_count() - 1, 1), | 26 | parser.add_option('-p', '--processors', default=max(cpu_count() - 1, 1), |
| @@ -139,21 +142,31 @@ def plot_dir(data_dir, out_dir, max_procs, force): | |||
| 139 | 142 | ||
| 140 | sys.stderr.write('\n') | 143 | sys.stderr.write('\n') |
| 141 | 144 | ||
| 145 | def get_dirs(args): | ||
| 146 | if args: | ||
| 147 | return args | ||
| 148 | elif os.path.exists(DEFAULTS['out-parse']): | ||
| 149 | return [DEFAULTS['out-parse']] | ||
| 150 | else: | ||
| 151 | return os.getcwd() | ||
| 152 | |||
| 142 | def main(): | 153 | def main(): |
| 143 | opts, args = parse_args() | 154 | opts, args = parse_args() |
| 144 | args = args or [os.getcwd()] | 155 | dirs = get_dirs(args) |
| 145 | 156 | ||
| 146 | if opts.force and os.path.exists(opts.out_dir): | 157 | if opts.force and os.path.exists(opts.out_dir): |
| 147 | sh.rmtree(opts.out_dir) | 158 | sh.rmtree(opts.out_dir) |
| 148 | if not os.path.exists(opts.out_dir): | 159 | if not os.path.exists(opts.out_dir): |
| 149 | os.mkdir(opts.out_dir) | 160 | os.mkdir(opts.out_dir) |
| 150 | 161 | ||
| 151 | for dir in args: | 162 | for dir in dirs: |
| 152 | if len(args) > 1: | 163 | if len(dirs) > 1: |
| 153 | out_dir = "%s/%s" % (opts.out_dir, os.path.split(dir)[1]) | 164 | out_dir = "%s/%s" % (opts.out_dir, os.path.split(dir)[1]) |
| 154 | else: | 165 | else: |
| 155 | out_dir = opts.out_dir | 166 | out_dir = opts.out_dir |
| 156 | plot_dir(dir, out_dir, opts.processors, opts.force) | 167 | plot_dir(dir, out_dir, opts.processors, opts.force) |
| 157 | 168 | ||
| 169 | sys.stderr.write("Plots saved in %s.\n" % opts.out_dir) | ||
| 170 | |||
| 158 | if __name__ == '__main__': | 171 | if __name__ == '__main__': |
| 159 | main() | 172 | main() |
