Skip to content
Snippets Groups Projects
Commit 0807e766 authored by Richter, Manuela's avatar Richter, Manuela
Browse files

read out json file for specific data

parent cf827783
No related branches found
No related tags found
No related merge requests found
{
"KPI":[
{"Name": "Attribut_1",
"Pumps":[
{"Name": "Pump_1",
"Manufacturer": "Company A",
"Unit": "Percentage",
"Value": 43},
{"Name": "Attribut_2",
"Efficiency": 43},
{"Name": "Pump_2",
"Manufacturer": "Company B",
"Unit": "Percentage",
"Value": 56
"Efficiency": 56
}
],
"Motors":[
{"Name": "Motor_1",
"Manufacturer": "Company A",
"Unit": "Percentage",
"Efficiency": 90},
{"Name": "Motor_2",
"Manufacturer": "Company B",
"Unit": "Percentage",
"Efficiency": 85
}
]
}
\ No newline at end of file
......@@ -42,27 +42,28 @@ def findkeys(node, kv):
#%% main script
with open("test_data.json","r+") as file:
data = json.load(file)
#print(len(data))
#print(type(data))
#print(data["Name"])
a = data.keys()
print(a)
print(type(a))
#print(a)
# read out key - value - pairs
for i in a:
print(i)
key = data[i]
print(len(key))
print(type(key))
for j in key:
attrs = list(j)
print(len(attrs))
print(type(attrs))
print(attrs)
print(j)
for j in range(0,len(key)):
#print(j)
dic = key[j]
attrs = list(dic.keys())
for x in attrs:
name = list(findkeys(dic, x))
#print("Maschinenart", i, "Das Attribut",x, "hat den Wert", name)
# find specific data
machine = "Pumps"
attribut = "Efficiency"
print(list(findkeys(data, 'KPI')))
\ No newline at end of file
data_pumps = data[machine]
print(len(data_pumps))
for c in range(0,len(data_pumps)):
name_pump = list(findkeys(data_pumps[c], "Name"))
efficiency_pump = list(findkeys(data_pumps[c], attribut))
print("Die Pumpe",str(name_pump),"besitzt den Wirkungsgrad", efficiency_pump)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment