Commit 89243e10 authored by Akshay G's avatar Akshay G

Added recursive dir creation, column naming for the csv file

parent 6b814467
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
...@@ -71,9 +71,8 @@ def get_data(query): ...@@ -71,9 +71,8 @@ def get_data(query):
if KariosConstants.GROUPBY_KEY not in config.keys(): if KariosConstants.GROUPBY_KEY not in config.keys():
query[KariosConstants.METRICS_KEY][0].pop(KariosConstants.GROUPBY_KEY) query[KariosConstants.METRICS_KEY][0].pop(KariosConstants.GROUPBY_KEY)
if KariosConstants.TAG_HIERARCHY_KEY in config.keys(): if KariosConstants.TAG_HIERARCHY_KEY in config.keys():
query[KariosConstants.METRICS_KEY][0][KariosConstants.TAGS_KEY][KariosConstants.C3_KEY] = [config[ query[KariosConstants.METRICS_KEY][0][KariosConstants.TAGS_KEY][KariosConstants.C3_KEY] = \
KariosConstants. [list(config[KariosConstants.TAG_HIERARCHY_KEY].values())[0]]
TAG_HIERARCHY_KEY]]
else: else:
raise Exception(ComponentExceptions.MISSING_TAG_HIERARCHY_EXCEPTION) raise Exception(ComponentExceptions.MISSING_TAG_HIERARCHY_EXCEPTION)
...@@ -84,6 +83,7 @@ def get_data(query): ...@@ -84,6 +83,7 @@ def get_data(query):
data = response.json()[KariosConstants.QUERIES_KEY][0][KariosConstants.RESULTS_KEY][0] \ data = response.json()[KariosConstants.QUERIES_KEY][0][KariosConstants.RESULTS_KEY][0] \
[KariosConstants.VALUES_KEY] [KariosConstants.VALUES_KEY]
df = DataFrame.from_dict(data) df = DataFrame.from_dict(data)
df.columns = [KariosConstants.TIMESTAMP_COLUMN_NAME, list(config[KariosConstants.TAG_HIERARCHY_KEY].keys())[0]]
return df return df
else: else:
raise Exception(response.json()[KariosConstants.ERRORS_KEY]) raise Exception(response.json()[KariosConstants.ERRORS_KEY])
...@@ -91,5 +91,5 @@ def get_data(query): ...@@ -91,5 +91,5 @@ def get_data(query):
if __name__ == '__main__': if __name__ == '__main__':
data = get_data(KariosConstants.QUERY) data = get_data(KariosConstants.QUERY)
data.to_csv(os.path.join(config['shared_volume'], 'data.csv')) data.to_csv(os.path.join(config['shared_volume'], 'data.csv'), index=False)
logger.info("Data successfully written to --> {}".format(os.path.join(config['shared_volume'], 'data.csv'))) logger.info("Data successfully written to --> {}".format(os.path.join(config['shared_volume'], 'data.csv')))
\ No newline at end of file
File mode changed from 100644 to 100755
...@@ -33,4 +33,6 @@ LOG_HANDLER_NAME = _config.get('SERVICE_CONFIG', {}).get("LOG_HANDLER_NAME", "Re ...@@ -33,4 +33,6 @@ LOG_HANDLER_NAME = _config.get('SERVICE_CONFIG', {}).get("LOG_HANDLER_NAME", "Re
config = json.loads(os.environ.get('config')) config = json.loads(os.environ.get('config'))
if not os.path.exists(config['shared_volume']): if not os.path.exists(config['shared_volume']):
raise Exception("Shared path does not exist!") sys.stderr.write("Shared path does not exist!")
sys.stderr.write("Creating path --> {}".format(config['shared_volume']))
os.makedirs(config['shared_volume'])
...@@ -26,6 +26,7 @@ class KariosConstants: ...@@ -26,6 +26,7 @@ class KariosConstants:
REQUEST_SUCCESS_CODE = 200 REQUEST_SUCCESS_CODE = 200
PLUGINS_KEY = "plugins" PLUGINS_KEY = "plugins"
CACHE_TIME_KEY = "cache_time" CACHE_TIME_KEY = "cache_time"
TIMESTAMP_COLUMN_NAME = "timestamp"
QUERY = { QUERY = {
METRICS_KEY: [ METRICS_KEY: [
{ {
......
File mode changed from 100644 to 100755
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment