|
@@ -14,13 +14,12 @@ import pandas as pd
|
|
|
import copy
|
|
|
sys.path.append(os.getcwd())
|
|
|
from cdplib.log import Log
|
|
|
-log = Log("Flatten data")
|
|
|
|
|
|
class FlattenData():
|
|
|
|
|
|
def __init__(self):
|
|
|
- log.info('Flatten Data Initialized')
|
|
|
-
|
|
|
+ self._log = Log("Flatten data")
|
|
|
+
|
|
|
def flatten(self, data):
|
|
|
'''
|
|
|
:parm data: data given in either dictionary, list or dataframe format.
|
|
@@ -32,7 +31,7 @@ class FlattenData():
|
|
|
start = time.time()
|
|
|
if type(data) is pd.DataFrame:
|
|
|
return_data = self.flatten_dataframe(data)
|
|
|
- print(('Data has been flattened in {} seconds').format(time.time()-start))
|
|
|
+ self._log.info(('Data has been flattened, created {} columns in {} seconds').format(len(return_data.index), time.time()-start))
|
|
|
return return_data
|
|
|
if type(data) is dict:
|
|
|
return self.flatten_dict(data)
|
|
@@ -129,13 +128,14 @@ class FlattenData():
|
|
|
key = incoming_key + '_' + str(data_list[iteration]['stationsnummer']) + '_' + str(data_list[iteration]['stage'])
|
|
|
else:
|
|
|
key = incoming_key + '_' + str(iteration)
|
|
|
+ else:
|
|
|
+ key = str(iteration)
|
|
|
if type(temp_dataframe) == list:
|
|
|
temp_result = self.flatten_list(temp_dataframe, key)
|
|
|
- result_dict = self.append_to_dict(result_dict, temp_result)
|
|
|
|
|
|
elif type(temp_dataframe) == dict:
|
|
|
temp_result = self.flatten_dict(temp_dataframe, key)
|
|
|
- result_dict = self.append_to_dict(result_dict, temp_result)
|
|
|
+
|
|
|
else:
|
|
|
result_dict[key] = temp_dataframe
|
|
|
|