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)
##Get from the above dictionaries the M1 key and define the following lists with data worksheets = workbook.sheet_names()
M1_ProcTime = ProcessingTimes.get('M1',[]) worksheet_ProcessingTimes = worksheets[0] #Define the worksheet with the Processing times data
M2_ProcTime = ProcessingTimes.get('M2',[])
inputData = Import_Excel() #Call the Python object Import_Excel
#Call the HandleMissingValues object and replace the missing values in the lists with the mean of the non-missing values ProcessingTimes = inputData.Input_data(worksheet_ProcessingTimes, workbook) #Create the Processing Times dictionary with key Machines 1,2 and values the processing time data
misValues =HandleMissingValues()
M1_ProcTime = misValues.ReplaceWithMean(M1_ProcTime) ##Get from the above dictionaries the M1 key and define the following lists with data
M2_ProcTime = misValues.ReplaceWithMean(M2_ProcTime) M1_ProcTime = ProcessingTimes.get('M1',[])
M2_ProcTime = ProcessingTimes.get('M2',[])
MLE = Distributions() #Call the Distributions object (Maximum Likelihood Estimation - MLE)
KS = DistFittest() #Call the DistFittest object (Kolmoghorov-Smirnov test) #Call the HandleMissingValues object and replace the missing values in the lists with the mean of the non-missing values
misValues =HandleMissingValues()
M1ProcTime_dist = KS.ks_test(M1_ProcTime) M1_ProcTime = misValues.ReplaceWithMean(M1_ProcTime)
M2ProcTime_dist = MLE.Normal_distrfit(M2_ProcTime) M2_ProcTime = misValues.ReplaceWithMean(M2_ProcTime)
MLE = Distributions() #Call the Distributions object (Maximum Likelihood Estimation - MLE)
#======================= Output preparation: output the updated values in the JSON file of this example ================================# 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 ================================#
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'
...@@ -70,19 +92,27 @@ data2=exportJSON.ProcessingTimes(data1, stationId2, M2ProcTime_dist) ...@@ -70,19 +92,27 @@ data2=exportJSON.ProcessingTimes(data1, stationId2, M2ProcTime_dist)
jsonFile = open('JSON_ParallelStations_Output.json',"w") #It opens the JSON file jsonFile = open('JSON_ParallelStations_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.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 ==========================#
# save the KE output in xls
export=Output()
# save KE results in Excel
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(M2_ProcTime,'M2_ProcTime_DistFitResults.xls')
#=================== Calling the ExcelOutput object, outputs the outcomes of the statistical analysis in xls files ==========================# # save the KE output in JSON
export=Output() jsonFile = open('JSON_ParallelStations_Output.json',"w") #It opens the JSON file
jsonFile.write(json.dumps(data, indent=True)) #It writes the updated data to the JSON file
jsonFile.close() #It closes the file
export.PrintStatisticalMeasures(M1_ProcTime,'M1_ProcTime_StatResults.xls') # save the simulation output
export.PrintStatisticalMeasures(M2_ProcTime,'M2_ProcTime_StatResults.xls') jsonFile = open('ManPyOutput.json',"w") #It opens the JSON file
jsonFile.write(simulationOutput) #It writes the updated data to the JSON file
export.PrintDistributionFit(M1_ProcTime,'M1_ProcTime_DistFitResults.xls') jsonFile.close() #It closes the file
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 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