Commit 5e72b0ff authored by Jérome Perrin's avatar Jérome Perrin

Configure in the GUI the URL for KE data

parent 32110ef4
......@@ -20,6 +20,7 @@
import sys
import argparse
import json
import urllib
import xlrd
import traceback
import multiprocessing
......@@ -148,41 +149,44 @@ def getConfigurationDict():
def runKnowledgeExtraction():
parameter_dict = request.json['json']
# TODO: really run knowledge extraction and change values:
workbook = xlrd.open_workbook('dream/KnowledgeExtraction/Mockup_ProcessingTimes.xls') #Using xlrd library opens the Excel document with the input data
worksheets = workbook.sheet_names()
worksheet_ProcessingTimes = worksheets[0] #It defines the worksheet_ProcessingTimes as the first sheet of the Excel file
A=Import_Excel() #Call the Import_Excel object
B=DistFittest() #Call the Distribution Fitting object
ProcessingTimes= A.Input_data(worksheet_ProcessingTimes, workbook) #Create a dictionary with the imported data from the Excel file
data = parameter_dict #It loads the file
nodes = data['nodes']
lista=[]
for (element_id, element) in nodes.iteritems(): #This loop appends in a list the id's of the json file
element['id'] = element_id
lista.append(element ['id'])
for element in ProcessingTimes: #This loop searches the elements of the Excel imported data and if these elements exist in json file append the distribution fitting results in a dictionary
if element in lista:
fitDict=B.ks_test(ProcessingTimes[element])
aParameter=fitDict.get('aParameter')
bParameter=fitDict.get('bParameter')
distributionType=fitDict.get('distributionType')
aParameterValue=fitDict.get('aParameterValue')
bParameterValue=fitDict.get('bParameterValue')
dictToAdd={}
dictToAdd['distributionType']=distributionType
if aParameter:
dictToAdd[aParameter]=aParameterValue
if bParameter:
dictToAdd[bParameter]=bParameterValue
print dictToAdd
parameter_dict['nodes'][element]['processingTime']=dictToAdd
return jsonify(parameter_dict)
try:
workbook = xlrd.open_workbook(
file_contents=urllib.urlopen(parameter_dict['general']['ke_url']).read())
worksheets = workbook.sheet_names()
worksheet_ProcessingTimes = worksheets[0] #It defines the worksheet_ProcessingTimes as the first sheet of the Excel file
A=Import_Excel() #Call the Import_Excel object
B=DistFittest() #Call the Distribution Fitting object
ProcessingTimes= A.Input_data(worksheet_ProcessingTimes, workbook) #Create a dictionary with the imported data from the Excel file
data = parameter_dict #It loads the file
nodes = data['nodes']
lista=[]
for (element_id, element) in nodes.iteritems(): #This loop appends in a list the id's of the json file
element['id'] = element_id
lista.append(element ['id'])
for element in ProcessingTimes: #This loop searches the elements of the Excel imported data and if these elements exist in json file append the distribution fitting results in a dictionary
if element in lista:
fitDict=B.ks_test(ProcessingTimes[element])
aParameter=fitDict.get('aParameter')
bParameter=fitDict.get('bParameter')
distributionType=fitDict.get('distributionType')
aParameterValue=fitDict.get('aParameterValue')
bParameterValue=fitDict.get('bParameterValue')
dictToAdd={}
dictToAdd['distributionType']=distributionType
if aParameter:
dictToAdd[aParameter]=aParameterValue
if bParameter:
dictToAdd[bParameter]=bParameterValue
parameter_dict['nodes'][element]['processingTime']=dictToAdd
return jsonify(dict(success=True, data=parameter_dict))
except Exception, e:
tb = traceback.format_exc()
app.logger.error(tb)
return jsonify(dict(error=tb))
def main(*args):
parser = argparse.ArgumentParser(description='Launch the DREAM simulation platform.')
......
......@@ -252,11 +252,8 @@
that.prepareDialogForGeneralProperties();
};
/** Runs the simulation, and call the callback with results once the
* simulation is finished.
*/
that.runSimulation = function (callback) {
// handle Dream.General properties (in another function maybe ?)
that.readGeneralPropertiesDialog = function () {
// handle Dream.General properties
var prefix = "General-",
properties = {}, prefixed_property_id;
......@@ -271,7 +268,13 @@
}
});
that.setGeneralProperties(properties);
}
/** Runs the simulation, and call the callback with results once the
* simulation is finished.
*/
that.runSimulation = function (callback) {
that.readGeneralPropertiesDialog()
$.ajax(
'../runSimulation', {
data: JSON.stringify({
......@@ -285,6 +288,24 @@
});
};
/** Runs the knowledge extraction, and call the callback with results once the
* KE is finished.
*/
that.runKnowledgeExtraction = function (callback) {
that.readGeneralPropertiesDialog()
$.ajax(
'../runKnowledgeExtraction', {
data: JSON.stringify({
json: that.getData()
}),
contentType: 'application/json',
type: 'POST',
success: function (data, textStatus, jqXHR) {
callback(data);
}
});
};
that.displayResult = function (idx) {
var active_tab = $("#reports").data("ui-tabs") ?
$("#reports").tabs("option", "active") : 0;
......
......@@ -156,27 +156,21 @@
// Enable "Run Knowledge Extraction" button
$("#run_knowledge_extraction").button().click(
function (e) {
$("#run_knowledge_extraction").button('disable');
$("#ke_loading_spinner").show();
$.ajax(
'../runKnowledgeExtraction', {
data: JSON.stringify({
json: dream_instance.getData()
}),
contentType: 'application/json',
type: 'POST',
success: function (data, textStatus, jqXHR) {
loadData(data);
$("#ke_loading_spinner").hide();
$("#run_knowledge_extraction").button('enable');
},
error: function() {
$("#run_knowledge_extraction").button('disable');
$('#error').empty();
dream_instance.runKnowledgeExtraction(
function(data) {
$("#ke_loading_spinner").hide();
$("#run_knowledge_extraction").button('enable');
}
});
}
)
if (data['success']) {
loadData(data.data);
} else {
$("#error").text(data["error"]).show().effect('shake', 50);
console.error(data['error'])
}
});
});
// Enable "Run Simulation" button
$("#run_simulation").button().click(
......
......@@ -151,6 +151,17 @@ schema = {
"_class": "Dream.Property",
"_default": "",
},
"ke_url": {
"id": "ke_url",
"name": "URL for Knowledge Extraction Spreadsheet",
"description": "The URL for knowledge extraction to access its data"
" for example "
"http://git.erp5.org/gitweb/dream.git/blob_plain/HEAD:/dream/KnowledgeExtraction/Mockup_ProcessingTimes.xls",
"type": "string",
"_class": "Dream.Property",
"_default":
"http://git.erp5.org/gitweb/dream.git/blob_plain/HEAD:/dream/KnowledgeExtraction/Mockup_ProcessingTimes.xls",
},
"batchNumberOfUnits": {
"id": "batchNumberOfUnits",
"type": "number",
......@@ -319,6 +330,7 @@ class Simulation(object):
schema["currentDate"],
schema["trace"],
schema["seed"],
schema["ke_url"],
],
"gui": {
'debug_json': 1,
......
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