Esempio n. 1
0
 def test_nodes_with_the_same_name_are_disallowed(self):
     importance_map = ImportanceScoreMap(DetailLevel.medium)
     builder = DotBuilderWrapper(importance_map, True, True)
     builder.add_node("n1", Node("Java", {}, {}))
     builder.add_node("n2", Node("Java", {}, {}))
     with pytest.raises(Exception):
         builder.add_node("n1", "Java", Node({}, {}))
Esempio n. 2
0
 def test_nodes_with_the_same_name_are_disallowed(self):
     importance_map = ImportanceScoreMap(DetailLevel.medium)
     builder = DotBuilderWrapper(importance_map, True, True)
     builder.add_node('n1', Node('Java', {}, {}))
     builder.add_node('n2', Node('Java', {}, {}))
     with pytest.raises(Exception):
         builder.add_node('n1', 'Java', Node({}, {}))
Esempio n. 3
0
class Converter:
    """Convert Pipeline to its visualization in GraphViz dot format."""
    def __init__(self,
                 detail_level,
                 show_input_ports,
                 show_output_ports,
                 vertical_orientation=True):
        """Args:
            detail_level (DetailLevel): level of presentation details
            show_input_ports (bool):
            show_output_ports (bool):
            vertical_orientation (bool): True if the graph should be drawn
                from top to bottom, False if it should be drawn from left to
                right.
        """
        score_map = ImportanceScoreMap(detail_level)
        self.__b = DotBuilderWrapper(score_map, show_input_ports,
                                     show_output_ports, vertical_orientation)
        self.__low_score_nodes_remover = LowScoreNodesRemover(score_map)
        self.__input_created = False
        self.__output_created = False
        self.__already_run = False

    def run(self, pipeline):
        """
        Convert Pipeline to its visualization in GraphViz dot format

        Args:
            pipeline (Pipeline): input Pipeline.

        Return:
            string: dot format
        """
        assert not self.__already_run
        self.__already_run = True

        clean_pipeline = self.__low_score_nodes_remover.run(pipeline)

        # We sort the collection to obtain the same order of output elements
        # every time. That is, we remove non-determinism of the output.
        for (name, node) in \
                sorted(clean_pipeline.nodes.items(), key=lambda x: x[0]):
            self.__b.add_node(name, node)
        pipeline_data = PipelineData.from_pipeline(clean_pipeline)

        # We sort the collection to obtain the same order of output elements
        # every time. That is, we remove non-determinism of the output.
        for data_id in sorted(pipeline_data.get_ids()):
            info = pipeline_data.get_info(data_id)
            start = self.__get_data_start(data_id, info.producers)
            ends = self.__get_data_ends(data_id, info.consumers)
            if start is not None and ends is not None:
                for end in ends:
                    self.__b.add_edge(start, end)
        return self.__b.get_result()

    def __get_data_start(self, data_id, data_producers):
        if len(data_producers) == 0:
            return None
        elif len(data_producers) > 1:
            self.__b.add_data_node(data_id)
            for address in data_producers:
                self.__b.add_edge(address, DataAddress(data_id, None))
            return DataAddress(data_id, None)
        else:
            assert len(data_producers) == 1
            # Take an element from the set
            for e in data_producers:
                break
            return e

    def __get_data_ends(self, data_id, data_consumers):
        if len(data_consumers) == 0:
            return None
        else:
            return [address for address in data_consumers]
Esempio n. 4
0
class Converter:
    """Convert Pipeline to its visualization in GraphViz dot format."""

    def __init__(self, detail_level, show_input_ports, show_output_ports,
                 vertical_orientation=True):
        """Args:
            detail_level (DetailLevel): level of presentation details
            show_input_ports (bool):
            show_output_ports (bool):
            vertical_orientation (bool): True if the graph should be drawn
                from top to bottom, False if it should be drawn from left to
                right.
        """
        score_map = ImportanceScoreMap(detail_level)
        self.__b = DotBuilderWrapper(
            score_map, show_input_ports, show_output_ports,
            vertical_orientation)
        self.__low_score_nodes_remover = LowScoreNodesRemover(score_map)
        self.__input_created = False
        self.__output_created = False
        self.__already_run = False

    def run(self, pipeline):
        """
        Convert Pipeline to its visualization in GraphViz dot format

        Args:
            pipeline (Pipeline): input Pipeline.

        Return:
            string: dot format
        """
        assert not self.__already_run
        self.__already_run = True

        clean_pipeline = self.__low_score_nodes_remover.run(pipeline)

        # We sort the collection to obtain the same order of output elements
        # every time. That is, we remove non-determinism of the output.
        for (name, node) in \
                sorted(clean_pipeline.nodes.items(), key=lambda x: x[0]):
            self.__b.add_node(name, node)
        pipeline_data = PipelineData.from_pipeline(clean_pipeline)

        # We sort the collection to obtain the same order of output elements
        # every time. That is, we remove non-determinism of the output.
        for data_id in sorted(pipeline_data.get_ids()):
            info = pipeline_data.get_info(data_id)
            start = self.__get_data_start(data_id, info.producers)
            ends = self.__get_data_ends(data_id, info.consumers)
            if start is not None and ends is not None:
                for end in ends:
                    self.__b.add_edge(start, end)
        return self.__b.get_result()

    def __get_data_start(self, data_id, data_producers):
        if len(data_producers) == 0:
            return None
        elif len(data_producers) > 1:
            self.__b.add_data_node(data_id)
            for address in data_producers:
                self.__b.add_edge(address, DataAddress(data_id, None))
            return DataAddress(data_id, None)
        else:
            assert len(data_producers) == 1
            # Take an element from the set
            for e in data_producers:
                break
            return e

    def __get_data_ends(self, data_id, data_consumers):
        if len(data_consumers) == 0:
            return None
        else:
            return [address for address in data_consumers]