diff options
| author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-02-08 16:20:01 -0500 |
|---|---|---|
| committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-02-08 16:20:01 -0500 |
| commit | 7c647198fc40e72ef6ca23c2484bf49eba2079ee (patch) | |
| tree | 270de30a1cd896382a0954b2d8f7994ca84f88b7 /parse/point.py | |
| parent | d312e270ed5c2926c8651291a4026062213876f8 (diff) | |
Added translation from DirMap to ReducedTupleTable.
Diffstat (limited to 'parse/point.py')
| -rw-r--r-- | parse/point.py | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/parse/point.py b/parse/point.py index 8e27869..ce9cfb0 100644 --- a/parse/point.py +++ b/parse/point.py | |||
| @@ -26,9 +26,9 @@ def dict_str(adict, sep = "\n"): | |||
| 26 | return sep.join([("%" + str(size) + "s: %9s") % (k, num_str(v)) for (k,v) in sorted(adict.iteritems())]) | 26 | return sep.join([("%" + str(size) + "s: %9s") % (k, num_str(v)) for (k,v) in sorted(adict.iteritems())]) |
| 27 | 27 | ||
| 28 | class Measurement(object): | 28 | class Measurement(object): |
| 29 | def __init__(self, id = None, kv = {}): | 29 | def __init__(self, id = None, kv = {}, default=list): |
| 30 | self.id = id | 30 | self.id = id |
| 31 | self.stats = {} | 31 | self.stats = defaultdict(default) |
| 32 | for k, v in kv.iteritems(): | 32 | for k, v in kv.iteritems(): |
| 33 | self[k] = v | 33 | self[k] = v |
| 34 | 34 | ||
| @@ -55,20 +55,24 @@ class Measurement(object): | |||
| 55 | self.__check_type(type) | 55 | self.__check_type(type) |
| 56 | return type in self.stats | 56 | return type in self.stats |
| 57 | 57 | ||
| 58 | def __setitem__(self, type, value): | 58 | def __setitem__(self, t, value): |
| 59 | self.__check_type(type) | 59 | self.__check_type(t) |
| 60 | self.stats[type] = value | 60 | # Numpy returns single memmapped values which can't be pickled |
| 61 | # Convert them to floats which can be | ||
| 62 | if type(value) is np.memmap: | ||
| 63 | value = float(value) | ||
| 64 | self.stats[t] = value | ||
| 61 | 65 | ||
| 62 | def __str__(self): | 66 | def __str__(self): |
| 63 | return "%s" % dict_str(self.stats, " ") | 67 | return "%s" % dict_str(self.stats, " ") |
| 64 | 68 | ||
| 65 | |||
| 66 | class Summary(Measurement): | 69 | class Summary(Measurement): |
| 67 | def __init__(self, id, measures, typemap = default_typemap): | 70 | def __init__(self, id="", measures=[], typemap = default_typemap): |
| 68 | super(Summary, self).__init__(id) | 71 | super(Summary, self).__init__(id, default=Measurement) |
| 69 | 72 | ||
| 70 | self.__check_types(measures, typemap) | 73 | if measures: |
| 71 | self.__summarize(measures, typemap) | 74 | self.__check_types(measures, typemap) |
| 75 | self.__summarize(measures, typemap) | ||
| 72 | 76 | ||
| 73 | def __check_types(self, measures, typemap): | 77 | def __check_types(self, measures, typemap): |
| 74 | required_types = self.__get_required(typemap) | 78 | required_types = self.__get_required(typemap) |
| @@ -100,8 +104,8 @@ class Summary(Measurement): | |||
| 100 | return required | 104 | return required |
| 101 | 105 | ||
| 102 | class ExpPoint(object): | 106 | class ExpPoint(object): |
| 103 | def __init__(self, id = "", init = {}): | 107 | def __init__(self, id = "", init = {}, default=Measurement): |
| 104 | self.stats = {} | 108 | self.stats = defaultdict(default) |
| 105 | for type, value in init.iteritems(): | 109 | for type, value in init.iteritems(): |
| 106 | self[type] = value | 110 | self[type] = value |
| 107 | self.id = id | 111 | self.id = id |
| @@ -124,14 +128,17 @@ class ExpPoint(object): | |||
| 124 | self.stats[type] = value | 128 | self.stats[type] = value |
| 125 | 129 | ||
| 126 | def __str__(self): | 130 | def __str__(self): |
| 127 | return "<ExpPoint-%s>\n%s" % (self.id, dict_str(self.stats)) | 131 | # return "<ExpPoint-%s>\n%s" % (self.id, dict_str(self.stats)) |
| 132 | return "<ExpPoint-%s>" % (self.id) | ||
| 128 | 133 | ||
| 129 | def get_stats(self): | 134 | def get_stats(self): |
| 130 | return self.stats.keys() | 135 | return self.stats.keys() |
| 131 | 136 | ||
| 137 | |||
| 132 | class SummaryPoint(ExpPoint): | 138 | class SummaryPoint(ExpPoint): |
| 133 | def __init__(self, id, points, typemap = default_typemap): | 139 | def __init__(self, id="", points=[], typemap = default_typemap): |
| 134 | super(SummaryPoint,self).__init__("Summary-%s" % id) | 140 | super(SummaryPoint,self).__init__("Summary-%s" % id, |
| 141 | default=Summary) | ||
| 135 | 142 | ||
| 136 | grouped = defaultdict(lambda : []) | 143 | grouped = defaultdict(lambda : []) |
| 137 | 144 | ||
