Untitled
unknown
plain_text
a year ago
2.4 kB
5
Indexable
def get_edges(self, idx, data):
"""
Function to get pairs of statement which has edge between them
Input:
idx : idx of statement
data : DataFrame
Returns:
List of tuples
"""
st,ed = self.get_block_idx(idx, data)
df = data.iloc[st:ed+1]
edges_pair = []
for i,d in df.iterrows():
if pd.notna(d.Conditional_Seq):
from_node = tuple(df[df['Sequence'].astype('int')==int(float(d.Conditional_Seq))].iloc[0])
to_node = tuple(d)
edges_pair.append((from_node, to_node))
return edges_pair
data = pd.DataFrame(result['data'], dtype=str)
# st.title("BRE Target Flow")
nodes = []
edges = []
input_param_idx = data[data['Sequence'].astype(str) == str(st.query_params['seq_id'])].index.item()
result = bre_utils.get_edges(input_param_idx, data)
cond = [str(i) for i in data['Conditional_Seq'].to_list()]
# Create a Graphviz graph object with a tree layout
graph = graphviz.Digraph(format='png')
graph.attr(rankdir='TB', splines='ortho') # TB = Top-Bottom, splines='ortho' for orthogonal edges
graph.attr(size='30,30')
graph.attr(nodesep='0.5', ranksep='0.7') # Increase spacing between nodes and ranks
graph.attr(margin='1')
graph.attr(dpi='70')
for node in result:
graph.node(
str(node[0][0]),
label=str(node[0][1]),
shape='box',
width='3',
height='1',
fontsize='15pt'
)
if st.query_params['var_name'] in str(node[1]):
graph.node(
str(node[1][0]),
label=str(node[1][1]),
shape='box',
style="filled",
fillcolor="green",
width='5',
height='1',
fontsize='15pt'
)
else:
graph.node(
str(node[1][0]),
label=str(node[1][1]),
shape='box', # Use square boxes
width='3',
height='1',
fontsize='15pt' # Increase font size
)
graph.edge(str(node[0][0]), str(node[1][0]), edge_type='straight')
graph.format = 'png'
graph.render(filename='graph')
image = Image.open('graph.png')
with Image.open('graph.png') as img:
img_width, img_height = img.size
st.image(image, width=img_width)
Editor is loading...
Leave a Comment