From: Guillaume Pellerin Date: Mon, 15 Apr 2013 13:51:36 +0000 (+0200) Subject: analyzer.results should return numpy arrays X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=refs%2Fheads%2Faubio-g;p=timeside.git analyzer.results should return numpy arrays --- diff --git a/timeside/analyzer/core.py b/timeside/analyzer/core.py index e43b28a..2c4bfa9 100644 --- a/timeside/analyzer/core.py +++ b/timeside/analyzer/core.py @@ -25,7 +25,7 @@ numpy_data_types = [ #'float128', 'float64', 'float32', - 'float16', + # 'float16', 'int64', 'int16', 'int32', @@ -56,7 +56,7 @@ class AnalyzerResult(dict): value = numpy.array(value) # serialize using numpy if type(value) in numpy_data_types: - value = value.tolist() + value = value if type(value) not in [list, str, int, long, float, complex, type(None)] + numpy_data_types: raise TypeError, 'AnalyzerResult can not accept type %s' % type(value) if name == 'value': self['value'] = value @@ -91,7 +91,7 @@ class AnalyzerResultContainer(object): node = doc.createElement('data') for a in ['name', 'id', 'unit']: node.setAttribute(a, str(data[a]) ) - node.setAttribute('value', repr(data['value']) ) + node.setAttribute('value', data['value'] ) root.appendChild(node) return xml.dom.minidom.Document.toprettyxml(doc) diff --git a/timeside/tools/cache.py b/timeside/tools/cache.py index 8decc97..18afd68 100644 --- a/timeside/tools/cache.py +++ b/timeside/tools/cache.py @@ -39,25 +39,27 @@ import os import xml.dom.minidom +from timeside.core import Processor, implements, interfacedoc + class Cache(object): - + def __init__(self, dir, params=None): self.dir = dir self.params = params self.files = self.get_files() - + def get_files(self): list = [] for root, dirs, files in os.walk(self.dir): for file in files: list.append(file) return list - + def exists(self, file): self.files = self.get_files() return file in self.files - + def write_bin(self, data, file): path = self.dir + os.sep + file f = open(path, 'w') @@ -70,7 +72,7 @@ class Cache(object): data = f.read() f.close() return data - + def read_stream_bin(self, file): path = self.dir + os.sep + file chunk_size = 0x1000 @@ -96,7 +98,7 @@ class Cache(object): value = data.getAttribute('value') list.append({'name': name, 'id': id, 'unit': unit, 'value': value}) return list - + def write_analyzer_xml(self, data_list, file): path = self.dir + os.sep + file doc = xml.dom.minidom.Document() @@ -116,3 +118,8 @@ class Cache(object): f = open(path, "w") f.write(xml.dom.minidom.Document.toprettyxml(doc)) f.close() + + +class Accumulator(Processor): + pass +