rasa/shared/core/training_data/visualization.py

Summary

Maintainability
D
3 days
Test Coverage
B
86%

File visualization.py has 492 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from collections import defaultdict, deque

import random
from typing import (
    Any,
Severity: Minor
Found in rasa/shared/core/training_data/visualization.py - About 7 hrs to fix

    Function visualize_neighborhood has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
    Open

    def visualize_neighborhood(
        current: Optional[List[Event]],
        event_sequences: List[List[Event]],
        output_file: Optional[Text] = None,
        max_history: int = 2,
    Severity: Minor
    Found in rasa/shared/core/training_data/visualization.py - About 5 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _merge_equivalent_nodes has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
    Open

    def _merge_equivalent_nodes(graph: "networkx.MultiDiGraph", max_history: int) -> None:
        """Searches for equivalent nodes in the graph and merges them."""
        changed = True
        # every node merge changes the graph and can trigger previously
        # impossible node merges - we need to repeat until
    Severity: Minor
    Found in rasa/shared/core/training_data/visualization.py - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function _replace_edge_labels_with_nodes has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def _replace_edge_labels_with_nodes(
        graph: "networkx.MultiDiGraph", next_id: int, nlu_training_data: "TrainingData"
    ) -> None:
        """Replaces edge labels with nodes.
    
    
    Severity: Minor
    Found in rasa/shared/core/training_data/visualization.py - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function visualize_neighborhood has 8 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def visualize_neighborhood(
    Severity: Major
    Found in rasa/shared/core/training_data/visualization.py - About 1 hr to fix

      Function _fingerprint_node has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

      def _fingerprint_node(
          graph: "networkx.MultiDiGraph", node: int, max_history: int
      ) -> Set[Text]:
          """Fingerprint a node in a graph.
      
      
      Severity: Minor
      Found in rasa/shared/core/training_data/visualization.py - About 55 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function visualize_stories has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def visualize_stories(
      Severity: Major
      Found in rasa/shared/core/training_data/visualization.py - About 50 mins to fix

        Function _add_edge has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def _add_edge(
        Severity: Minor
        Found in rasa/shared/core/training_data/visualization.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              if graph.has_node(j) and _nodes_are_equivalent(
                                  graph, i, j, max_history
                              ):
                                  # make sure we keep special styles
                                  _transfer_style(
          Severity: Major
          Found in rasa/shared/core/training_data/visualization.py - About 45 mins to fix

            Function _add_message_edge has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def _add_message_edge(
            Severity: Minor
            Found in rasa/shared/core/training_data/visualization.py - About 35 mins to fix

              Function _remove_auxiliary_nodes has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              def _remove_auxiliary_nodes(
                  graph: "networkx.MultiDiGraph", special_node_idx: int
              ) -> None:
                  """Remove any temporary or unused nodes."""
                  graph.remove_node(TMP_NODE_ID)
              Severity: Minor
              Found in rasa/shared/core/training_data/visualization.py - About 35 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function _length_of_common_action_prefix has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              def _length_of_common_action_prefix(this: List[Event], other: List[Event]) -> int:
                  """Calculate number of actions that two conversations have in common."""
                  num_common_actions = 0
                  t_cleaned = cast(
                      List[Union[ActionExecuted, UserUttered]],
              Severity: Minor
              Found in rasa/shared/core/training_data/visualization.py - About 35 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              There are no issues that match your filters.

              Category
              Status