Erdnaxela3/bioptim_gui

View on GitHub

Showing 105 of 105 total issues

File pike_acrobatics_variables.py has 298 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import numpy as np

from bioptim_gui_api.acrobatics_ocp.variables.variable_computers.straight_acrobatics_variables import (
    StraightAcrobaticsVariables,
)

    Cyclomatic complexity is too high in method get_q_bounds. (11)
    Open

        def get_q_bounds(cls, half_twists: list, prefer_left: bool) -> dict:
            nb_somersaults = len(half_twists)
            is_forward = sum(half_twists) % 2 != 0
            x_bounds = []
    
    

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Cyclomatic complexity is too high in function plot_solutions. (11)
    Open

    def plot_solutions(pkl_paths: list[str], variable: str = "q") -> None:
        assert len(pkl_paths) != 0
    
        with open(pkl_paths[0], "rb") as f:
            o = pkl.load(f)
    Severity: Minor
    Found in gui/graph_multiple_sols.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Cyclomatic complexity is too high in method penalties. (8)
    Open

        def penalties(cls, data: dict) -> str:
            phases = data["phases_info"]
            nb_phases = len(phases)
            ret = """
        # Declaration of the constraints and objectives of the ocp

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    File straight_acrobatics_variables.py has 254 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import numpy as np
    
    from bioptim_gui_api.acrobatics_ocp.variables.utils import maximum_fig_arms_angle
    from bioptim_gui_api.utils.format_utils import invert_min_max
    from bioptim_gui_api.variables.misc.variables_utils import define_loose_bounds, LooseValue

      Cyclomatic complexity is too high in function common_objectives. (7)
      Open

      def common_objectives(phase_name: str = None, position: str = "straight", phase_index: int = 0, model=None) -> list:
          """
          Objectives that are common regardless of the phase and position
      
          MINIMIZE_CONTROL lagrange: tau, all_shooting, weight=1.0

      Cyclomatic Complexity

      Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

      Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

      Construct Effect on CC Reasoning
      if +1 An if statement is a single decision.
      elif +1 The elif statement adds another decision.
      else +0 The else statement does not cause a new decision. The decision is at the if.
      for +1 There is a decision at the start of the loop.
      while +1 There is a decision at the while statement.
      except +1 Each except branch adds a new conditional path of execution.
      finally +0 The finally block is unconditionally executed.
      with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
      assert +1 The assert statement internally roughly equals a conditional statement.
      Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
      Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

      Source: http://radon.readthedocs.org/en/latest/intro.html

      Function plot_solutions has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

      def plot_solutions(pkl_paths: list[str], variable: str = "q") -> None:
          assert len(pkl_paths) != 0
      
          with open(pkl_paths[0], "rb") as f:
              o = pkl.load(f)
      Severity: Minor
      Found in gui/graph_multiple_sols.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

      Cyclomatic complexity is too high in class CollisionComputer. (6)
      Open

      class CollisionComputer:
          """
          This class is used to define the cylinder collision pairs for a given acrobatics figure.
      
          Attributes

      Cyclomatic Complexity

      Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

      Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

      Construct Effect on CC Reasoning
      if +1 An if statement is a single decision.
      elif +1 The elif statement adds another decision.
      else +0 The else statement does not cause a new decision. The decision is at the if.
      for +1 There is a decision at the start of the loop.
      while +1 There is a decision at the while statement.
      except +1 Each except branch adds a new conditional path of execution.
      finally +0 The finally block is unconditionally executed.
      with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
      assert +1 The assert statement internally roughly equals a conditional statement.
      Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
      Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

      Source: http://radon.readthedocs.org/en/latest/intro.html

      Cyclomatic complexity is too high in function obj_arguments. (6)
      Open

      def obj_arguments(objective_type: str, penalty_type: str) -> list:
          """
          Get the arguments of the objective function
      
          Parameters

      Cyclomatic Complexity

      Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

      Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

      Construct Effect on CC Reasoning
      if +1 An if statement is a single decision.
      elif +1 The elif statement adds another decision.
      else +0 The else statement does not cause a new decision. The decision is at the if.
      for +1 There is a decision at the start of the loop.
      while +1 There is a decision at the while statement.
      except +1 Each except branch adds a new conditional path of execution.
      finally +0 The finally block is unconditionally executed.
      with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
      assert +1 The assert statement internally roughly equals a conditional statement.
      Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
      Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

      Source: http://radon.readthedocs.org/en/latest/intro.html

      Cyclomatic complexity is too high in class TuckAcrobaticsVariables. (6)
      Open

      class TuckAcrobaticsVariables(PikeAcrobaticsVariables):
          X = 0
          Y = 1
          Z = 2
          Xrot = 3

      Cyclomatic Complexity

      Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

      Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

      Construct Effect on CC Reasoning
      if +1 An if statement is a single decision.
      elif +1 The elif statement adds another decision.
      else +0 The else statement does not cause a new decision. The decision is at the if.
      for +1 There is a decision at the start of the loop.
      while +1 There is a decision at the while statement.
      except +1 Each except branch adds a new conditional path of execution.
      finally +0 The finally block is unconditionally executed.
      with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
      assert +1 The assert statement internally roughly equals a conditional statement.
      Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
      Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

      Source: http://radon.readthedocs.org/en/latest/intro.html

      Cyclomatic complexity is too high in function get_args. (6)
      Open

      def get_args(penalty_fcn) -> list:
          """
          Get the arguments of the penalty function
      
          Parameters

      Cyclomatic Complexity

      Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

      Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

      Construct Effect on CC Reasoning
      if +1 An if statement is a single decision.
      elif +1 The elif statement adds another decision.
      else +0 The else statement does not cause a new decision. The decision is at the if.
      for +1 There is a decision at the start of the loop.
      while +1 There is a decision at the while statement.
      except +1 Each except branch adds a new conditional path of execution.
      finally +0 The finally block is unconditionally executed.
      with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
      assert +1 The assert statement internally roughly equals a conditional statement.
      Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
      Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

      Source: http://radon.readthedocs.org/en/latest/intro.html

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

          def get_q_bounds(cls, half_twists: list, prefer_left: bool) -> dict:
              nb_somersaults = len(half_twists)
              is_forward = sum(half_twists) % 2 != 0
              x_bounds = []
      
      

      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 closest_distance_between_lines has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      def closest_distance_between_lines():
          # adapté de https://stackoverflow.com/questions/2824478/shortest-distance-between-two-line-segments
      
          a0 = cas.SX.sym("a0", 3, 1)
          b0 = cas.SX.sym("b0", 3, 1)

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

        def custom_noncrossing_const(
        Severity: Major
        Found in api/bioptim_gui_api/acrobatics_ocp/code_generation/custom_penalty_fcn.py - About 50 mins to fix

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

          def custom_noncrossing_obj(
          Severity: Major
          Found in api/bioptim_gui_api/acrobatics_ocp/code_generation/custom_penalty_fcn.py - About 50 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                if phase != 0:
                                    axs[dof].vlines(
                                        t_start,
                                        bound[0],
                                        phases_bound[phase - 1][2],
            Severity: Major
            Found in gui/graph_multiple_sols.py - About 45 mins to fix

              Function _fill_position_phase has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  def _fill_position_phase(cls, x_bounds: list, i: int, half_twists: list) -> None:
                      # acrobatics starts with pike
                      if len(x_bounds) == 1:
                          x_bounds[0]["min"][:, 0] = [0] * cls.nb_q
                          x_bounds[0]["max"][:, 0] = [0] * cls.nb_q

              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 prepare_multi_start has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              def prepare_multi_start(

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

                    def register_put_objective_type(self):
                        @self.router.put("/{phase_index}/objectives/{objective_index}/objective_type", response_model=dict)
                        def put_objective_type(phase_index: int, objective_index: int, objective_type: ObjectiveTypeRequest):
                            phases_info = self.data.read_data("phases_info")
                            objective = phases_info[phase_index]["objectives"][objective_index]

                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 _fill_twist_phase has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    def _fill_twist_phase(cls, x_bounds: list, i: int, half_twists: list, is_last_somersault: bool) -> None:
                        nb_somersaults = len(half_twists)
                        for b in 0, 1, 2:
                            x_bounds[-1]["min"][:, b] = x_bounds[-2]["min"][:, 2]
                            x_bounds[-1]["max"][:, b] = x_bounds[-2]["max"][:, 2]

                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

                Severity
                Category
                Status
                Source
                Language