Commit 2bcb75b2 authored by Georgios Dagkakis's avatar Georgios Dagkakis

results outputted also in a JSON file

parent b6451406
...@@ -239,7 +239,18 @@ class Assembly(Process): ...@@ -239,7 +239,18 @@ class Assembly(Process):
G.outputIndex+=1 G.outputIndex+=1
G.outputIndex+=1 G.outputIndex+=1
#outputs results to JSON File
def outputResultsJSON(self):
from Globals import G
if(G.numberOfReplications==1): #if we had just one replication output the results to excel
json={}
json['_class'] = 'Dream.Assembly';
json['id'] = str(self.id)
json['results'] = {}
json['results']['working_ratio']=100*self.totalWorkingTime/G.maxSimTime
json['results']['blockage_ratio']=100*self.totalBlockageTime/G.maxSimTime
json['results']['waiting_ratio']=100*self.totalWaitingTime/G.maxSimTime
G.outputJSON['coreObject'].append(json)
#takes the array and checks if all its values are identical (returns false) or not (returns true) #takes the array and checks if all its values are identical (returns false) or not (returns true)
#needed because if somebody runs multiple runs in deterministic case it would crash! #needed because if somebody runs multiple runs in deterministic case it would crash!
......
...@@ -317,6 +317,18 @@ class Conveyer(Process): ...@@ -317,6 +317,18 @@ class Conveyer(Process):
G.outputIndex+=1 G.outputIndex+=1
G.outputIndex+=1 G.outputIndex+=1
#outputs results to JSON File
def outputResultsJSON(self):
from Globals import G
if(G.numberOfReplications==1): #if we had just one replication output the results to excel
json={}
json['_class'] = 'Dream.Conveyer';
json['id'] = str(self.id)
json['results'] = {}
json['results']['working_ratio']=100*self.totalWorkingTime/G.maxSimTime
json['results']['blockage_ratio']=100*self.totalBlockageTime/G.maxSimTime
json['results']['waiting_ratio']=100*self.totalWaitingTime/G.maxSimTime
G.outputJSON['coreObject'].append(json)
#takes the array and checks if all its values are identical (returns false) or not (returns true) #takes the array and checks if all its values are identical (returns false) or not (returns true)
#needed because if somebody runs multiple runs in deterministic case it would crash! #needed because if somebody runs multiple runs in deterministic case it would crash!
......
...@@ -273,6 +273,18 @@ class Dismantle(Process): ...@@ -273,6 +273,18 @@ class Dismantle(Process):
G.outputIndex+=1 G.outputIndex+=1
G.outputIndex+=1 G.outputIndex+=1
#outputs results to JSON File
def outputResultsJSON(self):
from Globals import G
if(G.numberOfReplications==1): #if we had just one replication output the results to excel
json={}
json['_class'] = 'Dream.Dismantle';
json['id'] = str(self.id)
json['results'] = {}
json['results']['working_ratio']=100*self.totalWorkingTime/G.maxSimTime
json['results']['blockage_ratio']=100*self.totalBlockageTime/G.maxSimTime
json['results']['waiting_ratio']=100*self.totalWaitingTime/G.maxSimTime
G.outputJSON['coreObject'].append(json)
#takes the array and checks if all its values are identical (returns false) or not (returns true) #takes the array and checks if all its values are identical (returns false) or not (returns true)
#needed because if somebody runs multiple runs in deterministic case it would crash! #needed because if somebody runs multiple runs in deterministic case it would crash!
......
...@@ -184,6 +184,19 @@ class Exit(Process): ...@@ -184,6 +184,19 @@ class Exit(Process):
G.outputIndex+=1 G.outputIndex+=1
G.outputIndex+=1 G.outputIndex+=1
#outputs results to JSON File
def outputResultsJSON(self):
from Globals import G
if(G.numberOfReplications==1): #if we had just one replication output the results to excel
json={}
json['_class'] = 'Dream.Exit';
json['id'] = str(self.id)
json['results'] = {}
json['results']['throughput']=self.numOfExits
json['results']['lifespan']=((self.totalLifespan)/self.numOfExits)/G.Base
json['results']['takt_time']=((self.totalTaktTime)/self.numOfExits)/G.Base
G.outputJSON['coreObject'].append(json)
#takes the array and checks if all its values are identical (returns false) or not (returns true) #takes the array and checks if all its values are identical (returns false) or not (returns true)
#needed because if somebody runs multiple runs in deterministic case it would crash! #needed because if somebody runs multiple runs in deterministic case it would crash!
def checkIfArrayHasDifValues(self, array): def checkIfArrayHasDifValues(self, array):
......
...@@ -36,9 +36,13 @@ class G: ...@@ -36,9 +36,13 @@ class G:
traceSheet = traceFile.add_sheet('sheet '+str(sheetIndex), cell_overwrite_ok=True) #create excel sheet traceSheet = traceFile.add_sheet('sheet '+str(sheetIndex), cell_overwrite_ok=True) #create excel sheet
#the output excel #variables for excel output
outputIndex=0 #index that shows in what row we are outputIndex=0 #index that shows in what row we are
sheetIndex=1 #index that shows in what sheet we are sheetIndex=1 #index that shows in what sheet we are
outputFile = xlwt.Workbook() #create excel file outputFile = xlwt.Workbook() #create excel file
outputSheet = outputFile.add_sheet('sheet '+str(sheetIndex), cell_overwrite_ok=True) #create excel sheet outputSheet = outputFile.add_sheet('sheet '+str(sheetIndex), cell_overwrite_ok=True) #create excel sheet
#variables for json output
outputJSON={}
outputJSONFile=None
...@@ -297,6 +297,10 @@ def main(argv=[]): ...@@ -297,6 +297,10 @@ def main(argv=[]):
for core_object in G.ObjList: for core_object in G.ObjList:
core_object.postProcessing(G.maxSimTime) core_object.postProcessing(G.maxSimTime)
#carry on the post processing operations for every model resource in the topology
for model_resource in G.RepairmanList:
model_resource.postProcessing(G.maxSimTime)
#output trace to excel #output trace to excel
if(G.trace=="Yes"): if(G.trace=="Yes"):
G.traceFile.save('trace'+str(i+1)+'.xls') G.traceFile.save('trace'+str(i+1)+'.xls')
...@@ -309,10 +313,42 @@ def main(argv=[]): ...@@ -309,10 +313,42 @@ def main(argv=[]):
G.outputSheet.write(G.outputIndex,1, str(time.time()-start)+" seconds") G.outputSheet.write(G.outputIndex,1, str(time.time()-start)+" seconds")
G.outputIndex+=2 G.outputIndex+=2
G.outputJSONFile=open('outputJSON.json', mode='w')
G.outputJSON['_class'] = 'Dream.Simulation';
G.outputJSON['general'] ={};
G.outputJSON['general']['_class'] = 'Dream.Configuration';
G.outputJSON['general']['totalExecutionTime'] = (time.time()-start);
G.outputJSON['modelResource'] =[];
G.outputJSON['coreObject'] =[];
#output data to JSON for every object in the topology
for core_object in G.ObjList:
try:
core_object.outputResultsJSON()
except AttributeError:
pass
#output data to JSON for every resource in the topology
for model_resource in G.RepairmanList:
try:
model_resource.outputResultsJSON()
except AttributeError:
pass
outputJSONString=str(str(G.outputJSON))
outputJSONString=outputJSONString.replace("'", '"')
G.outputJSONFile.write(str(outputJSONString))
#output data to excel for every object in the topology #output data to excel for every object in the topology
for core_object in G.ObjList: for core_object in G.ObjList:
core_object.outputResultsXL(G.maxSimTime) core_object.outputResultsXL(G.maxSimTime)
#output data to excel for every resource in the topology
for model_resource in G.RepairmanList:
model_resource.outputResultsXL(G.maxSimTime)
G.outputFile.save("output.xls") G.outputFile.save("output.xls")
print "execution time="+str(time.time()-start) print "execution time="+str(time.time()-start)
......
...@@ -13,6 +13,7 @@ from SimPy.Simulation import activate, passivate, waituntil, now, hold ...@@ -13,6 +13,7 @@ from SimPy.Simulation import activate, passivate, waituntil, now, hold
from Failure import Failure from Failure import Failure
from RandomNumberGenerator import RandomNumberGenerator from RandomNumberGenerator import RandomNumberGenerator
import scipy.stats as stat import scipy.stats as stat
import sys
#the Machine object #the Machine object
class Machine(Process): class Machine(Process):
...@@ -419,6 +420,20 @@ class Machine(Process): ...@@ -419,6 +420,20 @@ class Machine(Process):
G.outputIndex+=1 G.outputIndex+=1
G.outputIndex+=1 G.outputIndex+=1
#outputs results to JSON File
def outputResultsJSON(self):
from Globals import G
if(G.numberOfReplications==1): #if we had just one replication output the results to excel
json={}
json['_class'] = 'Dream.Machine';
json['id'] = str(self.id)
json['results'] = {}
json['results']['failure_ratio']=100*self.totalFailureTime/G.maxSimTime
json['results']['working_ratio']=100*self.totalWorkingTime/G.maxSimTime
json['results']['blockage_ratio']=100*self.totalBlockageTime/G.maxSimTime
json['results']['waiting_ratio']=100*self.totalWaitingTime/G.maxSimTime
G.outputJSON['coreObject'].append(json)
#takes the array and checks if all its values are identical (returns false) or not (returns true) #takes the array and checks if all its values are identical (returns false) or not (returns true)
#needed because if somebody runs multiple runs in deterministic case it would crash! #needed because if somebody runs multiple runs in deterministic case it would crash!
def checkIfArrayHasDifValues(self, array): def checkIfArrayHasDifValues(self, array):
......
...@@ -9,6 +9,7 @@ Models a FIFO queue where entities can wait in order to get into a server ...@@ -9,6 +9,7 @@ Models a FIFO queue where entities can wait in order to get into a server
from SimPy.Simulation import * from SimPy.Simulation import *
#import sys
#the Queue object #the Queue object
class Queue(Process): class Queue(Process):
...@@ -197,3 +198,7 @@ class Queue(Process): ...@@ -197,3 +198,7 @@ class Queue(Process):
#outputs data to "output.xls" #outputs data to "output.xls"
def outputResultsXL(self, MaxSimtime): def outputResultsXL(self, MaxSimtime):
pass pass
#outputs results to JSON File
def outputResultsJSON(self):
pass
\ No newline at end of file
...@@ -84,6 +84,17 @@ class Repairman(object): ...@@ -84,6 +84,17 @@ class Repairman(object):
G.outputIndex+=1 G.outputIndex+=1
G.outputIndex+=1 G.outputIndex+=1
#outputs results to JSON File
def outputResultsJSON(self):
from Globals import G
if(G.numberOfReplications==1): #if we had just one replication output the results to excel
json={}
json['_class'] = 'Dream.Repairman';
json['id'] = str(self.id)
json['results'] = {}
json['results']['working_ratio']=100*self.totalWorkingTime/G.maxSimTime
json['results']['waiting_ratio']=100*self.totalWaitingTime/G.maxSimTime
G.outputJSON['modelResource'].append(json)
#takes the array and checks if all its values are identical (returns false) or not (returns true) #takes the array and checks if all its values are identical (returns false) or not (returns true)
#needed because if somebody runs multiple runs in deterministic case it would crash! #needed because if somebody runs multiple runs in deterministic case it would crash!
......
...@@ -139,3 +139,7 @@ class Source(Process): ...@@ -139,3 +139,7 @@ class Source(Process):
#outputs data to "output.xls" #outputs data to "output.xls"
def outputResultsXL(self, MaxSimtime): def outputResultsXL(self, MaxSimtime):
pass pass
#outputs results to JSON File
def outputResultsJSON(self):
pass
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