Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json-parsing-merging-melting
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mohammed.shibili
json-parsing-merging-melting
Commits
8e366299
Commit
8e366299
authored
Jan 30, 2023
by
mohammed.shibili
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pivot error correction and header change
parent
35887f8f
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
104 additions
and
40 deletions
+104
-40
.idea/sonarlint/issuestore/1/e/1e9075f5bf079c01ef2c910709e91a497d262080
+0
-0
.idea/sonarlint/issuestore/7/4/742e03b5d9ae5b166ca116078a7bf85c41940472
+0
-0
.idea/sonarlint/issuestore/index.pb
+6
-0
script/core/handlers/json.py
+15
-5
script/servieces/main_call.py
+3
-3
script/temp/data.json
+20
-8
script/temp/melted.json
+20
-8
script/temp/merged.json
+20
-8
script/temp/pivoted.json
+20
-8
No files found.
.idea/sonarlint/issuestore/1/e/1e9075f5bf079c01ef2c910709e91a497d262080
0 → 100644
View file @
8e366299
.idea/sonarlint/issuestore/7/4/742e03b5d9ae5b166ca116078a7bf85c41940472
0 → 100644
View file @
8e366299
.idea/sonarlint/issuestore/index.pb
View file @
8e366299
No preview for this file type
script/core/handlers/json.py
View file @
8e366299
...
@@ -6,25 +6,33 @@ from script.core.handlers.pivot import to_pivot
...
@@ -6,25 +6,33 @@ from script.core.handlers.pivot import to_pivot
# creating json
# creating json
def
to_json
(
new_dataframe
,
label_dataframe
,
melting_data
):
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'
)}
data_dict
=
{
'body'
:
new_dataframe
.
to_dict
(
orient
=
'records'
)}
json_dict
=
{
**
header_dict
,
**
data_dict
}
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
:
try
:
with
open
(
json_path
,
'w'
)
as
f
:
with
open
(
json_path
,
'w'
)
as
f
:
json
.
dump
(
json_dict
,
f
,
indent
=
4
)
json
.
dump
(
json_dict
,
f
,
indent
=
4
)
print
(
f
'parsing of {json_dict} done
\n
'
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
"error while parsing "
,
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
# pivoted data to json
try
:
try
:
with
open
(
pivot_path
,
'w'
)
as
w
:
with
open
(
pivot_path
,
'w'
)
as
w
:
json
.
dump
(
pivot_dict
,
w
,
indent
=
4
)
json
.
dump
(
pivot_dict
,
w
,
indent
=
4
)
print
(
f
'parsing of pivoted data {pivot_dict} done
\n
'
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
"error while parsing of pivot"
,
e
)
print
(
"error while parsing of pivot"
,
e
)
# for melt
# for melt
melted_dataframe
=
{
'body'
:
melting_data
.
to_dict
(
orient
=
'records'
)}
melted_dataframe
=
{
'body'
:
melting_data
.
to_dict
(
orient
=
'records'
)}
...
@@ -32,6 +40,7 @@ def to_json(new_dataframe, label_dataframe, melting_data):
...
@@ -32,6 +40,7 @@ def to_json(new_dataframe, label_dataframe, melting_data):
try
:
try
:
with
open
(
melted_path
,
'w'
)
as
w
:
with
open
(
melted_path
,
'w'
)
as
w
:
json
.
dump
(
melted_dict
,
w
,
indent
=
4
)
json
.
dump
(
melted_dict
,
w
,
indent
=
4
)
print
(
f
'melting of {melted_dict} done
\n
'
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
"error while parsing melted data"
,
e
)
print
(
"error while parsing melted data"
,
e
)
...
@@ -42,5 +51,6 @@ def to_json(new_dataframe, label_dataframe, melting_data):
...
@@ -42,5 +51,6 @@ def to_json(new_dataframe, label_dataframe, melting_data):
try
:
try
:
with
open
(
merged_path
,
'w'
)
as
x
:
with
open
(
merged_path
,
'w'
)
as
x
:
json
.
dump
(
merged_dict
,
x
,
indent
=
4
)
json
.
dump
(
merged_dict
,
x
,
indent
=
4
)
print
(
f
'merging of {merged_dict} done'
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
"error while parsing merged data"
,
e
)
print
(
"error while parsing merged data"
,
e
)
script/servieces/main_call.py
View file @
8e366299
...
@@ -15,9 +15,9 @@ def json_parsing():
...
@@ -15,9 +15,9 @@ def json_parsing():
new_dataframe
=
pd
.
concat
([
new_dataframe
,
dataset
.
tail
(
10
)],
ignore_index
=
True
)
new_dataframe
=
pd
.
concat
([
new_dataframe
,
dataset
.
tail
(
10
)],
ignore_index
=
True
)
# dataframe for setting labels
# dataframe for setting labels
label_dataframe
=
pd
.
DataFrame
(
label_dataframe
=
(
'timestamp'
,
'kwh'
,
'kvah'
,
'kw'
,
'kva'
,
'current_value'
)
{
'label1'
:
''
,
'label2'
:
''
,
'label3'
:
''
,
'label4'
:
''
,
'label5'
:
''
,
'label6'
:
''
},
index
=
[
'column1'
,
'column2'
,
'column3'
,
'column4'
,
'column5'
,
'column6'
,
])
# for changing time format
new_dataframe
=
time_format
(
new_dataframe
)
new_dataframe
=
time_format
(
new_dataframe
)
# call for parsing to json
# call for parsing to json
...
...
script/temp/data.json
View file @
8e366299
{
{
"header"
:
{
"header"
:
[
"label1"
:
"Timestamp"
,
{
"label2"
:
"kWh"
,
"Timestamp"
:
"timestamp"
"label3"
:
"kVAh"
,
},
"label4"
:
"kW"
,
{
"label5"
:
"kVA"
,
"kWh"
:
"kwh"
"label6"
:
"current"
},
},
{
"kVAh"
:
"kvah"
},
{
"kW"
:
"kw"
},
{
"kVA"
:
"kva"
},
{
"current"
:
"current_value"
}
],
"body"
:
[
"body"
:
[
{
{
"Timestamp"
:
"21:00:00 01-12-19"
,
"Timestamp"
:
"21:00:00 01-12-19"
,
...
...
script/temp/melted.json
View file @
8e366299
{
{
"header"
:
{
"header"
:
[
"label1"
:
"Timestamp"
,
{
"label2"
:
"kWh"
,
"Timestamp"
:
"timestamp"
"label3"
:
"kVAh"
,
},
"label4"
:
"kW"
,
{
"label5"
:
"kVA"
,
"kWh"
:
"kwh"
"label6"
:
"current"
},
},
{
"kVAh"
:
"kvah"
},
{
"kW"
:
"kw"
},
{
"kVA"
:
"kva"
},
{
"current"
:
"current_value"
}
],
"body"
:
[
"body"
:
[
{
{
"Timestamp"
:
"21:00:00 01-12-19"
,
"Timestamp"
:
"21:00:00 01-12-19"
,
...
...
script/temp/merged.json
View file @
8e366299
{
{
"header"
:
{
"header"
:
[
"label1"
:
"Timestamp"
,
{
"label2"
:
"kWh"
,
"Timestamp"
:
"timestamp"
"label3"
:
"kVAh"
,
},
"label4"
:
"kW"
,
{
"label5"
:
"kVA"
,
"kWh"
:
"kwh"
"label6"
:
"current"
},
},
{
"kVAh"
:
"kvah"
},
{
"kW"
:
"kw"
},
{
"kVA"
:
"kva"
},
{
"current"
:
"current_value"
}
],
"body"
:
[
"body"
:
[
{
{
"Timestamp"
:
"21:00:00 01-12-19"
,
"Timestamp"
:
"21:00:00 01-12-19"
,
...
...
script/temp/pivoted.json
View file @
8e366299
{
{
"header"
:
{
"header"
:
[
"label1"
:
"Timestamp"
,
{
"label2"
:
"kWh"
,
"Timestamp"
:
"timestamp"
"label3"
:
"kVAh"
,
},
"label4"
:
"kW"
,
{
"label5"
:
"kVA"
,
"kWh"
:
"kwh"
"label6"
:
"current"
},
},
{
"kVAh"
:
"kvah"
},
{
"kW"
:
"kw"
},
{
"kVA"
:
"kva"
},
{
"current"
:
"current_value"
}
],
"body"
:
[
"body"
:
[
{
{
"current"
:
283.2255350748698
,
"current"
:
283.2255350748698
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment