Mir State

import graphviz as gv

g2 = gv.Digraph(format='svg')
g2.node('A')
g2.node('B')
g2.edge('A', 'B', '3')
g2

svg

diagram_comp = { 
  "statesArray": [
    { "id": 0, "text": "A",
      "mir": [{
        "content": "bass",
        "sfx.duration": "7.2",
        "lowlevel.hfc.mean": "* TO 0.0005",
        "lowlevel.spectral_complexity.mean": "1"
        }]
    },
    { "id": 1, "text": "B",
      "mir": [{
        "content": "bass",
        "sfx.duration": "* TO 5",
        "lowlevel.spectral_complexity.mean": "5"
        }]
    },
    { "id": 2, "text": "C",
      "mir": [{
        "tags": "hang",
        "content": "hang",
        "sfx.duration": "* TO 3",
        "sfx.inharmonicity.mean": "0.1"
        }]
    },
    { "id": 3, "text": "D", "duration": 23.4 },
    { "id": 4, "text": "E", "duration": 15.2 },
    { "id": 5, "text": "F", "duration": 12.76 },
    { "id": 6, "text": "G", "duration": 13.0 },
    { "id": 7, "text": "H", "duration": 23.1 }
  ],
  "linkArray": [
    { "from": 0, "to": 0, "text": "0.3"},
    { "from": 0, "to": 1, "text": "0.7" },
    { "from": 1, "to": 1, "text": "0.2" },
    { "from": 1, "to": 2, "text": "0.4" },
    { "from": 1, "to": 3, "text": "0.4" },
    { "from": 2, "to": 2, "text": "0.5" },
    { "from": 2, "to": 1, "text": "0.5" },
    { "from": 3, "to": 3, "text": "0.1" },
    { "from": 3, "to": 4, "text": "0.3" },
    { "from": 3, "to": 5, "text": "0.6" },
    { "from": 4, "to": 4, "text": "0.2" },
    { "from": 4, "to": 3, "text": "0.1" },
    { "from": 4, "to": 6, "text": "0.4" },
    { "from": 4, "to": 7, "text": "0.3" },
    { "from": 5, "to": 5, "text": "0.3" },
    { "from": 5, "to": 3, "text": "0.2" },
    { "from": 5, "to": 6, "text": "0.5" },
    { "from": 6, "to": 6, "text": "0.8" },
    { "from": 6, "to": 4, "text": "0.1" },
    { "from": 6, "to": 5, "text": "0.1" },
    { "from": 7, "to": 7, "text": "0.8" },
    { "from": 7, "to": 0, "text": "0.2" }
  ]
}
diagram_comp['statesArray']
[{'id': 0,
  'mir': [{'content': 'bass',
    'lowlevel.hfc.mean': '* TO 0.0005',
    'lowlevel.spectral_complexity.mean': '1',
    'sfx.duration': '7.2'}],
  'text': 'A'},
 {'id': 1,
  'mir': [{'content': 'bass',
    'lowlevel.spectral_complexity.mean': '5',
    'sfx.duration': '* TO 5'}],
  'text': 'B'},
 {'id': 2,
  'mir': [{'content': 'hang',
    'sfx.duration': '* TO 3',
    'sfx.inharmonicity.mean': '0.1',
    'tags': 'hang'}],
  'text': 'C'},
 {'duration': 23.4, 'id': 3, 'text': 'D'},
 {'duration': 15.2, 'id': 4, 'text': 'E'},
 {'duration': 12.76, 'id': 5, 'text': 'F'},
 {'duration': 13.0, 'id': 6, 'text': 'G'},
 {'duration': 23.1, 'id': 7, 'text': 'H'}]
state_diag = gv.Digraph(format='svg')
num_to_state = dict()
for state in diagram_comp['statesArray']:
    print( state['text'] )
    state_diag.node( state['text'] )
    num_to_state[ state['id'] ] = state['text']
A
B
C
D
E
F
G
H
diagram_comp['linkArray']
[{'from': 0, 'text': '0.3', 'to': 0},
 {'from': 0, 'text': '0.7', 'to': 1},
 {'from': 1, 'text': '0.2', 'to': 1},
 {'from': 1, 'text': '0.4', 'to': 2},
 {'from': 1, 'text': '0.4', 'to': 3},
 {'from': 2, 'text': '0.5', 'to': 2},
 {'from': 2, 'text': '0.5', 'to': 1},
 {'from': 3, 'text': '0.1', 'to': 3},
 {'from': 3, 'text': '0.3', 'to': 4},
 {'from': 3, 'text': '0.6', 'to': 5},
 {'from': 4, 'text': '0.2', 'to': 4},
 {'from': 4, 'text': '0.1', 'to': 3},
 {'from': 4, 'text': '0.4', 'to': 6},
 {'from': 4, 'text': '0.3', 'to': 7},
 {'from': 5, 'text': '0.3', 'to': 5},
 {'from': 5, 'text': '0.2', 'to': 3},
 {'from': 5, 'text': '0.5', 'to': 6},
 {'from': 6, 'text': '0.8', 'to': 6},
 {'from': 6, 'text': '0.1', 'to': 4},
 {'from': 6, 'text': '0.1', 'to': 5},
 {'from': 7, 'text': '0.8', 'to': 7},
 {'from': 7, 'text': '0.2', 'to': 0}]
#g2.edge('A', 'B')
for link in diagram_comp['linkArray']:
    #print( num_to_state[ link['from'] ] )
    #print( num_to_state[ link['to'] ] )
    state_diag.edge(num_to_state[ link['from'] ], num_to_state[ link['to'] ], link['text'] )
    
state_diag

svg

state_diag.render(filename='comp_diag')
'comp_diag.svg'

Written on August 23, 2017