Skip to content
Snippets Groups Projects
Commit 0d2c5dc6 authored by baigner's avatar baigner
Browse files

Added new functions to the VISTOS/KADMOS interface

- kadmosMakeAllVariablesValid
- kadmosRemoveUnusedOutputs
- kadmosL1Check, L2Check, L3Check
- kadmosUnmarkVariable


Former-commit-id: 41d33edb321d668ef402c9e2e7faca3f3d574300
parent 80c65366
No related branches found
No related tags found
No related merge requests found
Pipeline #192784 canceled
# Imports
import sys
import ast
import json
import logging
import os
......@@ -531,19 +533,16 @@ def kadmosGetPossibleFunctionOrder():
# Logs the error appropriately.
@app.route('/kadmosFinalizeFPG', methods=['POST'])
def kadmosFinalizeFPG():
@app.route('/kadmosMakeAllVariablesValid', methods=['POST'])
def kadmosMakeAllVariablesValid():
"""
Function to finalize the FPG. make all variables valid (or not, as requested by user) and add problem function roles
Function to make all variables from the graph valid --> Eliminates colissions
:param makeAllvariablesValid: Bool variable whether to make all variables valid or not (user input from VISTOMS)
:return: New VISTOMS json data with updated design competences
"""
try:
# get request form
graphID = request.form['graphID']
makeAllVariablesValid = request.form['makeAllVariablesValid']
remove_unused_outputs = request.form['removeUnusedOutputs']
function_order = request.form['currentOrder'].split(',')
path = app.config['UPLOAD_FOLDER']
......@@ -555,8 +554,6 @@ def kadmosFinalizeFPG():
graph = load(path + graphFileName, file_check_critical=False)
mpg = None
if isinstance(graph, FundamentalProblemGraph):
fpg = graph
else:
......@@ -566,14 +563,96 @@ def kadmosFinalizeFPG():
# Function to check the graph for collisions and holes. Collisions are solved based on the function order and holes
# will simply be removed.
if makeAllVariablesValid == "True":
fpg.make_all_variables_valid()
fpg.make_all_variables_valid()
# Add the graph with the updated function order to VISTOMS
newVistomsData = fpg.vistoms_add_json(vistoms_dir=app.config['VISTOMS_FOLDER'], function_order=function_order, graph_id=graphID, mpg=mpg)
# Save the graph in temp/tmp.kdms
fpg.save(app.config['UPLOAD_FOLDER'] + app.config['TEMP_FILE'] + '_' + graphID + '.kdms',
file_type='kdms', graph_check_critical=False, mpg=mpg)
return newVistomsData
except Exception as e:
return "ERROR: " + e.message
# Logs the error appropriately.
@app.route('/kadmosAddProblemFunctionRoles', methods=['POST'])
def kadmosAddProblemFunctionRoles():
"""
Function to Add the problem function roles to the graph
:return: New VISTOMS json data with updated design competences
"""
try:
# get request form
graphID = request.form['graphID']
function_order = request.form['currentOrder'].split(',')
if remove_unused_outputs == "True":
output_nodes = fpg.find_all_nodes(subcategory='all outputs')
for output_node in output_nodes:
if 'problem_role' not in fpg.node[output_node]:
fpg.remove_node(output_node)
path = app.config['UPLOAD_FOLDER']
graphFileName = app.config['TEMP_FILE'] + '_' + graphID + '.kdms'
mpgFileName = app.config['TEMP_FILE'] + '_' + graphID + '_mpg.kdms'
if os.path.exists(path + mpgFileName):
return ("ERROR: You cannot do that on an existing MPG! Please go back to the FPG or RCG to do so.")
else:
graph = load(path + graphFileName, file_check_critical=False)
mpg = None
if isinstance(graph, FundamentalProblemGraph):
fpg = graph
else:
fpg = FundamentalProblemGraph(graph)
fpg.graph['problem_formulation']['function_order'] = function_order
# Add the function problem roles (pre-coupling, coupled, post-coupling)
fpg.add_function_problem_roles()
# Add the graph with the updated function order to VISTOMS
newVistomsData = fpg.vistoms_add_json(vistoms_dir=app.config['VISTOMS_FOLDER'], function_order=function_order, graph_id=graphID, mpg=mpg)
# Save the graph in temp/tmp.kdms
fpg.save(app.config['UPLOAD_FOLDER'] + app.config['TEMP_FILE'] + '_' + graphID + '.kdms',
file_type='kdms', graph_check_critical=False, mpg=mpg)
return newVistomsData
except Exception as e:
return "ERROR: " + e.message
# Logs the error appropriately.
@app.route('/kadmosRemoveUnusedOutputs', methods=['POST'])
def kadmosRemoveUnusedOutputs():
"""
Function to remove all unused variables that are output to the coordinator
:return: New VISTOMS json data with updated design competences
"""
try:
# get request form
graphID = request.form['graphID']
function_order = request.form['currentOrder'].split(',')
path = app.config['UPLOAD_FOLDER']
graphFileName = app.config['TEMP_FILE'] + '_' + graphID + '.kdms'
mpgFileName = app.config['TEMP_FILE'] + '_' + graphID + '_mpg.kdms'
if os.path.exists(path + mpgFileName):
return ("ERROR: You cannot do that on an existing MPG! Please go back to the FPG or RCG to do so.")
else:
graph = load(path + graphFileName, file_check_critical=False)
mpg = None
if isinstance(graph, FundamentalProblemGraph):
fpg = graph
else:
fpg = FundamentalProblemGraph(graph)
fpg.graph['problem_formulation']['function_order'] = function_order
output_nodes = fpg.find_all_nodes(subcategory='all outputs')
for output_node in output_nodes:
if 'problem_role' not in fpg.node[output_node]:
fpg.remove_node(output_node)
# Add the function problem roles (pre-coupling, coupled, post-coupling)
......@@ -603,7 +682,12 @@ def kadmosFindAllNodes():
# Get request form
graphID = request.form['graphID']
category = str(request.form['category'])
subcategory = str(request.form['subcategory'])
sub_category = str(request.form['sub_category'])
attr_cond = ast.literal_eval(request.form['attr_cond'])
attr_include = ast.literal_eval(request.form['attr_include'])
attr_exclude = ast.literal_eval(request.form['attr_exclude'])
xPath_include = str(request.form['xPath_include']).split(', ')
xPath_exclude = str(request.form['xPath_exclude']).split(', ')
path = app.config['UPLOAD_FOLDER']
graphFileName = app.config['TEMP_FILE'] + '_' + graphID + '.kdms'
......@@ -615,9 +699,19 @@ def kadmosFindAllNodes():
graph = load(path + graphFileName, file_check_critical=False)
mpg = None
if attr_cond == []:
attr_cond = None
if attr_include == []:
attr_include = None
if attr_exclude == []:
attr_exclude = None
if xPath_include == [""]:
xPath_include = None
if xPath_exclude == [""]:
xPath_exclude = None
allNodes = graph.find_all_nodes(category=category,subcategory=sub_category,attr_cond=attr_cond,attr_include=attr_include,attr_exclude=attr_exclude,xpath_include=xPath_include,xpath_exclude=xPath_exclude)
allNodes = graph.find_all_nodes(category=category,subcategory=subcategory)
print allNodes
# allNodes_str = ', '.join(str(e) for e in allNodes)
allNodes_str = json.dumps(allNodes)
......@@ -628,10 +722,108 @@ def kadmosFindAllNodes():
# Logs the error appropriately.
@app.route('/kadmosL1Check', methods=['POST'])
def kadmosL1Check():
"""
Function to perform category a checks on the graph
:return: Message, whether the check was successful or not
"""
try:
# Get request form
graphID = request.form['graphID']
path = app.config['UPLOAD_FOLDER']
graphFileName = app.config['TEMP_FILE'] + '_' + graphID + '.kdms'
mpgFileName = app.config['TEMP_FILE'] + '_' + graphID + '_mpg.kdms'
if os.path.exists(path + mpgFileName):
graph = load(path + graphFileName, file_check_critical=False)
mpg = load(path + mpgFileName, file_check_critical=False)
else:
graph = load(path + graphFileName, file_check_critical=False)
mpg = None
check_result = graph._check_category_a()
if check_result[0] == True:
return ("Check successful!")
else:
return "ERROR: Check was not successful. For further information, please consult the python log"
except Exception as e:
return "ERROR: " + e.message
# Logs the error appropriately.
@app.route('/kadmosL2Check', methods=['POST'])
def kadmosL2Check():
"""
Function to perform category b checks on the graph
:return: Message, whether the check was successful or not
"""
try:
# Get request form
graphID = request.form['graphID']
path = app.config['UPLOAD_FOLDER']
graphFileName = app.config['TEMP_FILE'] + '_' + graphID + '.kdms'
mpgFileName = app.config['TEMP_FILE'] + '_' + graphID + '_mpg.kdms'
if os.path.exists(path + mpgFileName):
graph = load(path + graphFileName, file_check_critical=False)
mpg = load(path + mpgFileName, file_check_critical=False)
else:
graph = load(path + graphFileName, file_check_critical=False)
mpg = None
check_result = graph._check_category_b()
if check_result[0] == True:
return ("Check successful!")
else:
return "ERROR: Check was not successful. For further information, please consult the python log"
except Exception as e:
return "ERROR: " + e.message
# Logs the error appropriately.
@app.route('/kadmosL3Check', methods=['POST'])
def kadmosL3Check():
"""
Function to perform category c checks on the graph
:return: Message, whether the check was successful or not
"""
try:
# Get request form
graphID = request.form['graphID']
path = app.config['UPLOAD_FOLDER']
graphFileName = app.config['TEMP_FILE'] + '_' + graphID + '.kdms'
mpgFileName = app.config['TEMP_FILE'] + '_' + graphID + '_mpg.kdms'
if os.path.exists(path + mpgFileName):
graph = load(path + graphFileName, file_check_critical=False)
mpg = load(path + mpgFileName, file_check_critical=False)
else:
graph = load(path + graphFileName, file_check_critical=False)
mpg = None
check_result = graph._check_category_c()
if check_result[0] == True:
return ("Check successful!")
else:
return "ERROR: Check was not successful. For further information, please consult the python log"
except Exception as e:
return "ERROR: " + e.message
# Logs the error appropriately.
@app.route('/kadmosImposeMDAOArchitecture', methods=['POST'])
def kadmosImposeMDAOArchitecture():
"""
Function to wrap an MDAO architecture around the MDAO rpoblem
Function to wrap an MDAO architecture around the MDAO problem
:param allowUnconvergedCouplings: Bool variable whether unconverged couplings are allowed or not
:return: New VISTOMS json data with updated MDAO data and process graphs
......@@ -766,6 +958,42 @@ def kadmosMarkVariable():
return "ERROR: " + e.message
# Logs the error appropriately.
@app.route('/kadmosUnmarkVariable', methods=['POST'])
def kadmosUnmarkVariable():
try:
# get request form
graphID = request.form['graphID']
function_order = request.form['currentOrder'].split(',')
xPath = request.form['xPath']
path = app.config['UPLOAD_FOLDER']
graphFileName = app.config['TEMP_FILE']+'_'+graphID+'.kdms'
mpgFileName = app.config['TEMP_FILE']+'_'+graphID+'_mpg.kdms'
if os.path.exists(path + mpgFileName):
return ('ERROR: This function can only be performed on an FPG!')
else:
graph = load(path + graphFileName, file_check_critical=False)
mpg = None
if isinstance(graph, FundamentalProblemGraph):
fpg = graph
else:
fpg = FundamentalProblemGraph(graph)
fpg.unmark_variable(xPath)
# Add the graph with the updated function order to VISTOMS
newVistomsData = fpg.vistoms_add_json(vistoms_dir=app.config['VISTOMS_FOLDER'],function_order=function_order, graph_id=graphID, mpg=mpg)
# Save the graph in temp/tmp.kdms
fpg.save(app.config['UPLOAD_FOLDER'] + app.config['TEMP_FILE']+'_'+graphID+'.kdms', file_type='kdms', graph_check_critical=False,mpg=mpg)
return newVistomsData
except Exception as e:
return "ERROR: " + e.message
# Logs the error appropriately.
@app.route('/kadmosExportChangesToFile', methods=['POST'])
def kadmosExportChangesToFile():
try:
......@@ -816,7 +1044,7 @@ def kadmosSaveGraphTmp():
graphID = request.form['graphID']
newGraphName = request.form['newGraphName']
newGraphID = request.form['newGraphID']
function_order = request.form['currentOrder']
function_order = request.form['currentOrder'].split(',')
tmpDir = app.config['UPLOAD_FOLDER']
graphFileName = app.config['TEMP_FILE'] + '_' + graphID + '.kdms'
......@@ -832,7 +1060,7 @@ def kadmosSaveGraphTmp():
graph.graph['name'] = newGraphName
graph.save(app.config['UPLOAD_FOLDER'] + newFileName, file_type="kdms", graph_check_critical=False, mpg=mpg)
newVistomsData = graph.vistoms_add_json(vistoms_dir=app.config['VISTOMS_FOLDER'], function_order=function_order, graph_id=newGraphID, mpg=mpg)
newVistomsData = graph.vistoms_add_json(vistoms_dir=app.config['VISTOMS_FOLDER'], function_order=function_order,mpg=mpg, graph_id=newGraphID)
return newVistomsData
......
.attribute{
display: inline-block;
}
.panel-body {
background-color: white;
background-color:rgba(255,255,255,0.5);
max-width: 1100px;
max-height: 1000px;
overflow-x: auto;
......@@ -7,7 +10,7 @@
}
.myPanel {
background-color: white;
background-color:rgba(255,255,255,0.5);
}
a:link {
......@@ -213,7 +216,7 @@ pointer-events: none;
div.treeDiv {
position: absolute;
background-color: white;
background-color:rgba(255,255,255,0.5);
}
div.contextDiv {
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment