#The following is the Main script, that calls two Python objects in order to conduct the three main components of the Knowledge extraction tool
#In the following example the operation times of the topology's two machines are given in an Excel document.
#Import_Excel object imports data from the Excel document to the tool and DistFittest object fits the data to a statistical distribution using Kolmogorov-Smirnov test
workbook=xlrd.open_workbook('inputsTwoServers.xls')#Using xlrd library opens the Excel document with the input data
worksheets=workbook.sheet_names()
worksheet_OperationTime=worksheets[0]#It creates a variable that holds the first Excel worksheet
X=Import_Excel()#Call the import_Excel object
OperationTimes=X.Input_data(worksheet_OperationTime,workbook)#It defines a Python dictionary, giving as name OpearationTimes and as value the returned dictionary from the import_Excel object
Machine1_OpearationTimes=OperationTimes.get('Machine1',[])#Two lists are defined (Machine1_OpearationTimes, Machine2_OpearationTimes) with the operation times data of each machine
Dict['M1']=B.ks_test(Machine1_OpearationTimes)#It conducts the Kolmogorov-Smirnov test in the list with the operation times data
Dict['M2']=B.ks_test(Machine2_OpearationTimes)
M1=Dict.get('M1')
M2=Dict.get('M2')
#==================================== Output preparation: output the updated values in the CMSD information model ====================================================#
datafile=('CMSD_TwoServers.xml')#It defines the name or the directory of the XML file that is manually written the CMSD information model
tree=et.parse(datafile)#This file will be parsed using the XML.ETREE Python library
procTime2.write('CMSD_TwoServers_Output.xml',encoding="utf8")#It writes the element tree to a specified file, using the 'utf8' output encoding
#================================= Output preparation: output the updated values in the JSON file of Topology10 =========================================================#
jsonFile=open('JSON_TwoServers.json','r')#It opens the Topology10 JSON file
jsonFile=open('JSON_TwoServers_Output.json',"w")#It opens the JSON file
jsonFile.write(json.dumps(data1,indent=True))#It writes the updated data to the JSON file
jsonFile.close()#It closes the file
#================================ Calling the ExcelOutput object, outputs the outcomes of the statistical analysis in Excel files =============================================#
workbook=xlrd.open_workbook(ExcelFileName)#Using xlrd library opens the Excel document with the input data
worksheets=workbook.sheet_names()
worksheet_OperationTime=worksheets[0]#It creates a variable that holds the first Excel worksheet
X=Import_Excel()#Call the import_Excel object
OperationTimes=X.Input_data(worksheet_OperationTime,workbook)#It defines a Python dictionary, giving as name OpearationTimes and as value the returned dictionary from the import_Excel object
Machine1_OpearationTimes=OperationTimes.get('Machine1',[])#Two lists are defined (Machine1_OpearationTimes, Machine2_OpearationTimes) with the operation times data of each machine
Dict['M1']=B.ks_test(Machine1_OpearationTimes)#It conducts the Kolmogorov-Smirnov test in the list with the operation times data
Dict['M2']=B.ks_test(Machine2_OpearationTimes)
M1=Dict.get('M1')
M2=Dict.get('M2')
#==================================== Output preparation: output the updated values in the CMSD information model ====================================================#
ifnotcmsdFile:
datafile=CMSDFileName#It defines the name or the directory of the XML file that is manually written the CMSD information model
tree=et.parse(datafile)#This file will be parsed using the XML.ETREE Python library
procTime2.write('CMSD_TwoServers_Output.xml',encoding="utf8")#It writes the element tree to a specified file, using the 'utf8' output encoding
#================================= Output preparation: output the updated values in the JSON file of Topology10 =========================================================#
ifnotjsonFile:
jsonFile=open(JSONFileName,'r')#It opens the JSON file
#=================== Ouput the JSON file ==========================#
jsonFile=open('JSON_TwoServers_Output.json',"w")#It opens the JSON file
jsonFile.write(json.dumps(data1,indent=True))#It writes the updated data to the JSON file
jsonFile.close()#It closes the file
#================================ Calling the ExcelOutput object, outputs the outcomes of the statistical analysis in Excel files =============================================#