Commit aa01cbd5 authored by Georgios Dagkakis's avatar Georgios Dagkakis Committed by panos

examples changed to be able to run from test suite

parent daa3c284
...@@ -22,44 +22,66 @@ Created on 20 Jun 2014 ...@@ -22,44 +22,66 @@ Created on 20 Jun 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 DistFittest from dream.KnowledgeExtraction.DistributionFitting import DistFittest
from DistributionFitting import Distributions from dream.KnowledgeExtraction.DistributionFitting import Distributions
from ImportExceldata import Import_Excel from dream.KnowledgeExtraction.ImportExceldata import Import_Excel
from ExcelOutput import Output from dream.KnowledgeExtraction.ExcelOutput import Output
from ReplaceMissingValues import HandleMissingValues from dream.KnowledgeExtraction.ReplaceMissingValues import HandleMissingValues
from JSONOutput import JSONOutput from JSONOutput import JSONOutput
import xlrd import xlrd
import json import json
import dream.simulation.LineGenerationJSON as ManPyMain #import ManPy main JSON script import dream.simulation.LineGenerationJSON as ManPyMain #import ManPy main JSON script
#Read from the given directory the Excel document with the input data def main(test=0, ExcelFileName='KEtool_examples/TwoParallelStations/inputData.xls',
workbook = xlrd.open_workbook('inputData.xls') JSONFileName='KEtool_examples/TwoParallelStations/JSON_TwoParallelStations.json',
worksheets = workbook.sheet_names() workbook=None,
worksheet_ProcessingTimes = worksheets[0] #Define the worksheet with the Processing times data jsonFile=None):
inputData = Import_Excel() #Call the Python object Import_Excel #Read from the given directory the Excel document with the input data
ProcessingTimes = inputData.Input_data(worksheet_ProcessingTimes, workbook) #Create the Processing Times dictionary with key Machines 1,2 and values the processing time data if not workbook:
workbook = xlrd.open_workbook(ExcelFileName)
worksheets = workbook.sheet_names()
worksheet_ProcessingTimes = worksheets[0] #Define the worksheet with the Processing times data
##Get from the above dictionaries the M1 key and define the following lists with data inputData = Import_Excel() #Call the Python object Import_Excel
M1_ProcTime = ProcessingTimes.get('M1',[]) ProcessingTimes = inputData.Input_data(worksheet_ProcessingTimes, workbook) #Create the Processing Times dictionary with key Machines 1,2 and values the processing time data
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 ##Get from the above dictionaries the M1 key and define the following lists with data
misValues =HandleMissingValues() M1_ProcTime = ProcessingTimes.get('M1',[])
M1_ProcTime = misValues.ReplaceWithMean(M1_ProcTime) M2_ProcTime = ProcessingTimes.get('M2',[])
M2_ProcTime = misValues.ReplaceWithMean(M2_ProcTime)
MLE = Distributions() #Call the Distributions object (Maximum Likelihood Estimation - MLE) #Call the HandleMissingValues object and replace the missing values in the lists with the mean of the non-missing values
KS = DistFittest() #Call the DistFittest object (Kolmoghorov-Smirnov test) misValues =HandleMissingValues()
M1_ProcTime = misValues.ReplaceWithMean(M1_ProcTime)
M2_ProcTime = misValues.ReplaceWithMean(M2_ProcTime)
M1ProcTime_dist = KS.ks_test(M1_ProcTime) MLE = Distributions() #Call the Distributions object (Maximum Likelihood Estimation - MLE)
M2ProcTime_dist = MLE.Normal_distrfit(M2_ProcTime) 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 ================================#
#======================= Output preparation: output the updated values in the JSON file of this example ================================#
jsonFile = open('JSON_ParallelStations.json','r') #It opens the JSON file jsonFile = open('JSON_ParallelStations.json','r') #It opens the JSON file
data = json.load(jsonFile) #It loads the file jsonFile = open(JSONFileName,'r') #It opens the JSON file
jsonFile.close() data = json.load(jsonFile) #It loads the file
jsonFile.close()
else:
data = json.load(jsonFile)
nodes = data['graph']['node'] #It creates a variable that holds the 'nodes' dictionary
procTimeM1dict={}
procTimeM2dict={}
dist=M1ProcTime_dist['distributionType']
del M1ProcTime_dist['distributionType']
procTimeM1dict[dist]=M1ProcTime_dist
dist=M2ProcTime_dist['distributionType']
del M2ProcTime_dist['distributionType']
procTimeM2dict[dist]=M2ProcTime_dist
for element in nodes:
exportJSON=JSONOutput() exportJSON=JSONOutput()
stationId1='St1' stationId1='St1'
...@@ -71,18 +93,26 @@ jsonFile = open('JSON_ParallelStations_Output.json',"w") #It opens the JSON ...@@ -71,18 +93,26 @@ jsonFile = open('JSON_ParallelStations_Output.json',"w") #It opens the JSON
jsonFile.write(json.dumps(data2, indent=True)) #It writes the updated data to 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 jsonFile.close() #It closes the file
#=================== Calling the ExcelOutput object, outputs the outcomes of the statistical analysis in xls files ==========================# #=================== Calling the ExcelOutput object, outputs the outcomes of the statistical analysis in xls files ==========================#
export=Output() # save the KE output in xls
export=Output()
export.PrintStatisticalMeasures(M1_ProcTime,'M1_ProcTime_StatResults.xls') # save KE results in Excel
export.PrintStatisticalMeasures(M2_ProcTime,'M2_ProcTime_StatResults.xls') export.PrintStatisticalMeasures(M1_ProcTime,'M1_ProcTime_StatResults.xls')
export.PrintStatisticalMeasures(M2_ProcTime,'M2_ProcTime_StatResults.xls')
export.PrintDistributionFit(M1_ProcTime,'M1_ProcTime_DistFitResults.xls') export.PrintDistributionFit(M1_ProcTime,'M1_ProcTime_DistFitResults.xls')
export.PrintDistributionFit(M2_ProcTime,'M2_ProcTime_DistFitResults.xls') export.PrintDistributionFit(M2_ProcTime,'M2_ProcTime_DistFitResults.xls')
#calls ManPy main script with the input
simulationOutput=ManPyMain.main(input_data=json.dumps(data)) # save the KE output in JSON
# save the simulation output jsonFile = open('JSON_ParallelStations_Output.json',"w") #It opens the JSON file
jsonFile = open('ManPyOutput.json',"w") #It opens the JSON file jsonFile.write(json.dumps(data, indent=True)) #It writes the updated data to the JSON file
jsonFile.write(simulationOutput) #It writes the updated data to the JSON file jsonFile.close() #It closes the file
jsonFile.close() #It closes the file
# save the simulation output
jsonFile = open('ManPyOutput.json',"w") #It opens the JSON file
jsonFile.write(simulationOutput) #It writes the updated data to the JSON file
jsonFile.close() #It closes the file
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