scripts: csv.py: Tweaked --list-computed to infer all input field types
On one hand, only inferring the used input fields is conceptually
correct because that's how csv.py works. On the other, it doesn't really
make sense for --list-computed to show _less_ information than
--list-fields.
So, showing all inferred types now:
$ ./scripts/csv.py --list-computed test.csv \
-bcase='%(case)s+%(m)s' \
-fsimtime='float(bench_simtime)/1.0e9' \
-fsimthroughput='float(n)/max(float(bench_simtime)/1.0e9,1.0e-9)'
i int .--> case ? ?
suite ? |.-> simtime int sum
case ? -+|.> simthroughput int sum
SKIP_WARMUP int |||
FILE_SIZE int |||
SEED int |||
...
m ? -'||
n int ---+
bench_reads int ||
bench_progs int ||
bench_erases int ||
bench_readed int ||
bench_progged int ||
bench_erased int ||
bench_simtime int ---'
I think this makes --list-computed a strict superset of --list-fields
now.
This commit is contained in:
+29
-6
@@ -2391,11 +2391,34 @@ def list_fields(csv_paths, **args):
|
||||
for k, t in zip(fields_, types__):
|
||||
print('%-*s %s' % (w[0], k, t))
|
||||
|
||||
def list_computed(Result, **args):
|
||||
# figure out input fields and types, these are stashed in the
|
||||
# compiled Result type for this sort of introspection
|
||||
fields_ = Result._fields_
|
||||
types_ = Result._types_
|
||||
def list_computed(fields_, results, Result, **args):
|
||||
# find best type for fields, note this matches compile behavior
|
||||
types_ = {}
|
||||
for k in fields_:
|
||||
try:
|
||||
for t in [CsvInt, CsvFloat, CsvFrac]:
|
||||
for r in results:
|
||||
if k in r and r[k].strip():
|
||||
try:
|
||||
t(r[k])
|
||||
except ValueError:
|
||||
break
|
||||
else:
|
||||
types_[k] = t
|
||||
break
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
# find best name for types
|
||||
types__ = []
|
||||
for k in fields_:
|
||||
if k in types_:
|
||||
t = types_[k].__name__
|
||||
if t.startswith('Csv'):
|
||||
t = t[len('Csv'):]
|
||||
types__.append(t.lower())
|
||||
else:
|
||||
types__.append('?')
|
||||
|
||||
# find best name for types
|
||||
types__ = []
|
||||
@@ -2699,7 +2722,7 @@ def main(csv_paths, *,
|
||||
|
||||
# list computed?
|
||||
if args.get('list_computed'):
|
||||
return list_computed(Result, **args)
|
||||
return list_computed(fields_, results, Result, **args)
|
||||
|
||||
# homogenize
|
||||
results = homogenize(Result, results,
|
||||
|
||||
Reference in New Issue
Block a user