Commit 585372bf authored by panos's avatar panos

Example JSONOutput object modified

parent 8289c722
...@@ -23,13 +23,23 @@ Created on 9 Oct 2014 ...@@ -23,13 +23,23 @@ Created on 9 Oct 2014
# =========================================================================== # ===========================================================================
import json import json
#Create a method that receives the three dictionaries from the KE tool main script, updates the JSON schema and returns it to the KE tool main script #Create an object that receives the three dictionaries from the KE tool main script, updates the JSON schema and returns it to the KE tool main script
def JSON_example(list1,list2,list3): class JSONOutput(object):
def Distributions(self,data):
data1={}
dist=data['distributionType']
del data['distributionType']
data1[dist]=data
data=data1
return data
def JSONOutput(self,list1,list2,list3):
jsonFile= open('JSON_example.json', 'r') #open the JSON_example.json file jsonFile= open('JSON_example.json', 'r') #open the JSON_example.json file
data = json.load(jsonFile) data = json.load(jsonFile)
jsonFile.close() jsonFile.close()
nodes=data.get('nodes',{}) nodes=data['graph']['node']
batchWIP={} batchWIP={}
for (element_id,element) in nodes.iteritems(): for (element_id,element) in nodes.iteritems():
name=element.get('name') name=element.get('name')
...@@ -51,11 +61,11 @@ def JSON_example(list1,list2,list3): ...@@ -51,11 +61,11 @@ def JSON_example(list1,list2,list3):
else: else:
continue continue
if name in list1.keys(): # condition that checks if the element in the list1 is the same as the name of the element in JSON file if name in list1.keys(): # condition that checks if the element in the list1 is the same as the name of the element in JSON file
element['processingTime']= list1[name] # input the attributes of list1[name] to the JSON's element 'processingTime' element['processingTime']= self.Distributions(list1[name]) # input the attributes of list1[name] to the JSON's element 'processingTime'
else: else:
continue continue
if name in list2.keys(): # condition that checks if the element in the list2 is the same as the name of the element in JSON file if name in list2.keys():# condition that checks if the element in the list2 is the same as the name of the element in JSON file
element['scrapQuantity']= list2[name] # input the attributes of list2[name] to the JSON's element 'scrapQuantity' element['scrapQuantity']= self.Distributions(list2[name]) # input the attributes of list2[name] to the JSON's element 'scrapQuantity'
else: else:
continue continue
jsonFile = open('JSON_exampleOutput.json',"w") jsonFile = open('JSON_exampleOutput.json',"w")
......
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