Commit f0d08a38 authored by panos's avatar panos

A test created for this example

parent 88ad45f9
...@@ -29,49 +29,67 @@ from dream.KnowledgeExtraction.JSONOutput import JSONOutput ...@@ -29,49 +29,67 @@ from dream.KnowledgeExtraction.JSONOutput import JSONOutput
from dream.KnowledgeExtraction.DetectOutliers import HandleOutliers from dream.KnowledgeExtraction.DetectOutliers import HandleOutliers
from dream.KnowledgeExtraction.ReplaceMissingValues import HandleMissingValues from dream.KnowledgeExtraction.ReplaceMissingValues import HandleMissingValues
import json import json
import os
################### Import data using the ImportCSVdataobject ################################### ################### Import data using the ImportCSVdataobject ###################################
filename1=("DataSet.csv") def main(test=0, CSVFileName1='InterArrivalData.csv',
filename2=("InterArrivalData.csv") CSVFileName2='DataSet.csv',
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 JSONFileName='JSON_ConveyerLine.json',
procData=CSV.Input_data(filename1) jsonFile=None, csvFile1=None, csvFile2=None):
sourceData=CSV.Input_data(filename2) if csvFile2:
M1=procData.get('M1',[]) #get from the returned Python dictionary the data sets CSVFileName2 = csvFile2.name
M2=procData.get('M2',[]) if csvFile1:
S1=sourceData.get('S1',[]) CSVFileName1 = csvFile1.name
################### Processing of the data sets calling the following objects ################################### 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
#Replace missing values calling the corresponding object procData=CSV.Input_data(CSVFileName2)
missingValues=HandleMissingValues() sourceData=CSV.Input_data(CSVFileName1)
M1=missingValues.DeleteMissingValue(M1) M1=procData.get('M1',[]) #get from the returned Python dictionary the data sets
M2=missingValues.DeleteMissingValue(M2) M2=procData.get('M2',[])
S1=missingValues.ReplaceWithMean(S1) S1=sourceData.get('S1',[])
#Detect outliers calling the DetectOutliers object ################### Processing of the data sets calling the following objects ###################################
outliers=HandleOutliers() #Replace missing values calling the corresponding object
M1=outliers.DeleteExtremeOutliers(M1) missingValues=HandleMissingValues()
M2=outliers.DeleteExtremeOutliers(M2) M1=missingValues.DeleteMissingValue(M1)
S1=outliers.DeleteOutliers(S1) M2=missingValues.DeleteMissingValue(M2)
S1=missingValues.ReplaceWithMean(S1)
#Conduct distribution fitting calling the Distributions object and DistFittest object
MLE=Distributions() #Detect outliers calling the DetectOutliers object
KStest=DistFittest() outliers=HandleOutliers()
M1=KStest.ks_test(M1) M1=outliers.DeleteExtremeOutliers(M1)
M2=KStest.ks_test(M2) M2=outliers.DeleteExtremeOutliers(M2)
S1=MLE.Exponential_distrfit(S1) S1=outliers.DeleteOutliers(S1)
#================================= Output preparation: output the updated values in the JSON file of this example =========================================================#
jsonFile = open('JSON_ConveyerLine.json','r') #It opens the JSON file #Conduct distribution fitting calling the Distributions object and DistFittest object
data = json.load(jsonFile) #It loads the file MLE=Distributions()
jsonFile.close() KStest=DistFittest()
M1=KStest.ks_test(M1)
exportJSON=JSONOutput() M2=KStest.ks_test(M2)
stationId1='M1' S1=MLE.Exponential_distrfit(S1)
stationId2='M2' #================================= Output preparation: output the updated values in the JSON file of this example =========================================================#
stationId3='S1' if not jsonFile:
jsonFile = open(os.path.join(os.path.dirname(os.path.realpath(__file__)), JSONFileName),'r') #It opens the JSON file
data=exportJSON.ProcessingTimes(data, stationId1, M1) data = json.load(jsonFile) #It loads the file
data1=exportJSON.ProcessingTimes(data, stationId2, M2) jsonFile.close()
data2=exportJSON.InterarrivalTime(data1, stationId3, S1) else:
data = json.load(jsonFile)
jsonFile = open('JSON_ConveyerLine_Output.json',"w") #It opens the JSON file
jsonFile.write(json.dumps(data2, indent=True)) #It writes the updated data to the JSON file exportJSON=JSONOutput()
jsonFile.close() #It closes the file stationId1='M1'
\ No newline at end of file stationId2='M2'
stationId3='S1'
data=exportJSON.ProcessingTimes(data, stationId1, M1)
data1=exportJSON.ProcessingTimes(data, stationId2, M2)
data2=exportJSON.InterarrivalTime(data1, stationId3, S1)
# if we run from test return the data2
if test:
return data2
jsonFile = open('JSON_ConveyerLine_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
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