Commit d38da9ba authored by panos's avatar panos

A test added for this example

parent 41191a72
...@@ -27,155 +27,172 @@ from dream.KnowledgeExtraction.DistributionFitting import DistFittest ...@@ -27,155 +27,172 @@ from dream.KnowledgeExtraction.DistributionFitting import DistFittest
from dream.KnowledgeExtraction.DistributionFitting import Distributions from dream.KnowledgeExtraction.DistributionFitting import Distributions
from dream.KnowledgeExtraction.ExcelOutput import Output from dream.KnowledgeExtraction.ExcelOutput import Output
from dream.KnowledgeExtraction.JSONOutput import JSONOutput from dream.KnowledgeExtraction.JSONOutput import JSONOutput
import ImportDatabase from dream.KnowledgeExtraction.ImportDatabase import ConnectionData
from xml.etree import ElementTree as et from xml.etree import ElementTree as et
from CMSDOutput import CMSDOutput from dream.KnowledgeExtraction.CMSDOutput import CMSDOutput
import json import json
import os
#================================= Extract data from the database ==========================================# #================================= Extract data from the database ==========================================#
def main(test=0, JSONFileName='JSON_example.json',
cnxn=ImportDatabase.ConnectionData(seekName='ServerData', implicitExt='txt', number_of_cursors=3) CMSDFileName='CMSD_ParallelStations.xml',
cursors=cnxn.getCursors() DBFilePath = 'C:\Users\Panos\Documents\KE tool_documentation',
file_path=None,
a = cursors[0].execute(""" jsonFile=None, cmsdFile=None):
select prod_code, stat_code,emp_no, TIMEIN, TIMEOUT if not file_path:
from production_status cnxn=ConnectionData(seekName='ServerData', file_path=DBFilePath, implicitExt='txt', number_of_cursors=3)
""") cursors=cnxn.getCursors()
MILL1=[]
MILL2=[] a = cursors[0].execute("""
for j in range(a.rowcount): select prod_code, stat_code,emp_no, TIMEIN, TIMEOUT
#get the next line from production_status
ind1=a.fetchone() """)
if ind1.stat_code == 'MILL1': MILL1=[]
procTime=[] MILL2=[]
procTime.insert(0,ind1.TIMEIN) for j in range(a.rowcount):
procTime.insert(1,ind1.TIMEOUT) #get the next line
MILL1.append(procTime) ind1=a.fetchone()
elif ind1.stat_code == 'MILL2': if ind1.stat_code == 'MILL1':
procTime=[] procTime=[]
procTime.insert(0,ind1.TIMEIN) procTime.insert(0,ind1.TIMEIN)
procTime.insert(1,ind1.TIMEOUT) procTime.insert(1,ind1.TIMEOUT)
MILL2.append(procTime) MILL1.append(procTime)
else: elif ind1.stat_code == 'MILL2':
continue procTime=[]
procTime.insert(0,ind1.TIMEIN)
transform = BasicTransformations() procTime.insert(1,ind1.TIMEOUT)
procTime_MILL1=[] MILL2.append(procTime)
for elem in MILL1: else:
t1=[] continue
t2=[]
t1.append(((elem[0].hour)*60)*60 + (elem[0].minute)*60 + elem[0].second) transform = BasicTransformations()
t2.append(((elem[1].hour)*60)*60 + (elem[1].minute)*60 + elem[1].second) procTime_MILL1=[]
dt=transform.subtraction(t2, t1) for elem in MILL1:
procTime_MILL1.append(dt[0]) t1=[]
t2=[]
procTime_MILL2=[] t1.append(((elem[0].hour)*60)*60 + (elem[0].minute)*60 + elem[0].second)
for elem in MILL2: t2.append(((elem[1].hour)*60)*60 + (elem[1].minute)*60 + elem[1].second)
t1=[] dt=transform.subtraction(t2, t1)
t2=[] procTime_MILL1.append(dt[0])
t1.append(((elem[0].hour)*60)*60 + (elem[0].minute)*60 + elem[0].second)
t2.append(((elem[1].hour)*60)*60 + (elem[1].minute)*60 + elem[1].second) procTime_MILL2=[]
dt=transform.subtraction(t2, t1) for elem in MILL2:
procTime_MILL2.append(dt[0]) t1=[]
t2=[]
t1.append(((elem[0].hour)*60)*60 + (elem[0].minute)*60 + elem[0].second)
b = cursors[1].execute(""" t2.append(((elem[1].hour)*60)*60 + (elem[1].minute)*60 + elem[1].second)
select stat_code, MTTF_hour dt=transform.subtraction(t2, t1)
from failures procTime_MILL2.append(dt[0])
""")
c = cursors[2].execute(""" b = cursors[1].execute("""
select stat_code, MTTR_hour select stat_code, MTTF_hour
from repairs from failures
""") """)
MTTF_MILL1=[]
MTTF_MILL2=[] c = cursors[2].execute("""
for j in range(b.rowcount): select stat_code, MTTR_hour
#get the next line from repairs
ind2=b.fetchone() """)
if ind2.stat_code == 'MILL1': MTTF_MILL1=[]
MTTF_MILL1.append(ind2.MTTF_hour) MTTF_MILL2=[]
elif ind2.stat_code == 'MILL2': for j in range(b.rowcount):
MTTF_MILL2.append(ind2.MTTF_hour) #get the next line
else: ind2=b.fetchone()
continue if ind2.stat_code == 'MILL1':
MTTF_MILL1.append(ind2.MTTF_hour)
MTTR_MILL1=[] elif ind2.stat_code == 'MILL2':
MTTR_MILL2=[] MTTF_MILL2.append(ind2.MTTF_hour)
for j in range(c.rowcount): else:
#get the next line continue
ind3=c.fetchone()
if ind3.stat_code == 'MILL1': MTTR_MILL1=[]
MTTR_MILL1.append(ind3.MTTR_hour) MTTR_MILL2=[]
elif ind3.stat_code == 'MILL2': for j in range(c.rowcount):
MTTR_MILL2.append(ind3.MTTR_hour) #get the next line
ind3=c.fetchone()
if ind3.stat_code == 'MILL1':
MTTR_MILL1.append(ind3.MTTR_hour)
elif ind3.stat_code == 'MILL2':
MTTR_MILL2.append(ind3.MTTR_hour)
else:
continue
#======================= Fit data to statistical distributions ================================#
dist_proctime = DistFittest()
distProcTime_MILL1 = dist_proctime.ks_test(procTime_MILL1)
distProcTime_MILL2 = dist_proctime.ks_test(procTime_MILL2)
dist_MTTF = Distributions()
dist_MTTR = Distributions()
distMTTF_MILL1 = dist_MTTF.Weibull_distrfit(MTTF_MILL1)
distMTTF_MILL2 = dist_MTTF.Weibull_distrfit(MTTF_MILL2)
distMTTR_MILL1 = dist_MTTR.Poisson_distrfit(MTTR_MILL1)
distMTTR_MILL2 = dist_MTTR.Poisson_distrfit(MTTR_MILL2)
#======================== Output preparation: output the values prepared in the CMSD information model of this model ====================================================#
if not cmsdFile:
datafile=(os.path.join(os.path.dirname(os.path.realpath(__file__)), 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
exportCMSD=CMSDOutput()
stationId1='M1'
stationId2='M2'
procTime1=exportCMSD.ProcessingTimes(tree, stationId1, distProcTime_MILL1)
procTime2=exportCMSD.ProcessingTimes(procTime1, stationId2, distProcTime_MILL2)
TTF1=exportCMSD.TTF(procTime2, stationId1, distMTTF_MILL1)
TTR1=exportCMSD.TTR(TTF1, stationId1, distMTTR_MILL1)
TTF2=exportCMSD.TTF(TTR1, stationId2, distMTTF_MILL2)
TTR2=exportCMSD.TTR(TTF2, stationId2, distMTTR_MILL2)
TTR2.write('CMSD_ParallelStations_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 this example ================================#
if not jsonFile:
jsonFile = open(os.path.join(os.path.dirname(os.path.realpath(__file__)), JSONFileName),'r') #It opens the JSON file
data = json.load(jsonFile) #It loads the file
jsonFile.close()
else: else:
continue data = json.load(jsonFile)
#======================= Fit data to statistical distributions ================================#
dist_proctime = DistFittest()
distProcTime_MILL1 = dist_proctime.ks_test(procTime_MILL1)
distProcTime_MILL2 = dist_proctime.ks_test(procTime_MILL2)
dist_MTTF = Distributions()
dist_MTTR = Distributions()
distMTTF_MILL1 = dist_MTTF.Weibull_distrfit(MTTF_MILL1)
distMTTF_MILL2 = dist_MTTF.Weibull_distrfit(MTTF_MILL2)
distMTTR_MILL1 = dist_MTTR.Poisson_distrfit(MTTR_MILL1)
distMTTR_MILL2 = dist_MTTR.Poisson_distrfit(MTTR_MILL2)
#======================== Output preparation: output the values prepared in the CMSD information model of this model ====================================================#
datafile=('CMSD_ParallelStations.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
exportCMSD=CMSDOutput()
stationId1='M1'
stationId2='M2'
procTime1=exportCMSD.ProcessingTimes(tree, stationId1, distProcTime_MILL1)
procTime2=exportCMSD.ProcessingTimes(procTime1, stationId2, distProcTime_MILL2)
TTF1=exportCMSD.TTF(procTime2, stationId1, distMTTF_MILL1)
TTR1=exportCMSD.TTR(TTF1, stationId1, distMTTR_MILL1)
TTF2=exportCMSD.TTF(TTR1, stationId2, distMTTF_MILL2)
TTR2=exportCMSD.TTR(TTF2, stationId2, distMTTR_MILL2)
TTR2.write('CMSD_ParallelStations_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 this example ================================#
jsonFile = open('JSON_example.json','r') #It opens the JSON file
data = json.load(jsonFile) #It loads the file
jsonFile.close()
exportJSON=JSONOutput()
stationId1='M1'
stationId2='M2'
data1=exportJSON.ProcessingTimes(data, stationId1, distProcTime_MILL1)
data2=exportJSON.ProcessingTimes(data1, stationId2, distProcTime_MILL2)
data3=exportJSON.TTF(data2, stationId1, distMTTF_MILL1)
data4=exportJSON.TTR(data3, stationId1, distMTTR_MILL1)
data5=exportJSON.TTF(data4, stationId2, distMTTF_MILL2)
data6=exportJSON.TTR(data5, stationId2, distMTTR_MILL2)
jsonFile = open('JSON_ParallelStations_Output.json',"w") #It opens the JSON file exportJSON=JSONOutput()
jsonFile.write(json.dumps(data6, indent=True)) #It writes the updated data to the JSON file stationId1='M1'
jsonFile.close() #It closes the file stationId2='M2'
data1=exportJSON.ProcessingTimes(data, stationId1, distProcTime_MILL1)
#=================== Calling the ExcelOutput object, outputs the outcomes of the statistical analysis in xls files ==========================# data2=exportJSON.ProcessingTimes(data1, stationId2, distProcTime_MILL2)
export=Output()
data3=exportJSON.TTF(data2, stationId1, distMTTF_MILL1)
export.PrintStatisticalMeasures(procTime_MILL1,'procTimeMILL1_StatResults.xls') data4=exportJSON.TTR(data3, stationId1, distMTTR_MILL1)
export.PrintStatisticalMeasures(procTime_MILL2,'procTimeMILL2_StatResults.xls')
export.PrintStatisticalMeasures(MTTF_MILL1,'MTTFMILL1_StatResults.xls') data5=exportJSON.TTF(data4, stationId2, distMTTF_MILL2)
export.PrintStatisticalMeasures(MTTF_MILL2,'MTTFMILL2_StatResults.xls') data6=exportJSON.TTR(data5, stationId2, distMTTR_MILL2)
export.PrintStatisticalMeasures(MTTR_MILL1,'MTTRMILL1_StatResults.xls')
export.PrintStatisticalMeasures(MTTR_MILL2,'MTTRMILL2_StatResults.xls') # if we run from test return the data6
if test:
export.PrintDistributionFit(procTime_MILL1,'procTimeMILL1_DistFitResults.xls') return data6
export.PrintDistributionFit(procTime_MILL2,'procTimeMILL2_DistFitResults.xls')
export.PrintDistributionFit(MTTF_MILL1,'MTTFMILL1_DistFitResults.xls') jsonFile = open('JSON_ParallelStations_Output.json',"w") #It opens the JSON file
export.PrintDistributionFit(MTTF_MILL2,'MTTFMILL2_DistFitResults.xls') jsonFile.write(json.dumps(data6, indent=True)) #It writes the updated data to the JSON file
export.PrintDistributionFit(MTTR_MILL1,'MTTRMILL1_DistFitResults.xls') jsonFile.close() #It closes the file
export.PrintDistributionFit(MTTR_MILL2,'MTTRMILL2_DistFitResults.xls')
#=================== Calling the ExcelOutput object, outputs the outcomes of the statistical analysis in xls files ==========================#
export=Output()
export.PrintStatisticalMeasures(procTime_MILL1,'procTimeMILL1_StatResults.xls')
export.PrintStatisticalMeasures(procTime_MILL2,'procTimeMILL2_StatResults.xls')
export.PrintStatisticalMeasures(MTTF_MILL1,'MTTFMILL1_StatResults.xls')
export.PrintStatisticalMeasures(MTTF_MILL2,'MTTFMILL2_StatResults.xls')
export.PrintStatisticalMeasures(MTTR_MILL1,'MTTRMILL1_StatResults.xls')
export.PrintStatisticalMeasures(MTTR_MILL2,'MTTRMILL2_StatResults.xls')
export.PrintDistributionFit(procTime_MILL1,'procTimeMILL1_DistFitResults.xls')
export.PrintDistributionFit(procTime_MILL2,'procTimeMILL2_DistFitResults.xls')
export.PrintDistributionFit(MTTF_MILL1,'MTTFMILL1_DistFitResults.xls')
export.PrintDistributionFit(MTTF_MILL2,'MTTFMILL2_DistFitResults.xls')
export.PrintDistributionFit(MTTR_MILL1,'MTTRMILL1_DistFitResults.xls')
export.PrintDistributionFit(MTTR_MILL2,'MTTRMILL2_DistFitResults.xls')
if __name__ == '__main__':
main()
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