Commit 6828c186 authored by panos's avatar panos

A test created for this example

parent 3ccc00a4
...@@ -31,62 +31,83 @@ from dream.KnowledgeExtraction.JSONOutput import JSONOutput ...@@ -31,62 +31,83 @@ from dream.KnowledgeExtraction.JSONOutput import JSONOutput
import dream.simulation.LineGenerationJSON as ManPyMain #import ManPy main JSON script import dream.simulation.LineGenerationJSON as ManPyMain #import ManPy main JSON script
import xlrd import xlrd
import json import json
import os
#Read from the given directory the Excel document with the input data def main(test=0, ExcelFileName='inputData.xls',
workbook = xlrd.open_workbook('inputData.xls') JSONFileName='JSON_AssembleDismantle.json',
worksheets = workbook.sheet_names() workbook=None,
worksheet_ProcessingTimes = worksheets[0] #Define the worksheet with the Processing times data jsonFile=None):
worksheet_MTTF = worksheets[1] #Define the worksheet with Time-to-Failure data if not workbook:
worksheet_MTTR = worksheets[2] #Define the worksheet with Time-to-Repair data workbook = xlrd.open_workbook(os.path.join(os.path.dirname(os.path.realpath(__file__)), ExcelFileName))
#Read from the given directory the Excel document with the input data
A = Import_Excel() #Call the Python object Import_Excel worksheets = workbook.sheet_names()
ProcessingTimes = A.Input_data(worksheet_ProcessingTimes, workbook) #Create the Processing Times dictionary with key the Machine 1 and values the processing time data worksheet_ProcessingTimes = worksheets[0] #Define the worksheet with the Processing times data
MTTF=A.Input_data(worksheet_MTTF, workbook) #Create the MTTF dictionary with key the Machine 1 and time-to-failure data worksheet_MTTF = worksheets[1] #Define the worksheet with Time-to-Failure data
MTTR=A.Input_data(worksheet_MTTR, workbook) #Create the MTTR Quantity dictionary with key the Machine 1 and time-to-repair data worksheet_MTTR = worksheets[2] #Define the worksheet with Time-to-Repair data
##Get from the above dictionaries the M1 key and define the following lists with data
ProcTime = ProcessingTimes.get('M1',[])
MTTF = MTTF.get('M1',[])
MTTR = MTTR.get('M1',[])
#Call the HandleMissingValues object and replace the missing values in the lists with the mean of the non-missing values
B =HandleMissingValues()
ProcTime = B.ReplaceWithMean(ProcTime)
MTTF = B.ReplaceWithMean(MTTF)
MTTR = B.ReplaceWithMean(MTTR)
C = Distributions() #Call the Distributions object
D = DistFittest() #Call the DistFittest object
ProcTime_dist = D.ks_test(ProcTime)
MTTF_dist = C.Exponential_distrfit(MTTF)
MTTR_dist = C.Exponential_distrfit(MTTR)
#================================= Output preparation: output the updated values in the JSON file of this example =========================================================#
jsonFile = open('JSON_AssembleDismantle.json','r') #It opens the JSON file
data = json.load(jsonFile) #It loads the file
jsonFile.close()
exportJSON=JSONOutput()
stationId='M1'
data=exportJSON.ProcessingTimes(data, stationId, ProcTime_dist)
data1=exportJSON.TTF(data, stationId, MTTF_dist)
data2=exportJSON.TTR(data1, stationId, MTTR_dist)
jsonFile = open('JSON_AssembleDismantle_Output.json',"w") #It opens the JSON file A = Import_Excel() #Call the Python object Import_Excel
jsonFile.write(json.dumps(data2, indent=True)) #It writes the updated data to the JSON file ProcessingTimes = A.Input_data(worksheet_ProcessingTimes, workbook) #Create the Processing Times dictionary with key the Machine 1 and values the processing time data
jsonFile.close() #It closes the file MTTF=A.Input_data(worksheet_MTTF, workbook) #Create the MTTF dictionary with key the Machine 1 and time-to-failure data
#================================ Calling the ExcelOutput object, outputs the outcomes of the statistical analysis in xls files =============================================# MTTR=A.Input_data(worksheet_MTTR, workbook) #Create the MTTR Quantity dictionary with key the Machine 1 and time-to-repair data
C=Output()
C.PrintStatisticalMeasures(ProcTime,'ProcTime_StatResults.xls') ##Get from the above dictionaries the M1 key and define the following lists with data
C.PrintStatisticalMeasures(MTTR,'MTTR_StatResults.xls') ProcTime = ProcessingTimes.get('M1',[])
C.PrintStatisticalMeasures(MTTF,'MTTF_StatResults.xls') MTTF = MTTF.get('M1',[])
C.PrintDistributionFit(ProcTime,'ProcTime_DistFitResults.xls') MTTR = MTTR.get('M1',[])
C.PrintDistributionFit(MTTR,'MTTR_DistFitResults.xls')
#Call the HandleMissingValues object and replace the missing values in the lists with the mean of the non-missing values
#================================ Call ManPy and run the simulation model =============================================# B =HandleMissingValues()
#calls ManPy main script with the input ProcTime = B.ReplaceWithMean(ProcTime)
simulationOutput=ManPyMain.main(input_data=json.dumps(data)) MTTF = B.ReplaceWithMean(MTTF)
# save the simulation output MTTR = B.ReplaceWithMean(MTTR)
jsonFile = open('ManPyOutput.json',"w") #It opens the JSON file
jsonFile.write(simulationOutput) #It writes the updated data to the JSON file C = Distributions() #Call the Distributions object
jsonFile.close() #It closes the file D = DistFittest() #Call the DistFittest object
\ No newline at end of file
ProcTime_dist = D.ks_test(ProcTime)
MTTF_dist = C.Exponential_distrfit(MTTF)
MTTR_dist = C.Exponential_distrfit(MTTR)
#================================= 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:
data = json.load(jsonFile)
exportJSON=JSONOutput()
stationId='M1'
data=exportJSON.ProcessingTimes(data, stationId, ProcTime_dist)
data1=exportJSON.TTF(data, stationId, MTTF_dist)
data2=exportJSON.TTR(data1, stationId, MTTR_dist)
#================================ Call ManPy and run the simulation model =============================================#
#calls ManPy main script with the input
simulationOutput=ManPyMain.main(input_data=json.dumps(data2))
# if we run from test return the ManPy result
if test:
return simulationOutput
#===================== Output the JSON file ========================================#
jsonFile = open('JSON_AssembleDismantle_Output.json',"w") #It opens the JSON file
jsonFile.write(json.dumps(data2, 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 xls files =============================================#
C=Output()
C.PrintStatisticalMeasures(ProcTime,'ProcTime_StatResults.xls')
C.PrintStatisticalMeasures(MTTR,'MTTR_StatResults.xls')
C.PrintStatisticalMeasures(MTTF,'MTTF_StatResults.xls')
C.PrintDistributionFit(ProcTime,'ProcTime_DistFitResults.xls')
C.PrintDistributionFit(MTTR,'MTTR_DistFitResults.xls')
#================================ Call ManPy and run the simulation model =============================================#
#calls ManPy main script with the input
simulationOutput=ManPyMain.main(input_data=json.dumps(data))
# save the simulation output
jsonFile = open('ManPyOutput.json',"w") #It opens the JSON file
jsonFile.write(simulationOutput) #It writes the updated data to the JSON file
jsonFile.close() #It closes the file
if __name__ == '__main__':
main()
\ No newline at end of file
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