Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
---------------
para : list or str
if para is list, return itself, if para is str starts with "< " and
follows by a file name, load the parameters in the txt
Returns
para : lsit
a list of parameters
--------------
"""
if isinstance(para, str) and para.startswith('< '):
f_name = para.split('< ')[0]
return loadtxt(f_name)
return para
class NNode(Node):
""" Normal Node
Parameters
---------------
ipdests : list of str
ip table for the node
node_seq : int
id of the node
Attributes
----------------
ipdests : list of str
ip table for the node
node_seq : int
id of the node
mod_num : int
}
if use_urls:
node_seed_shape = 'rectangle'
node_shape = 'oval'
else:
node_seed_shape = 'square'
node_shape = 'circle'
node_args.update({
"fixedsize": node_fixedsize,
"width": node_width,
"height": node_height,
})
graph.set_node_defaults(**node_args)
for page in self.pages:
graph.add_node(pydot.Node(name=self._clean_page_name(page, include_id=include_ids),
fontname=fontname,
fontsize=node_fontsize,
shape=node_seed_shape if page.is_seed else node_shape))
for link in page.links:
graph.add_edge(pydot.Edge(self._clean_page_name(page, include_id=include_ids),
self._clean_page_name(link, include_id=include_ids)))
graph.write_png(filename)
def makeendnode(name):
return pydot.Node(name, shape="doubleoctagon", label=name,
style="filled", fillcolor="#e4e4e4")
style = op_node_style
# Check if we should override the style of this node.
if styles is not None and op_node[0] in styles:
style = styles[op_node[0]]
pydot_graph.add_node(pydot.Node(op_node[0], **style, label="\n".join(op_node)))
for data_node in data_nodes:
pydot_graph.add_node(pydot.Node(data_node[0], label="\n".join(data_node[1:])))
node_style = {'shape': 'oval',
'fillcolor': 'gray',
'style': 'rounded, filled'}
if param_nodes is not None:
for param_node in param_nodes:
pydot_graph.add_node(pydot.Node(param_node[0], **node_style, label="\n".join(param_node[1:])))
for edge in edges:
pydot_graph.add_edge(pydot.Edge(edge[0], edge[1]))
return pydot_graph
return self.py_dot_graph
if self.__isCompartments():
return self.py_dot_graph
if self.__isSpecies():
return self.py_dot_graph
compart_dict = self.__createCompartmentDict()
#Add the species into a compartment
for i, sp in enumerate(self.m.getListOfSpecies()):
node_attribute = self.specieNode(i+1)
compart_dict[sp.getCompartment()][1].add_node(
pydot.Node(sp.getId(), **node_attribute))
for i, reaction in enumerate(self.m.getListOfReactions()):
node_attribute = self.reactionNode(i+1)
for j, sp_ref in enumerate(reaction.getListOfReactants()):
if j == 0 and self.__addReactionToCompartment(sp_ref):
compart_dict[sp.getCompartment()][1].add_node(
pydot.Node(reaction.getId(), **node_attribute))
# stoc = int(sp_ref.getStoichiometry()) # brett 20050702
stoc = sp_ref.getStoichiometry() # brett 20050702: allow for non-int stoich
edge_attribute = self.edgeNode(reaction, stoc).reactant()
edge = pydot.Edge(sp_ref.getSpecies(),
reaction.getId(), **edge_attribute)
self.add_edge(edge)
def buildNode(self,dimName,objtName):
objtUrl = dimName + '#' + objtName
if (dimName == 'persona'):
objt = self.dbProxy.dimensionObject(objtName,'persona')
if (objt.assumption() == True):
objtLabel = "<<Assumption>>" + objtName
self.theGraph.add_node(pydot.Node(objtName,label=objtLabel,shape='ellipse',fontname=self.fontName,fontsize=self.fontSize,URL=objtUrl))
else:
self.theGraph.add_node(pydot.Node(objtName,shape='ellipse',fontname=self.fontName,fontsize=self.fontSize,URL=objtUrl))
elif (dimName == 'goalconcern' or dimName == 'taskconcern'):
self.theGraph.add_node(pydot.Node(objtName,shape='note',fontname=self.fontName,fontsize=self.fontSize,fontcolor='blue',color='blue',URL=objtUrl))
elif (dimName == 'obstacleconcern'):
self.theGraph.add_node(pydot.Node(objtName,shape='note',fontname=self.fontName,fontsize=self.fontSize,fontcolor='red',color='red',URL=objtUrl))
else:
assetObjt = self.dbProxy.dimensionObject(objtName,dimName)
borderColour = 'black'
if (dimName == 'asset' and assetObjt.critical()):
borderColour = 'red'
if (dimName == 'template_asset' and self.isComponentAssetModel):
stScore = self.dbProxy.templateAssetMetrics(objtName)
assetNode = pydot.Node(objtName,shape='record',style='filled',fillcolor=surfaceTypeColourCode(stScore),fontcolor=surfaceTypeTextColourCode(stScore),fontname=self.fontName,fontsize=self.fontSize,URL=objtUrl)
else:
assetNode = pydot.Node(objtName,shape='record',color=borderColour,fontname=self.fontName,fontsize=self.fontSize,URL=objtUrl)
self.theGraph.add_node(assetNode)
self.nodeList.add(objtName)
def buildNode(self,dimName,objtName):
objtUrl = dimName + '#' + str(objtName)
if (dimName == 'task'):
self.theGraph.add_node(pydot.Node(objtName,shape='ellipse',margin=0,fontname=self.fontName,fontsize=self.fontSize,URL=objtUrl))
elif (dimName == 'domainproperty'):
self.theGraph.add_node(pydot.Node(objtName,shape='house',margin=0,fontname=self.fontName,fontsize=self.fontSize,URL=objtUrl))
elif (dimName == 'task_characteristic'):
self.theGraph.add_node(pydot.Node(objtName,shape='record',margin=0,fontname=self.fontName,style='filled',fillcolor='green',fontsize=self.fontSize,URL=objtUrl))
elif (dimName == 'rebuttal'):
self.theGraph.add_node(pydot.Node(objtName,shape='record',margin=0,fontname=self.fontName,style='filled',fillcolor='red',fontcolor='white',fontsize=self.fontSize,URL=objtUrl))
elif (dimName == 'qualifier'):
self.theGraph.add_node(pydot.Node(objtName,shape='rectangle',margin=0,fontname=self.fontName,style='dashed',fontsize=self.fontSize,URL=objtUrl))
elif (dimName == 'warrant'):
self.theGraph.add_node(pydot.Node(objtName,shape='record',margin=0,fontname=self.fontName,style='filled',fillcolor='darkslategray3',fontsize=self.fontSize,URL=objtUrl))
elif (dimName == 'backing'):
self.theGraph.add_node(pydot.Node(objtName,shape='record',margin=0,fontname=self.fontName,style='filled',fillcolor='gray95',fontsize=self.fontSize,URL=objtUrl))
elif (dimName == 'grounds'):
self.theGraph.add_node(pydot.Node(objtName,shape='record',margin=0,fontname=self.fontName,fontsize=self.fontSize,URL=objtUrl))
else:
self.theGraph.add_node(pydot.Node(objtName,shape='point',fontname=self.fontName,label='',fontsize=self.fontSize))
def makeendnode(name):
name = escape_char(name, ':')
return pydot.Node(name, shape="doubleoctagon", label=name,
style="filled", fillcolor="#e4e4e4")
def buildNode(self,objtName,envName):
objtUrl = 'requirement#' + objtName
envLabel = envName.replace(' ','_')
if envName not in self.theClusters:
self.theClusters[envName] = pydot.Cluster(envLabel,label=str(envName))
reqObjt = self.dbProxy.dimensionObject(objtName,'requirement')
tScore = self.dbProxy.traceabilityScore(objtName)
fontColour = 'black'
if (reqObjt.priority() == 1):
if tScore != 3: fontColour = 1
n = pydot.Node(objtName,color=str(tScore),fontcolor=str(fontColour),URL=objtUrl)
if (self.cfSet == False):
n.obj_dict['attributes']['style'] = '"rounded,filled"'
self.theClusters[envName].add_node(n)
user_id = self._get_actor()
try:
import pydot
except ImportError:
raise ImportError("You need pydot library to get network functionality.")
graph = pydot.Dot('network_of_user_{}'.format(user_id), graph_type='digraph')
target_node = pydot.Node(user_id)
for _id in self(user_id).following():
user_node = pydot.Node(_id)
graph.add_edge(pydot.Edge(target_node, user_node))
for _id in self(user_id).followers():
user_node = pydot.Node(_id)
graph.add_edge(pydot.Edge(user_node, target_node))
graph.write_png(output)