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