Beispiel #1
0
def _twonode_viewgraph():
    view_graph = LayeredGraph()
    view_graph.add_node('a', node=ProcessGroup())
    view_graph.add_node('b', node=ProcessGroup())
    view_graph.add_edge('a', 'b', bundles=[0])
    view_graph.ordering = Ordering([
        [['a']],
        [['b']],
    ])
    return view_graph
Beispiel #2
0
def test_results_graph_material_key():
    # Mock flow data
    flows = pd.DataFrame.from_records([
        ('a1', 'c1', 'm', 'long', 3),
        ('a1', 'c1', 'n', 'long', 1),
    ],
                                      columns=('source', 'target',
                                               'material_type', 'shape',
                                               'value'))

    view_graph = LayeredGraph()
    view_graph.add_node('a', node=ProcessGroup())
    view_graph.add_node('c', node=ProcessGroup())
    view_graph.add_edge('a', 'c', bundles=[0])
    view_graph.ordering = Ordering([[['a']], [['c']]])
    bundle_flows = {0: flows}

    material_partition = Partition.Simple('material_type', ['m', 'n'])
    shape_partition = Partition.Simple('shape', ['long', 'thin'])

    # Partition based on material_type
    view_graph.edges['a', 'c']['flow_partition'] = material_partition
    Gr, groups = results_graph(view_graph, bundle_flows)
    assert sorted(Gr.edges(keys=True, data=True)) == [
        ('a^*', 'c^*', ('m', '*'), {
            'measures': {
                'value': 3
            },
            'original_flows': [0],
            'bundles': [0]
        }),
        ('a^*', 'c^*', ('n', '*'), {
            'measures': {
                'value': 1
            },
            'original_flows': [1],
            'bundles': [0]
        }),
    ]

    # Partition based on shape
    view_graph.edges['a', 'c']['flow_partition'] = shape_partition
    Gr, groups = results_graph(view_graph, bundle_flows)
    assert sorted(Gr.edges(keys=True, data=True)) == [
        ('a^*', 'c^*', ('long', '*'), {
            'measures': {
                'value': 4
            },
            'original_flows': [0, 1],
            'bundles': [0]
        }),
    ]
def test_results_graph_elsewhere_stubs():
    b_partition = Partition.Simple('process', ['b1', 'b2'])

    view_graph = LayeredGraph()
    view_graph.add_node('a', node=ProcessGroup())
    view_graph.add_node('b',
                        node=ProcessGroup(partition=b_partition),
                        from_elsewhere_bundles=[1])
    view_graph.add_edge('a', 'b', bundles=[0])
    view_graph.ordering = Ordering([[['a']], [['b']]])

    # Mock flow data
    bundle_flows = {
        0:
        pd.DataFrame.from_records([
            ('a1', 'b1', 'm', 3),
            ('a2', 'b1', 'n', 1),
        ],
                                  index=(0, 1),
                                  columns=('source', 'target', 'material',
                                           'value')),
        1:
        pd.DataFrame.from_records([
            ('x1', 'b1', 'm', 1),
            ('x3', 'b2', 'n', 5),
        ],
                                  index=(2, 3),
                                  columns=('source', 'target', 'material',
                                           'value'))
    }

    # Do partition based on flows stored in bundles
    Gr, groups = results_graph(view_graph, bundle_flows)

    assert sorted(Gr.nodes(data=True)) == [
        ('a^*', {
            'direction': 'R',
            'type': 'process',
            'title': 'a'
        }),
        ('b^b1', {
            'direction':
            'R',
            'type':
            'process',
            'title':
            'b1',
            'from_elsewhere_edges': [
                (('*', '*'), {
                    'measures': {
                        'value': 1
                    },
                    'original_flows': [2],
                    'bundles': [1]
                }),
            ]
        }),
        ('b^b2', {
            'direction':
            'R',
            'type':
            'process',
            'title':
            'b2',
            'from_elsewhere_edges': [
                (('*', '*'), {
                    'measures': {
                        'value': 5
                    },
                    'original_flows': [3],
                    'bundles': [1]
                }),
            ]
        }),
    ]
    assert sorted(Gr.edges(keys=True, data=True)) == [
        ('a^*', 'b^b1', ('*', '*'), {
            'measures': {
                'value': 4
            },
            'original_flows': [0, 1],
            'bundles': [0]
        }),
    ]