From 2e804f8fa7d26755088e47357f8de6feb6dbe292 Mon Sep 17 00:00:00 2001 From: Jonathan Herman Date: Mon, 29 Oct 2012 21:48:23 -0400 Subject: Added option to output parsed data as a python-parseable map. --- parse/tuple_table.py | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'parse/tuple_table.py') diff --git a/parse/tuple_table.py b/parse/tuple_table.py index 434eb22..465abb3 100644 --- a/parse/tuple_table.py +++ b/parse/tuple_table.py @@ -1,7 +1,9 @@ from collections import defaultdict -from point import SummaryPoint +from point import SummaryPoint,Type from dir_map import DirMap +from pprint import pprint + class ColMap(object): def __init__(self): self.rev_map = {} @@ -31,13 +33,16 @@ class ColMap(object): map[self.col_list[i]] = tuple[i] return map + def force_add(self, column): + self.rev_map[column] = len(self.col_list) + self.col_list += [column] + def try_add(self, column, value): if column not in self.rev_map: if column not in self.value_map: self.value_map[column] = value elif value != self.value_map[column]: - self.rev_map[column] = len(self.col_list) - self.col_list += [column] + self.force_add(column) def __str__(self): return "%s" % (self.rev_map) @@ -53,6 +58,9 @@ class TupleTable(object): key = self.col_map.get_key(kv) self.table[key] += [point] + def col_map(self): + return self.col_map + def get_exps(self, kv): key = self.col_map.get_key(kv) return self.table[key] @@ -66,9 +74,32 @@ class TupleTable(object): raise Exception("cannot reduce twice!") self.reduced = True for key, values in self.table.iteritems(): - self.table[key] = SummaryPoint(str(key), values) + self.table[key] = SummaryPoint(values[0].id, values) - def write_result(self, out_dir): + def write_map(self, out_map): + if not self.reduced: + raise Exception("must reduce table to write map!") + + rows = {} + + for key, point in self.table.iteritems(): + row = {} + for name,measurement in point: + name = name.lower().replace('_','-') + row[name]={} + for base_type in Type: + type_key = str(base_type).lower() + if base_type in measurement[Type.Avg]: + value = measurement[Type.Avg][base_type] + row[name][type_key] = value + rows[key] = row + + result = {'columns': self.col_map.columns(), 'rows':rows} + + with open(out_map, 'wc') as map_file: + pprint(result,stream=map_file, width=20) + + def write_csvs(self, out_dir): dir_map = DirMap(out_dir) for key, point in self.table.iteritems(): -- cgit v1.2.2