diff options
author | mbeierl <mark.beierl@emc.com> | 2015-10-07 19:18:19 -0700 |
---|---|---|
committer | Mark Beierl <mark.beierl@emc.com> | 2015-10-15 18:49:30 +0000 |
commit | 2313923abdffd35bb6644956355617999f1a5f06 (patch) | |
tree | 04becf56706909136ae3d9d193d822f0e9954baa /storperf/carbon | |
parent | 7792fc2fb6ff60abdb1b1bee3c0b6932e72a3c4d (diff) |
Created converters
JIRA: STORPERF-6
Change-Id: Idba1718a8ad8243872ca100ed10b1c457221d147
Signed-off-by: mbeierl <mark.beierl@emc.com>
Diffstat (limited to 'storperf/carbon')
-rw-r--r-- | storperf/carbon/__init__.py | 0 | ||||
-rw-r--r-- | storperf/carbon/converter.py | 45 |
2 files changed, 45 insertions, 0 deletions
diff --git a/storperf/carbon/__init__.py b/storperf/carbon/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/storperf/carbon/__init__.py diff --git a/storperf/carbon/converter.py b/storperf/carbon/converter.py new file mode 100644 index 0000000..4ad5be2 --- /dev/null +++ b/storperf/carbon/converter.py @@ -0,0 +1,45 @@ +############################################################################## +# Copyright (c) 2015 EMC and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +class JSONToCarbon(object): + def __init__(self): + pass + + def convert_to_dictionary(self, json_object, prefix=None): + self.timestamp = str(json_object['timestamp']) + self.flat_dictionary = {} + self.resurse_to_flat_dictionary(json_object, prefix) + return self.flat_dictionary + + def resurse_to_flat_dictionary(self, json, prefix=None): + if type(json) == dict: + for k, v in json.items(): + if prefix is None: + key = k.decode("utf-8").replace(" ", "_") + else: + key = prefix + "." + k.decode("utf-8").replace(" ", "_") + if hasattr(v, '__iter__'): + self.resurse_to_flat_dictionary(v, key) + else: + self.flat_dictionary[key] = str(v).replace(" ", "_") + " " + self.timestamp + elif type(json) == list: + index = 0 + for v in json: + index += 1 + if hasattr(v, '__iter__'): + self.resurse_to_flat_dictionary(v, prefix+"."+str(index)) + else: + if prefix is None: + self.flat_dictionary[index] = str(v).replace(" ", "_") + + " " + self.timestamp + else: + key = prefix + "." + index; + self.flat_dictionary[key] = str(v).replace(" ", "_") + " " + self.timestamp + else: + self.flat_dictionary[json] = self.timestamp |