Ejemplo n.º 1
0
#
# You should have received a copy of the GNU Lesser General Public License
# along with DREAM.  If not, see <http://www.gnu.org/licenses/>.
# ===========================================================================

import xlrd
import json
from DistributionFitting import DistFittest
from ImportExceldata import Import_Excel

workbook = xlrd.open_workbook('Mockup_ProcessingTimes.xls')      #Using xlrd library opens the Excel document with the input data 
worksheets = workbook.sheet_names()
worksheet_ProcessingTimes = worksheets[0]   #It defines the worksheet_ProcessingTimes as the first sheet of the Excel file

A=Import_Excel()            #Call the Import_Excel object 
B=DistFittest()             #Call the Distribution Fitting object
ProcessingTimes= A.Input_data(worksheet_ProcessingTimes, workbook)  #Create a dictionary with the imported data from the Excel file

jsonFile= open('BatchesInput.json','r')       #open the json file
data = json.load(jsonFile)                            #It loads the file
jsonFile.close()
nodes = data['nodes'] 

lista=[]
for (element_id, element) in nodes.iteritems():  #This loop appends in a list the id's of the json file
    element['id'] = element_id 
    lista.append(element ['id'])

fittingDict={}
for element in ProcessingTimes:             #This loop searches the elements of the Excel imported data and if these elements exist in json file append the distribution fitting results in a dictionary   
    if element in lista:
Ejemplo n.º 2
0
failures = data.Input_data(
    worksheet_Fail, workbook
)  #Create the failures dictionary with key the MTTF and MTTR data points

MTTF = failures.get('MTTF', [])
MTTR = failures.get('MTTR', [])

#======================= Fit data to probability distributions ================================#
#The Distributions and DistFittest objects are called to fit statistical distributions to the in scope data
dist = Distributions()
act2Proc = dist.Weibull_distrfit(Activity2_Proc)
act3Proc = dist.Weibull_distrfit(Activity3_Proc)

s1Times = dist.Exponential_distrfit(S1)

distFit = DistFittest()
act1MTTF = distFit.ks_test(MTTF)
act1MTTR = distFit.ks_test(MTTR)

#======================= Output preparation: output the updated values in the XML file of this example ================================#

datafile = ('Topology1.xml')  #define the input xml file
tree = et.parse(datafile)
simul8 = Simul8Output()  #Call the Simul8Output object
#Assign the statistical distribution calculated above in the XML file using methods of the Simul8Output object
interTimes = simul8.InterArrivalTime(tree, 'Source', s1Times)

procTimes2 = simul8.ProcTimes(interTimes, 'Activity 2', act2Proc)
procTimes3 = simul8.ProcTimes(procTimes2, 'Activity 3', act3Proc)

#Again assign the MTTF and MTTR probability distributions calling the relevant methods from the Simul8Output object
Ejemplo n.º 3
0
   
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
Machine2_OpearationTimes = OperationTimes.get('Machine2',[])

A=HandleMissingValues()                                     #Call the HandleMissingValues object
Machine1_OpearationTimes= A.DeleteMissingValue(Machine1_OpearationTimes)        #It deletes the missing values in the lists with the operation times data
Machine2_OpearationTimes= A.DeleteMissingValue(Machine2_OpearationTimes)

Dict={}
B=DistFittest()                                     #It calls the DistFittest object
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 of Topology10 ====================================================#

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

M1Parameters=[]
M1ParameterValue=[]
for index in list(Dict['M1'].keys()):
    if index is not 'distributionType':
        continue

MTTR_MILL1=[]
MTTR_MILL2=[]
for j in range(c.rowcount):
    #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 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()
MTTF=A.Input_data(worksheet_MTTF, workbook)        #Create the MTTF dictionary with key the Machine 1 and 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 

##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()
nodes = data.get('nodes',[])                                                         #It creates a variable that holds the 'nodes' dictionary

for element in nodes:
    processingTime = nodes[element].get('processingTime',{})        #It creates a variable that gets the element attribute 'processingTime'
    MTTF_Nodes = nodes[element].get('MTTF',{})                            #It creates a variable that gets the element attribute 'MTTF'
    MTTR_Nodes = nodes[element].get('MTTR',{})                            #It creates a variable that gets the element attribute 'MTTR'
Ejemplo n.º 6
0
            WIP[key].append(unitsToProcess)
        elif WIP[key][0] == 'PaA':
            secs = WIP[key][1].total_seconds()
            minutes = int(secs / 60)
            unitsToProcess = round(batchSize - (minutes / meanPaA_Proc))
            WIP[key].append(unitsToProcess)
        elif WIP[key][0] == 'PaB':
            secs = WIP[key][1].total_seconds()
            minutes = int(secs / 60)
            unitsToProcess = round(batchSize - (minutes / meanPaB_Proc))
            WIP[key].append(unitsToProcess)
    except IndexError:
        continue

# Call the DistFittest object and conduct Kolmogorov-Smirnov distribution fitting test in the processing times lists of each station
D = DistFittest()
dictProc = {
}  #Create a dictionary that holds the statistical distributions of the processing times of each station
dictProc['MA'] = D.ks_test(MA_Proc)
dictProc['M1A'] = D.ks_test(M1A_Proc)
dictProc['M1B'] = D.ks_test(M1B_Proc)
dictProc['M2A'] = D.ks_test(M2A_Proc)
dictProc['M2B'] = D.ks_test(M2B_Proc)
dictProc['M3A'] = D.ks_test(M3A_Proc)
dictProc['M3B'] = D.ks_test(M3B_Proc)
dictProc['MM'] = D.ks_test(MM_Proc)
dictProc['PrA'] = D.ks_test(PrA_Proc)
dictProc['PrB'] = D.ks_test(PrB_Proc)
dictProc['PaA'] = D.ks_test(PaA_Proc)
dictProc['PaB'] = D.ks_test(PaB_Proc)
#Call the Distributions object and fit (using the Maximum Likelihood Estimation) the lists with the scrap quantity into a discrete statistical distribution, i.e. Geometric distribution
ProcessingTimes = inputData.Input_data(
    worksheet_ProcessingTimes, workbook
)  #Create the Processing Times dictionary with key Machines 1,2 and values the processing time data

##Get from the above dictionaries the M1 key and define the following lists with data
M1_ProcTime = ProcessingTimes.get('M1', [])
M2_ProcTime = ProcessingTimes.get('M2', [])

#Call the HandleMissingValues object and replace the missing values in the lists with the mean of the non-missing values
misValues = HandleMissingValues()
M1_ProcTime = misValues.ReplaceWithMean(M1_ProcTime)
M2_ProcTime = misValues.ReplaceWithMean(M2_ProcTime)

MLE = Distributions(
)  #Call the Distributions object (Maximum Likelihood Estimation - MLE)
KS = DistFittest()  #Call the DistFittest object  (Kolmoghorov-Smirnov test)

M1ProcTime_dist = KS.ks_test(M1_ProcTime)
M2ProcTime_dist = MLE.Normal_distrfit(M2_ProcTime)

#======================= Output preparation: output the updated values in the JSON file of this example ================================#
jsonFile = open('JSON_TwoParallelStations.json', 'r')  #It opens the JSON file
data = json.load(jsonFile)  #It loads the file
jsonFile.close()
nodes = data.get('nodes',
                 [])  #It creates a variable that holds the 'nodes' dictionary

for element in nodes:
    processingTime = nodes[element].get(
        'processingTime', {}
    )  #It creates a variable that gets the element attribute 'processingTime'