]> git.parisson.com Git - timeside.git/commitdiff
timeside/analyzer/core.py: add to_json() to AnalyzerResult
authorPaul Brossier <piem@piem.org>
Tue, 16 Apr 2013 00:03:57 +0000 (19:03 -0500)
committerPaul Brossier <piem@piem.org>
Tue, 16 Apr 2013 00:03:57 +0000 (19:03 -0500)
timeside/analyzer/core.py

index 13479a44f21ae9335402672462ea8fd585c690c0..99ac45a4acbc3b2f8769388efb35b0de198ec83c 100644 (file)
@@ -70,6 +70,13 @@ class AnalyzerResult(dict):
             return self[name]
         return super(AnalyzerResult, self).__getattr__(name)
 
+    def to_json(self):
+        import simplejson as json
+        data_dict = {}
+        for a in ['name', 'id', 'unit', 'value']:
+            data_dict[a] = self[a]
+        return json.dumps(data_dict)
+
 class AnalyzerResultContainer(object):
 
     def __init__(self, analyzer_results = []):