In [15]:
import os
from performance_tools.digraph import Digraph

Digraph

Create Digraph from CSV file


In [3]:
filename = os.path.realpath(os.path.join(os.path.abspath(__file__), 'digraph.csv'))
dg = Digraph.from_csv(filename)

Digraph vertices


In [18]:
dg._vertices


Out[18]:
{'/', '/bar', '/foo', '/foo/bar', 'None'}

Digraph arcs


In [21]:
dg._arcs


Out[21]:
array([[0, 1, 0, 0, 1],
       [0, 0, 0, 0, 2],
       [1, 0, 0, 1, 0],
       [3, 1, 0, 0, 1],
       [0, 0, 0, 0, 0]], dtype=int8)

Draw Digraph using Graphviz


In [4]:
dg.draw('examples/digraph.pdf', relative_value=True)

Calculate all paths between two vertices


In [5]:
dg.all_paths('None', '/foo/bar')


Out[5]:
[['None', '/foo', '/bar', '/foo/bar'],
 ['None', '/foo', '/foo/bar'],
 ['None', '/', '/foo', '/bar', '/foo/bar'],
 ['None', '/', '/foo', '/foo/bar'],
 ['None', '/', '/bar', '/foo/bar'],
 ['None', '/', '/foo/bar']]

Draw all these paths in different files using Graphviz


In [6]:
dg.draw_all_paths('None', '/foo/bar', 'examples/digraph.pdf', relative_value=True)

Subgraph

Create subgraph from current digraph


In [16]:
vertices = {'None', '/', '/foo/bar'}
sub_dg = dg.subgraph(vertices)

Subgraph vertices


In [19]:
sub_dg._vertices


Out[19]:
{'/', '/foo/bar', 'None'}

Subgraph arcs


In [20]:
sub_dg._arcs


Out[20]:
array([[0, 1, 0],
       [0, 0, 1],
       [0, 0, 0]], dtype=int8)