Commit c6c53b4a authored by Jérome Perrin's avatar Jérome Perrin

make getConfidenceIntervals a global function because not all classes are subclass of CoreObject

parent e2b9b97b
......@@ -245,6 +245,7 @@ class Assembly(CoreObject):
#outputs data to "output.xls"
def outputResultsXL(self, MaxSimtime=None):
from Globals import G
from Globals import getConfidenceIntervals
if MaxSimtime==None:
MaxSimtime=G.maxSimTime
if(G.numberOfReplications==1): #if we had just one replication output the results to excel
......@@ -259,21 +260,21 @@ class Assembly(CoreObject):
G.outputIndex+=1
else:
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Working of "+ self.objName+" is:")
working_ci = self.getConfidenceIntervals(self.Working)
working_ci = getConfidenceIntervals(self.Working)
G.outputSheet.write(G.outputIndex, 1, working_ci['min'])
G.outputSheet.write(G.outputIndex, 2, working_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, working_ci['max'])
G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Blockage of "+ self.objName+" is:")
blockage_ci = self.getConfidenceIntervals(self.Blockage)
blockage_ci = getConfidenceIntervals(self.Blockage)
G.outputSheet.write(G.outputIndex, 1, blockage_ci['min'])
G.outputSheet.write(G.outputIndex, 2, blockage_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, blockage_ci['max'])
G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Waiting of "+ self.objName+" is:")
waiting_ci = self.getConfidenceIntervals(self.Waiting)
waiting_ci = getConfidenceIntervals(self.Waiting)
G.outputSheet.write(G.outputIndex, 1, waiting_ci['min'])
G.outputSheet.write(G.outputIndex, 2, waiting_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, waiting_ci['max'])
......@@ -283,6 +284,7 @@ class Assembly(CoreObject):
#outputs results to JSON File
def outputResultsJSON(self):
from Globals import G
from Globals import getConfidenceIntervals
json = {'_class': self.class_name,
'id': self.id,
'results': {}}
......@@ -291,8 +293,8 @@ class Assembly(CoreObject):
json['results']['blockage_ratio']=100*self.totalBlockageTime/G.maxSimTime
json['results']['waiting_ratio']=100*self.totalWaitingTime/G.maxSimTime
else:
json['results']['working_ratio'] = self.getConfidenceIntervals(self.Working)
json['results']['blockage_ratio'] = self.getConfidenceIntervals(self.Blockage)
json['results']['waiting_ratio'] = self.getConfidenceIntervals(self.Waiting)
json['results']['working_ratio'] = getConfidenceIntervals(self.Working)
json['results']['blockage_ratio'] = getConfidenceIntervals(self.Blockage)
json['results']['waiting_ratio'] = getConfidenceIntervals(self.Waiting)
G.outputJSON['elementList'].append(json)
......@@ -296,6 +296,7 @@ class Conveyer(CoreObject):
#outputs data to "output.xls"
def outputResultsXL(self, MaxSimtime=None):
from Globals import G
from Globals import getConfidenceIntervals
if MaxSimtime==None:
MaxSimtime=G.maxSimTime
if(G.numberOfReplications==1): #if we had just one replication output the results to excel
......@@ -314,21 +315,21 @@ class Conveyer(CoreObject):
#so for each output value we check if there was difference in the runs' results
#if yes we output the Confidence Intervals. if not we output just the fix value
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Working of "+self.objName +" is:")
working_ci = self.getConfidenceIntervals(self.Working)
working_ci = getConfidenceIntervals(self.Working)
G.outputSheet.write(G.outputIndex, 1, working_ci['min'])
G.outputSheet.write(G.outputIndex, 2, working_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, working_ci['max'])
G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Blockage of "+ self.objName+" is:")
blockage_ci = self.getConfidenceIntervals(self.Blockage)
blockage_ci = getConfidenceIntervals(self.Blockage)
G.outputSheet.write(G.outputIndex, 1, blockage_ci['min'])
G.outputSheet.write(G.outputIndex, 2, blockage_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, blockage_ci['max'])
G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Waiting of "+ self.objName+" is:")
waiting_ci = self.getConfidenceIntervals(self.Waiting)
waiting_ci = getConfidenceIntervals(self.Waiting)
G.outputSheet.write(G.outputIndex, 1, waiting_ci['min'])
G.outputSheet.write(G.outputIndex, 2, waiting_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, waiting_ci['max'])
......@@ -338,6 +339,7 @@ class Conveyer(CoreObject):
#outputs results to JSON File
def outputResultsJSON(self):
from Globals import G
from Globals import getConfidenceIntervals
json = {'_class': self.class_name,
'id': self.id,
'results': {}}
......@@ -347,9 +349,9 @@ class Conveyer(CoreObject):
json['results']['blockage_ratio']=100*self.totalBlockageTime/G.maxSimTime
json['results']['waiting_ratio']=100*self.totalWaitingTime/G.maxSimTime
else:
json['results']['working_ratio'] = self.getConfidenceIntervals(self.Working)
json['results']['blockage_ratio'] = self.getConfidenceIntervals(self.Blockage)
json['results']['waiting_ratio'] = self.getConfidenceIntervals(self.Waiting)
json['results']['working_ratio'] = getConfidenceIntervals(self.Working)
json['results']['blockage_ratio'] = getConfidenceIntervals(self.Blockage)
json['results']['waiting_ratio'] = getConfidenceIntervals(self.Waiting)
G.outputJSON['elementList'].append(json)
......
......@@ -310,21 +310,6 @@ class CoreObject(Process):
def sortEntities(self):
pass
# =======================================================================
# Helper method to calculate the min, max and average values of a serie
# =======================================================================
def getConfidenceIntervals(self, value_list):
from Globals import G
if len(set(value_list)) == 1:
# All values are same, no need to perform statistical analysis
return { 'min': value_list[0],
'max': value_list[0],
'avg': value_list[0], }
bayes_mvs = stat.bayes_mvs(value_list, G.confidenceLevel)
return { 'min': bayes_mvs[0][1][0],
'max': bayes_mvs[0][1][1],
'avg': bayes_mvs[0][0], }
# =======================================================================
# get the active object. This always returns self
# =======================================================================
......
......@@ -281,6 +281,7 @@ class Dismantle(CoreObject):
# =======================================================================
def outputResultsXL(self, MaxSimtime=None):
from Globals import G
from Globals import getConfidenceIntervals
if MaxSimtime==None:
MaxSimtime=G.maxSimTime
if(G.numberOfReplications==1): #if we had just one replication output the results to excel
......@@ -295,21 +296,21 @@ class Dismantle(CoreObject):
G.outputIndex+=1
else:
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Working of "+ self.objName+" is:")
working_ci = self.getConfidenceIntervals(self.Working)
working_ci = getConfidenceIntervals(self.Working)
G.outputSheet.write(G.outputIndex, 1, working_ci['min'])
G.outputSheet.write(G.outputIndex, 2, working_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, working_ci['max'])
G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Blockage of "+ self.objName+" is:")
blockage_ci = self.getConfidenceIntervals(self.Blockage)
blockage_ci = getConfidenceIntervals(self.Blockage)
G.outputSheet.write(G.outputIndex, 1, blockage_ci['min'])
G.outputSheet.write(G.outputIndex, 2, blockage_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, blockage_ci['max'])
G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Waiting of "+ self.objName+" is:")
waiting_ci = self.getConfidenceIntervals(self.Waiting)
waiting_ci = getConfidenceIntervals(self.Waiting)
G.outputSheet.write(G.outputIndex, 1, waiting_ci['min'])
G.outputSheet.write(G.outputIndex, 2, waiting_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, waiting_ci['max'])
......@@ -321,6 +322,7 @@ class Dismantle(CoreObject):
# =======================================================================
def outputResultsJSON(self):
from Globals import G
from Globals import getConfidenceIntervals
json = {'_class': self.class_name,
'id': self.id,
'results': {}}
......@@ -329,7 +331,7 @@ class Dismantle(CoreObject):
json['results']['blockage_ratio']=100*self.totalBlockageTime/G.maxSimTime
json['results']['waiting_ratio']=100*self.totalWaitingTime/G.maxSimTime
else:
json['results']['working_ratio'] = self.getConfidenceIntervals(self.Working)
json['results']['blockage_ratio'] = self.getConfidenceIntervals(self.Blockage)
json['results']['waiting_ratio'] = self.getConfidenceIntervals(self.Waiting)
json['results']['working_ratio'] = getConfidenceIntervals(self.Working)
json['results']['blockage_ratio'] = getConfidenceIntervals(self.Blockage)
json['results']['waiting_ratio'] = getConfidenceIntervals(self.Waiting)
G.outputJSON['elementList'].append(json)
......@@ -29,6 +29,7 @@ from SimPy.Simulation import now, Process, Resource, infinity, waituntil
import xlwt
import scipy.stats as stat
from CoreObject import CoreObject
# ===========================================================================
# The exit object
# ===========================================================================
......@@ -148,6 +149,7 @@ class Exit(CoreObject):
# =======================================================================
def outputResultsXL(self, MaxSimtime=None):
from Globals import G
from Globals import getConfidenceIntervals
if MaxSimtime==None:
MaxSimtime=G.maxSimTime
if(G.numberOfReplications==1): #if we had just one replication output the results to excel
......@@ -172,21 +174,21 @@ class Exit(CoreObject):
#so for each output value we check if there was difference in the runs' results
#if yes we output the Confidence Intervals. if not we output just the fix value
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean Throughput in " +self.objName + " is:")
throughput_ci = self.getConfidenceIntervals(self.Exits)
throughput_ci = getConfidenceIntervals(self.Exits)
G.outputSheet.write(G.outputIndex, 1, throughput_ci['min'])
G.outputSheet.write(G.outputIndex, 2, throughput_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, throughput_ci['max'])
G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean Lifespan of an entity that exited from "+ self.objName + " is:")
lifespan_ci = self.getConfidenceIntervals(self.Lifespan)
lifespan_ci = getConfidenceIntervals(self.Lifespan)
G.outputSheet.write(G.outputIndex, 1, lifespan_ci['min'])
G.outputSheet.write(G.outputIndex, 2, lifespan_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, lifespan_ci['max'])
G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the avg takt time in "+ self.objName + " is:")
takt_time_ci = self.getConfidenceIntervals(self.TaktTime)
takt_time_ci = getConfidenceIntervals(self.TaktTime)
G.outputSheet.write(G.outputIndex, 1, takt_time_ci['min'])
G.outputSheet.write(G.outputIndex, 2, takt_time_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, takt_time_ci['max'])
......@@ -197,6 +199,7 @@ class Exit(CoreObject):
# =======================================================================
def outputResultsJSON(self):
from Globals import G
from Globals import getConfidenceIntervals
json = { '_class': self.class_name,
'id': self.id,
'results': {} }
......@@ -210,10 +213,10 @@ class Exit(CoreObject):
json['results']['lifespan']=self.Lifespan[0]
json['results']['takt_time']=self.TaktTime[0]
else:
json['results']['throughput'] = self.getConfidenceIntervals(self.Exits)
json['results']['lifespan'] = self.getConfidenceIntervals(self.Lifespan)
json['results']['takt_time'] = self.getConfidenceIntervals(self.TaktTime)
json['results']['throughput'] = getConfidenceIntervals(self.Exits)
json['results']['lifespan'] = getConfidenceIntervals(self.Lifespan)
json['results']['takt_time'] = getConfidenceIntervals(self.TaktTime)
if self.Exits!=self.UnitExits: #output this only if there was variability in units
json['results']['unitsThroughput'] = self.getConfidenceIntervals(self.UnitExits)
json['results']['unitsThroughput'] = getConfidenceIntervals(self.UnitExits)
G.outputJSON['elementList'].append(json)
......@@ -202,3 +202,19 @@ def countQueueMetrics(argumentDict={}):
if isinstance(obj, Queue):
obj.wip_stat_list.append((now(), len(obj.Res.activeQ)))
# =======================================================================
# Helper function to calculate the min, max and average values of a serie
# =======================================================================
def getConfidenceIntervals(value_list):
from Globals import G
if len(set(value_list)) == 1:
# All values are same, no need to perform statistical analysis
return { 'min': value_list[0],
'max': value_list[0],
'avg': value_list[0], }
bayes_mvs = stat.bayes_mvs(value_list, G.confidenceLevel)
return { 'min': bayes_mvs[0][1][0],
'max': bayes_mvs[0][1][1],
'avg': bayes_mvs[0][0], }
......@@ -858,6 +858,7 @@ class Machine(CoreObject):
# =======================================================================
def outputResultsXL(self, MaxSimtime=None):
from Globals import G
from Globals import getConfidenceIntervals
if MaxSimtime==None:
MaxSimtime=G.maxSimTime
......@@ -881,28 +882,28 @@ class Machine(CoreObject):
#if yes we output the Confidence Intervals. if not we output just the fix value
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Failure of "+ self.objName+" is:")
failure_ci = self.getConfidenceIntervals(self.Failure)
failure_ci = getConfidenceIntervals(self.Failure)
G.outputSheet.write(G.outputIndex, 1, failure_ci['min'])
G.outputSheet.write(G.outputIndex, 2, failure_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, failure_ci['max'])
G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Working of "+ self.objName+" is:")
working_ci = self.getConfidenceIntervals(self.Working)
working_ci = getConfidenceIntervals(self.Working)
G.outputSheet.write(G.outputIndex, 1, working_ci['min'])
G.outputSheet.write(G.outputIndex, 2, working_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, working_ci['max'])
G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Blockage of "+ self.objName+" is:")
blockage_ci = self.getConfidenceIntervals(self.Blockage)
blockage_ci = getConfidenceIntervals(self.Blockage)
G.outputSheet.write(G.outputIndex, 1, blockage_ci['min'])
G.outputSheet.write(G.outputIndex, 2, blockage_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, blockage_ci['max'])
G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Waiting of "+ self.objName+" is:")
waiting_ci = self.getConfidenceIntervals(self.Waiting)
waiting_ci = getConfidenceIntervals(self.Waiting)
G.outputSheet.write(G.outputIndex, 1, waiting_ci['min'])
G.outputSheet.write(G.outputIndex, 2, waiting_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, waiting_ci['max'])
......@@ -914,6 +915,7 @@ class Machine(CoreObject):
# =======================================================================
def outputResultsJSON(self):
from Globals import G
from Globals import getConfidenceIntervals
json = {'_class': self.class_name,
'id': self.id,
'results': {}}
......@@ -931,13 +933,13 @@ class Machine(CoreObject):
if any(type=='Load' for type in self.multOperationTypeList):
json['results']['load_ratio']=100*self.totalLoadTime/G.maxSimTime
else:
json['results']['failure_ratio'] = self.getConfidenceIntervals(self.Failure)
json['results']['working_ratio'] = self.getConfidenceIntervals(self.Working)
json['results']['blockage_ratio'] = self.getConfidenceIntervals(self.Blockage)
json['results']['waiting_ratio'] = self.getConfidenceIntervals(self.Waiting)
json['results']['off_shift_ratio'] = self.getConfidenceIntervals(self.OffShift)
json['results']['setup_ratio'] = self.getConfidenceIntervals(self.SettingUp)
json['results']['loading_ratio'] = self.getConfidenceIntervals(self.Loading)
json['results']['failure_ratio'] = getConfidenceIntervals(self.Failure)
json['results']['working_ratio'] = getConfidenceIntervals(self.Working)
json['results']['blockage_ratio'] = getConfidenceIntervals(self.Blockage)
json['results']['waiting_ratio'] = getConfidenceIntervals(self.Waiting)
json['results']['off_shift_ratio'] = getConfidenceIntervals(self.OffShift)
json['results']['setup_ratio'] = getConfidenceIntervals(self.SettingUp)
json['results']['loading_ratio'] = getConfidenceIntervals(self.Loading)
G.outputJSON['elementList'].append(json)
......@@ -74,6 +74,7 @@ class Repairman(ObjectResource):
# =======================================================================
def outputResultsXL(self, MaxSimtime=None):
from Globals import G
from Globals import getConfidenceIntervals
if MaxSimtime==None:
MaxSimtime=G.maxSimTime
# if we had just one replication output the results to excel
......@@ -91,14 +92,14 @@ class Repairman(ObjectResource):
# if yes we output the Confidence Intervals. if not we output just the fix value
else:
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Working of "+ self.objName+" is:")
working_ci = self.getConfidenceIntervals(self.Working)
working_ci = getConfidenceIntervals(self.Working)
G.outputSheet.write(G.outputIndex, 1, working_ci['min'])
G.outputSheet.write(G.outputIndex, 2, working_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, working_ci['max'])
G.outputIndex+=1
G.outputSheet.write(G.outputIndex,0, "CI "+str(G.confidenceLevel*100)+"% for the mean percentage of Waiting of "+ self.objName+" is:")
waiting_ci = self.getConfidenceIntervals(self.Waiting)
waiting_ci = getConfidenceIntervals(self.Waiting)
G.outputSheet.write(G.outputIndex, 1, waiting_ci['min'])
G.outputSheet.write(G.outputIndex, 2, waiting_ci['avg'])
G.outputSheet.write(G.outputIndex, 3, waiting_ci['max'])
......@@ -110,6 +111,7 @@ class Repairman(ObjectResource):
# =======================================================================
def outputResultsJSON(self):
from Globals import G
from Globals import getConfidenceIntervals
json = {'_class': self.class_name,
'id': self.id,
'results': {}}
......@@ -117,6 +119,6 @@ class Repairman(ObjectResource):
json['results']['working_ratio']=100*self.totalWorkingTime/G.maxSimTime
json['results']['waiting_ratio']=100*self.totalWaitingTime/G.maxSimTime
else:
json['results']['working_ratio'] = self.getConfidenceIntervals(self.Working)
json['results']['waiting_ratio'] = self.getConfidenceIntervals(self.Waiting)
json['results']['working_ratio'] = getConfidenceIntervals(self.Working)
json['results']['waiting_ratio'] = getConfidenceIntervals(self.Waiting)
G.outputJSON['elementList'].append(json)
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