Commit b3f95f9f authored by panos's avatar panos

A test added in this example

parent 9d91378e
...@@ -22,71 +22,90 @@ Created on 4 Dec 2014 ...@@ -22,71 +22,90 @@ Created on 4 Dec 2014
# along with DREAM. If not, see <http://www.gnu.org/licenses/>. # along with DREAM. If not, see <http://www.gnu.org/licenses/>.
# =========================================================================== # ===========================================================================
from DistributionFitting import Distributions from dream.KnowledgeExtraction.DistributionFitting import Distributions
from DistributionFitting import DistFittest from dream.KnowledgeExtraction.DistributionFitting import DistFittest
from xml.etree import ElementTree as et from xml.etree import ElementTree as et
from Simul8XML import Simul8Output from dream.KnowledgeExtraction.Simul8XML import Simul8Output
from ImportCSVdata import Import_CSV from dream.KnowledgeExtraction.ImportCSVdata import Import_CSV
from ImportExceldata import Import_Excel from dream.KnowledgeExtraction.ImportExceldata import Import_Excel
import xlrd import xlrd
import os
def main(test=0, ExcelFileName='DataSet.xlsx',
CSVFileName='ProcTimesData.csv',
simul8XMLFileName='Topology1.xml',
workbook=None, csvFile=None, simul8XMLFile=None):
#================================= Extract the required data from the data files ==========================================# #================================= Extract the required data from the data files ==========================================#
filename = ("ProcTimesData.csv") if csvFile:
csv = Import_CSV() #call the Import_CSV module and using its method Input_data import the data set from the CSV file to the tool CSVFileName = csvFile.name
Data = csv.Input_data(filename) filename = CSVFileName
csv = Import_CSV() #call the Import_CSV module and using its method Input_data import the data set from the CSV file to the tool
Activity2_Proc = Data.get('Activity 2',[]) #get from the returned Python dictionary the two data sets Data = csv.Input_data(filename)
Activity3_Proc = Data.get('Activity 3',[])
Activity2_Proc = Data.get('Activity 2',[]) #get from the returned Python dictionary the two data sets
#Read from the given directory the Excel document with the data Activity3_Proc = Data.get('Activity 3',[])
workbook = xlrd.open_workbook('DataSet.xlsx')
worksheets = workbook.sheet_names() #Read from the given directory the Excel document with the data
worksheet_Inter = worksheets[0] #Define the worksheet with the Inter-arrivals time data if not workbook:
workbook = xlrd.open_workbook(os.path.join(os.path.dirname(os.path.realpath(__file__)), ExcelFileName))
data = Import_Excel() worksheets = workbook.sheet_names()
interTimes = data.Input_data(worksheet_Inter, workbook) #Create the Inter-arrival times dictionary with key the Source and values the inter-arrival time data worksheet_Inter = worksheets[0] #Define the worksheet with the Inter-arrivals time data
S1 = interTimes.get('Source',[]) data = Import_Excel()
interTimes = data.Input_data(worksheet_Inter, workbook) #Create the Inter-arrival times dictionary with key the Source and values the inter-arrival time data
#Read from the given directory the Excel document with the data
workbook = xlrd.open_workbook('DataSet.xlsx') S1 = interTimes.get('Source',[])
worksheets = workbook.sheet_names()
worksheet_Fail = worksheets[1] #Define the worksheet with the failures data (MTTF,MTTR) #Read from the given directory the Excel document with the data
worksheets = workbook.sheet_names()
data = Import_Excel() worksheet_Fail = worksheets[1] #Define the worksheet with the failures data (MTTF,MTTR)
failures = data.Input_data(worksheet_Fail, workbook) #Create the failures dictionary with key the MTTF and MTTR data points
data = Import_Excel()
MTTF = failures.get('MTTF',[]) failures = data.Input_data(worksheet_Fail, workbook) #Create the failures dictionary with key the MTTF and MTTR data points
MTTR = failures.get('MTTR',[])
MTTF = failures.get('MTTF',[])
#======================= Fit data to probability distributions ================================# MTTR = failures.get('MTTR',[])
#The Distributions and DistFittest objects are called to fit statistical distributions to the in scope data
dist = Distributions() #======================= Fit data to probability distributions ================================#
act2Proc = dist.Weibull_distrfit(Activity2_Proc) #The Distributions and DistFittest objects are called to fit statistical distributions to the in scope data
act3Proc = dist.Weibull_distrfit(Activity3_Proc) dist = Distributions()
act2Proc = dist.Weibull_distrfit(Activity2_Proc)
s1Times = dist.Exponential_distrfit(S1) act3Proc = dist.Weibull_distrfit(Activity3_Proc)
distFit = DistFittest() s1Times = dist.Exponential_distrfit(S1)
act1MTTF = distFit.ks_test(MTTF)
act1MTTR = distFit.ks_test(MTTR) distFit = DistFittest()
act1MTTF = distFit.ks_test(MTTF)
#======================= Output preparation: output the updated values in the XML file of this example ================================# act1MTTR = distFit.ks_test(MTTR)
datafile = ('Topology1.xml') #define the input xml file #======================= Output preparation: output the updated values in the XML file of this example ================================#
tree = et.parse(datafile)
simul8 = Simul8Output() #Call the Simul8Output object if not simul8XMLFile:
#Assign the statistical distribution calculated above in the XML file using methods of the Simul8Output object datafile=(os.path.join(os.path.dirname(os.path.realpath(__file__)), simul8XMLFileName)) #It defines the name or the directory of the XML file
interTimes = simul8.InterArrivalTime(tree,'Source', s1Times) tree = et.parse(datafile)
else:
procTimes2 = simul8.ProcTimes(interTimes,'Activity 2', act2Proc) datafile=simul8XMLFile
procTimes3 = simul8.ProcTimes(procTimes2,'Activity 3', act3Proc) tree = et.parse(datafile)
#Again assign the MTTF and MTTR probability distributions calling the relevant methods from the Simul8Output object simul8 = Simul8Output() #Call the Simul8Output object
MTTF1 = simul8.MTBF(procTimes3,'Activity 1', act1MTTF) #Assign the statistical distribution calculated above in the XML file using methods of the Simul8Output object
MTTR1 = simul8.MTTR(MTTF1,'Activity 1', act1MTTR ) interTimes = simul8.InterArrivalTime(tree,'Source', s1Times)
#Output the XML file with the processed data
output= MTTR1.write('KEtool_Topology1.xml') 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
MTTF1 = simul8.MTBF(procTimes3,'Activity 1', act1MTTF)
MTTR1 = simul8.MTTR(MTTF1,'Activity 1', act1MTTR)
#Output the XML file with the processed data
output= MTTR1.write('KEtool_Topology1.xml')
if test:
output=et.parse('KEtool_Topology1.xml')
return output
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