Commit 8e366299 by mohammed.shibili

pivot error correction and header change

parent 35887f8f
......@@ -6,25 +6,33 @@ from script.core.handlers.pivot import to_pivot
# creating json
def to_json(new_dataframe, label_dataframe, melting_data):
header_dict = {'header': dict(zip(label_dataframe.columns, new_dataframe.columns))}
head_list = []
for index, header in enumerate(new_dataframe.columns):
head_list.append({header: label_dataframe[index]})
header_dict = {'header': head_list}
data_dict = {'body': new_dataframe.to_dict(orient='records')}
json_dict = {**header_dict, **data_dict}
# for pivot data
pivoted_data = to_pivot(new_dataframe)
pivoted_dataframe = {'body': pivoted_data.to_dict(orient='records')}
pivot_dict = {**header_dict, **pivoted_dataframe}
try:
with open(json_path, 'w') as f:
json.dump(json_dict, f, indent=4)
print(f'parsing of {json_dict} done\n')
except Exception as e:
print("error while parsing ", e)
# for pivot data
pivoted_data = to_pivot(new_dataframe)
pivoted_dataframe = {'body': pivoted_data.to_dict(orient='records')}
pivot_dict = {**header_dict, **pivoted_dataframe}
# pivoted data to json
try:
with open(pivot_path, 'w') as w:
json.dump(pivot_dict, w, indent=4)
print(f'parsing of pivoted data {pivot_dict} done\n')
except Exception as e:
print("error while parsing of pivot", e)
# for melt
melted_dataframe = {'body': melting_data.to_dict(orient='records')}
......@@ -32,6 +40,7 @@ def to_json(new_dataframe, label_dataframe, melting_data):
try:
with open(melted_path, 'w') as w:
json.dump(melted_dict, w, indent=4)
print(f'melting of {melted_dict} done\n')
except Exception as e:
print("error while parsing melted data", e)
......@@ -42,5 +51,6 @@ def to_json(new_dataframe, label_dataframe, melting_data):
try:
with open(merged_path, 'w') as x:
json.dump(merged_dict, x, indent=4)
print(f'merging of {merged_dict} done')
except Exception as e:
print("error while parsing merged data", e)
......@@ -15,9 +15,9 @@ def json_parsing():
new_dataframe = pd.concat([new_dataframe, dataset.tail(10)], ignore_index=True)
# dataframe for setting labels
label_dataframe = pd.DataFrame(
{'label1': '', 'label2': '', 'label3': '', 'label4': '', 'label5': '', 'label6': ''},
index=['column1', 'column2', 'column3', 'column4', 'column5', 'column6', ])
label_dataframe = ('timestamp', 'kwh', 'kvah', 'kw', 'kva', 'current_value')
# for changing time format
new_dataframe = time_format(new_dataframe)
# call for parsing to json
......
{
"header": {
"label1": "Timestamp",
"label2": "kWh",
"label3": "kVAh",
"label4": "kW",
"label5": "kVA",
"label6": "current"
"header": [
{
"Timestamp": "timestamp"
},
{
"kWh": "kwh"
},
{
"kVAh": "kvah"
},
{
"kW": "kw"
},
{
"kVA": "kva"
},
{
"current": "current_value"
}
],
"body": [
{
"Timestamp": "21:00:00 01-12-19",
......
{
"header": {
"label1": "Timestamp",
"label2": "kWh",
"label3": "kVAh",
"label4": "kW",
"label5": "kVA",
"label6": "current"
"header": [
{
"Timestamp": "timestamp"
},
{
"kWh": "kwh"
},
{
"kVAh": "kvah"
},
{
"kW": "kw"
},
{
"kVA": "kva"
},
{
"current": "current_value"
}
],
"body": [
{
"Timestamp": "21:00:00 01-12-19",
......
{
"header": {
"label1": "Timestamp",
"label2": "kWh",
"label3": "kVAh",
"label4": "kW",
"label5": "kVA",
"label6": "current"
"header": [
{
"Timestamp": "timestamp"
},
{
"kWh": "kwh"
},
{
"kVAh": "kvah"
},
{
"kW": "kw"
},
{
"kVA": "kva"
},
{
"current": "current_value"
}
],
"body": [
{
"Timestamp": "21:00:00 01-12-19",
......
{
"header": {
"label1": "Timestamp",
"label2": "kWh",
"label3": "kVAh",
"label4": "kW",
"label5": "kVA",
"label6": "current"
"header": [
{
"Timestamp": "timestamp"
},
{
"kWh": "kwh"
},
{
"kVAh": "kvah"
},
{
"kW": "kw"
},
{
"kVA": "kva"
},
{
"current": "current_value"
}
],
"body": [
{
"current": 283.2255350748698,
......
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