Konano/arknights-mower

View on GitHub
arknights_mower/utils/solver.py

Summary

Maintainability
B
4 hrs
Test Coverage

Function login has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
Wontfix

    def login(self):
        """
        登录进游戏
        """
        retry_times = config.MAX_RETRYTIME
Severity: Minor
Found in arknights_mower/utils/solver.py - About 4 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 back_to_index has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Wontfix

    def back_to_index(self):
        """
        返回主页
        """
        logger.info('back to index')
Severity: Minor
Found in arknights_mower/utils/solver.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

File solver.py has 274 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from __future__ import annotations

import time
import traceback
from abc import abstractmethod
Severity: Minor
Found in arknights_mower/utils/solver.py - About 2 hrs to fix

    BaseSolver has 21 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class BaseSolver:
        """ Base class, provide basic operation """
    
        def __init__(self, device: Device = None, recog: Recognizer = None) -> None:
            # self.device = device if device is not None else (recog.device if recog is not None else Device())
    Severity: Minor
    Found in arknights_mower/utils/solver.py - About 2 hrs to fix

      Function tap_element has 9 arguments (exceeds 4 allowed). Consider refactoring.
      Wontfix

          def tap_element(self, element_name: str, x_rate: float = 0.5, y_rate: float = 0.5, interval: float = 1, rebuild: bool = True,
      Severity: Major
      Found in arknights_mower/utils/solver.py - About 1 hr to fix

        Function run has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Wontfix

            def run(self)-> None:
                retry_times = config.MAX_RETRYTIME
                result =None
                while retry_times > 0:
                    try:
        Severity: Minor
        Found in arknights_mower/utils/solver.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 find has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Wontfix

            def find(self, res: str, draw: bool = False, scope: tp.Scope = None, thres: int = None, judge: bool = True, strict: bool = False) -> tp.Scope:
        Severity: Minor
        Found in arknights_mower/utils/solver.py - About 45 mins to fix

          Function tap has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Wontfix

              def tap(self, poly: tp.Location, x_rate: float = 0.5, y_rate: float = 0.5, interval: float = 1, rebuild: bool = True) -> None:
          Severity: Minor
          Found in arknights_mower/utils/solver.py - About 35 mins to fix

            Function swipe_noinertia has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Wontfix

                def swipe_noinertia(self, start: tp.Coordinate, movement: tp.Coordinate, duration: int = 100, interval: float = 1, rebuild: bool = False) -> None:
            Severity: Minor
            Found in arknights_mower/utils/solver.py - About 35 mins to fix

              Function swipe has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Wontfix

                  def swipe(self, start: tp.Coordinate, movement: tp.Coordinate, duration: int = 100, interval: float = 1, rebuild: bool = True) -> None:
              Severity: Minor
              Found in arknights_mower/utils/solver.py - About 35 mins to fix

                Refactor this function to reduce its Cognitive Complexity from 28 to the 15 allowed.
                Wontfix

                    def back_to_index(self):
                Severity: Critical
                Found in arknights_mower/utils/solver.py by sonar-python

                Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

                See

                Method "tap_element" has 10 parameters, which is greater than the 7 authorized.
                Wontfix

                    def tap_element(self, element_name: str, x_rate: float = 0.5, y_rate: float = 0.5, interval: float = 1, rebuild: bool = True,
                                    draw: bool = False, scope: tp.Scope = None, judge: bool = True, detected: bool = False) -> bool:

                A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

                Noncompliant Code Example

                With a maximum number of 4 parameters:

                def do_something(param1, param2, param3, param4, param5):
                    ...
                

                Compliant Solution

                def do_something(param1, param2, param3, param4):
                    ...
                

                Refactor this function to reduce its Cognitive Complexity from 31 to the 15 allowed.
                Wontfix

                    def login(self):
                Severity: Critical
                Found in arknights_mower/utils/solver.py by sonar-python

                Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

                See

                Missing whitespace after ','
                Open

                        self.tap((self.recog.w*0.2, self.recog.h*0.8),interval=0.5)
                Severity: Minor
                Found in arknights_mower/utils/solver.py by pep8

                Each comma, semicolon or colon should be followed by whitespace.

                Okay: [a, b]
                Okay: (3,)
                Okay: a[1:4]
                Okay: a[:4]
                Okay: a[1:]
                Okay: a[1:4:2]
                E231: ['a','b']
                E231: foo(bar,baz)
                E231: [{'a':'b'}]

                Missing whitespace around operator
                Open

                    def run(self)-> None:
                Severity: Minor
                Found in arknights_mower/utils/solver.py by pep8

                Surround operators with a single space on either side.

                - Always surround these binary operators with a single space on
                  either side: assignment (=), augmented assignment (+=, -= etc.),
                  comparisons (==, <, >, !=, <=, >=, in, not in, is, is not),
                  Booleans (and, or, not).
                
                - If operators with different priorities are used, consider adding
                  whitespace around the operators with the lowest priorities.
                
                Okay: i = i + 1
                Okay: submitted += 1
                Okay: x = x * 2 - 1
                Okay: hypot2 = x * x + y * y
                Okay: c = (a + b) * (a - b)
                Okay: foo(bar, key='word', *args, **kwargs)
                Okay: alpha[:-i]
                
                E225: i=i+1
                E225: submitted +=1
                E225: x = x /2 - 1
                E225: z = x **y
                E225: z = 1and 1
                E226: c = (a+b) * (a-b)
                E226: hypot2 = x*x + y*y
                E227: c = a|b
                E228: msg = fmt%(errno, errmsg)

                Blank line at end of file
                Open

                Severity: Minor
                Found in arknights_mower/utils/solver.py by pep8

                Trailing blank lines are superfluous.

                Okay: spam(1)
                W391: spam(1)\n
                
                However the last line should end with a new line (warning W292).

                Missing whitespace around operator
                Open

                        result =None
                Severity: Minor
                Found in arknights_mower/utils/solver.py by pep8

                Surround operators with a single space on either side.

                - Always surround these binary operators with a single space on
                  either side: assignment (=), augmented assignment (+=, -= etc.),
                  comparisons (==, <, >, !=, <=, >=, in, not in, is, is not),
                  Booleans (and, or, not).
                
                - If operators with different priorities are used, consider adding
                  whitespace around the operators with the lowest priorities.
                
                Okay: i = i + 1
                Okay: submitted += 1
                Okay: x = x * 2 - 1
                Okay: hypot2 = x * x + y * y
                Okay: c = (a + b) * (a - b)
                Okay: foo(bar, key='word', *args, **kwargs)
                Okay: alpha[:-i]
                
                E225: i=i+1
                E225: submitted +=1
                E225: x = x /2 - 1
                E225: z = x **y
                E225: z = 1and 1
                E226: c = (a+b) * (a-b)
                E226: hypot2 = x*x + y*y
                E227: c = a|b
                E228: msg = fmt%(errno, errmsg)

                There are no issues that match your filters.

                Category
                Status