Commit d38da9ba authored by panos's avatar panos

A test added for this example

parent 41191a72
...@@ -27,22 +27,28 @@ from dream.KnowledgeExtraction.DistributionFitting import DistFittest ...@@ -27,22 +27,28 @@ 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):
if not file_path:
cnxn=ConnectionData(seekName='ServerData', file_path=DBFilePath, implicitExt='txt', number_of_cursors=3)
cursors=cnxn.getCursors()
a = cursors[0].execute("""
select prod_code, stat_code,emp_no, TIMEIN, TIMEOUT select prod_code, stat_code,emp_no, TIMEIN, TIMEOUT
from production_status from production_status
""") """)
MILL1=[] MILL1=[]
MILL2=[] MILL2=[]
for j in range(a.rowcount): for j in range(a.rowcount):
#get the next line #get the next line
ind1=a.fetchone() ind1=a.fetchone()
if ind1.stat_code == 'MILL1': if ind1.stat_code == 'MILL1':
...@@ -58,9 +64,9 @@ for j in range(a.rowcount): ...@@ -58,9 +64,9 @@ for j in range(a.rowcount):
else: else:
continue continue
transform = BasicTransformations() transform = BasicTransformations()
procTime_MILL1=[] procTime_MILL1=[]
for elem in MILL1: for elem in MILL1:
t1=[] t1=[]
t2=[] t2=[]
t1.append(((elem[0].hour)*60)*60 + (elem[0].minute)*60 + elem[0].second) t1.append(((elem[0].hour)*60)*60 + (elem[0].minute)*60 + elem[0].second)
...@@ -68,8 +74,8 @@ for elem in MILL1: ...@@ -68,8 +74,8 @@ for elem in MILL1:
dt=transform.subtraction(t2, t1) dt=transform.subtraction(t2, t1)
procTime_MILL1.append(dt[0]) procTime_MILL1.append(dt[0])
procTime_MILL2=[] procTime_MILL2=[]
for elem in MILL2: for elem in MILL2:
t1=[] t1=[]
t2=[] t2=[]
t1.append(((elem[0].hour)*60)*60 + (elem[0].minute)*60 + elem[0].second) t1.append(((elem[0].hour)*60)*60 + (elem[0].minute)*60 + elem[0].second)
...@@ -78,18 +84,18 @@ for elem in MILL2: ...@@ -78,18 +84,18 @@ for elem in MILL2:
procTime_MILL2.append(dt[0]) procTime_MILL2.append(dt[0])
b = cursors[1].execute(""" b = cursors[1].execute("""
select stat_code, MTTF_hour select stat_code, MTTF_hour
from failures from failures
""") """)
c = cursors[2].execute(""" c = cursors[2].execute("""
select stat_code, MTTR_hour select stat_code, MTTR_hour
from repairs from repairs
""") """)
MTTF_MILL1=[] MTTF_MILL1=[]
MTTF_MILL2=[] MTTF_MILL2=[]
for j in range(b.rowcount): for j in range(b.rowcount):
#get the next line #get the next line
ind2=b.fetchone() ind2=b.fetchone()
if ind2.stat_code == 'MILL1': if ind2.stat_code == 'MILL1':
...@@ -99,9 +105,9 @@ for j in range(b.rowcount): ...@@ -99,9 +105,9 @@ for j in range(b.rowcount):
else: else:
continue continue
MTTR_MILL1=[] MTTR_MILL1=[]
MTTR_MILL2=[] MTTR_MILL2=[]
for j in range(c.rowcount): for j in range(c.rowcount):
#get the next line #get the next line
ind3=c.fetchone() ind3=c.fetchone()
if ind3.stat_code == 'MILL1': if ind3.stat_code == 'MILL1':
...@@ -111,71 +117,82 @@ for j in range(c.rowcount): ...@@ -111,71 +117,82 @@ for j in range(c.rowcount):
else: else:
continue continue
#======================= Fit data to statistical distributions ================================# #======================= Fit data to statistical distributions ================================#
dist_proctime = DistFittest() dist_proctime = DistFittest()
distProcTime_MILL1 = dist_proctime.ks_test(procTime_MILL1) distProcTime_MILL1 = dist_proctime.ks_test(procTime_MILL1)
distProcTime_MILL2 = dist_proctime.ks_test(procTime_MILL2) distProcTime_MILL2 = dist_proctime.ks_test(procTime_MILL2)
dist_MTTF = Distributions() dist_MTTF = Distributions()
dist_MTTR = Distributions() dist_MTTR = Distributions()
distMTTF_MILL1 = dist_MTTF.Weibull_distrfit(MTTF_MILL1) distMTTF_MILL1 = dist_MTTF.Weibull_distrfit(MTTF_MILL1)
distMTTF_MILL2 = dist_MTTF.Weibull_distrfit(MTTF_MILL2) distMTTF_MILL2 = dist_MTTF.Weibull_distrfit(MTTF_MILL2)
distMTTR_MILL1 = dist_MTTR.Poisson_distrfit(MTTR_MILL1) distMTTR_MILL1 = dist_MTTR.Poisson_distrfit(MTTR_MILL1)
distMTTR_MILL2 = dist_MTTR.Poisson_distrfit(MTTR_MILL2) distMTTR_MILL2 = dist_MTTR.Poisson_distrfit(MTTR_MILL2)
#======================== Output preparation: output the values prepared in the CMSD information model of this model ====================================================# #======================== 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 if not cmsdFile:
tree = et.parse(datafile) #This file will be parsed using the XML.ETREE Python library 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' exportCMSD=CMSDOutput()
stationId2='M2' stationId1='M1'
procTime1=exportCMSD.ProcessingTimes(tree, stationId1, distProcTime_MILL1) stationId2='M2'
procTime2=exportCMSD.ProcessingTimes(procTime1, stationId2, distProcTime_MILL2) 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) 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) 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
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 #======================= Output preparation: output the updated values in the JSON file of this example ================================#
data = json.load(jsonFile) #It loads the file if not jsonFile:
jsonFile.close() 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
exportJSON=JSONOutput() jsonFile.close()
stationId1='M1' else:
stationId2='M2' data = json.load(jsonFile)
data1=exportJSON.ProcessingTimes(data, stationId1, distProcTime_MILL1)
data2=exportJSON.ProcessingTimes(data1, stationId2, distProcTime_MILL2) exportJSON=JSONOutput()
stationId1='M1'
data3=exportJSON.TTF(data2, stationId1, distMTTF_MILL1) stationId2='M2'
data4=exportJSON.TTR(data3, stationId1, distMTTR_MILL1) data1=exportJSON.ProcessingTimes(data, stationId1, distProcTime_MILL1)
data2=exportJSON.ProcessingTimes(data1, stationId2, distProcTime_MILL2)
data5=exportJSON.TTF(data4, stationId2, distMTTF_MILL2)
data6=exportJSON.TTR(data5, stationId2, distMTTR_MILL2) data3=exportJSON.TTF(data2, stationId1, distMTTF_MILL1)
data4=exportJSON.TTR(data3, stationId1, distMTTR_MILL1)
jsonFile = open('JSON_ParallelStations_Output.json',"w") #It opens the JSON file
jsonFile.write(json.dumps(data6, indent=True)) #It writes the updated data to the JSON file data5=exportJSON.TTF(data4, stationId2, distMTTF_MILL2)
jsonFile.close() #It closes the file data6=exportJSON.TTR(data5, stationId2, distMTTR_MILL2)
#=================== Calling the ExcelOutput object, outputs the outcomes of the statistical analysis in xls files ==========================# # if we run from test return the data6
export=Output() if test:
return data6
export.PrintStatisticalMeasures(procTime_MILL1,'procTimeMILL1_StatResults.xls')
export.PrintStatisticalMeasures(procTime_MILL2,'procTimeMILL2_StatResults.xls') jsonFile = open('JSON_ParallelStations_Output.json',"w") #It opens the JSON file
export.PrintStatisticalMeasures(MTTF_MILL1,'MTTFMILL1_StatResults.xls') jsonFile.write(json.dumps(data6, indent=True)) #It writes the updated data to the JSON file
export.PrintStatisticalMeasures(MTTF_MILL2,'MTTFMILL2_StatResults.xls') jsonFile.close() #It closes the file
export.PrintStatisticalMeasures(MTTR_MILL1,'MTTRMILL1_StatResults.xls')
export.PrintStatisticalMeasures(MTTR_MILL2,'MTTRMILL2_StatResults.xls') #=================== Calling the ExcelOutput object, outputs the outcomes of the statistical analysis in xls files ==========================#
export=Output()
export.PrintDistributionFit(procTime_MILL1,'procTimeMILL1_DistFitResults.xls')
export.PrintDistributionFit(procTime_MILL2,'procTimeMILL2_DistFitResults.xls') export.PrintStatisticalMeasures(procTime_MILL1,'procTimeMILL1_StatResults.xls')
export.PrintDistributionFit(MTTF_MILL1,'MTTFMILL1_DistFitResults.xls') export.PrintStatisticalMeasures(procTime_MILL2,'procTimeMILL2_StatResults.xls')
export.PrintDistributionFit(MTTF_MILL2,'MTTFMILL2_DistFitResults.xls') export.PrintStatisticalMeasures(MTTF_MILL1,'MTTFMILL1_StatResults.xls')
export.PrintDistributionFit(MTTR_MILL1,'MTTRMILL1_DistFitResults.xls') export.PrintStatisticalMeasures(MTTF_MILL2,'MTTFMILL2_StatResults.xls')
export.PrintDistributionFit(MTTR_MILL2,'MTTRMILL2_DistFitResults.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