Konano/arknights-mower

View on GitHub
menu.py

Summary

Maintainability
D
1 day
Test Coverage

File menu.py has 310 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import json
from multiprocessing import Pipe, Process, freeze_support
import time
from datetime import datetime
import PySimpleGUI as sg
Severity: Minor
Found in menu.py - About 3 hrs to fix

    Function simulate has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

    def simulate():
        '''
        具体调用方法可见各个函数的参数说明
        '''
        tasks = []
    Severity: Minor
    Found in menu.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 initBtn has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    def initBtn(event):
        room_key = event[4:]
        station_name = plan[room_key]['name'] if room_key in plan.keys() else ''
        plans = plan[room_key]['plans'] if room_key in plan.keys() else []
        if room_key.startswith('room'):
    Severity: Minor
    Found in menu.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 menu has 44 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    def menu():
        global window
        global buffer
        loadConf()
        sg.theme('LightBlue2')
    Severity: Minor
    Found in menu.py - About 1 hr to fix

      Function menu has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

      def menu():
          global window
          global buffer
          loadConf()
          sg.theme('LightBlue2')
      Severity: Minor
      Found in menu.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 loadPlan has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      def loadPlan(url):
          global plan
          if not os.path.isfile(url):
              with open(url, 'w') as f:
                  json.dump(plan, f)  # 创建空json文件
      Severity: Minor
      Found in menu.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

      Refactor this function to reduce its Cognitive Complexity from 23 to the 15 allowed.
      Open

      def simulate():
      Severity: Critical
      Found in menu.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

      Refactor this function to reduce its Cognitive Complexity from 22 to the 15 allowed.
      Open

      def initBtn(event):
      Severity: Critical
      Found in menu.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

      Statement ends with a semicolon
      Open

      confUrl = './conf.yml';
      Severity: Minor
      Found in menu.py by pep8

      Compound statements (on the same line) are generally discouraged.

      While sometimes it's okay to put an if/for/while with a small body
      on the same line, never do this for multi-clause statements.
      Also avoid folding such long lines!
      
      Always use a def statement instead of an assignment statement that
      binds a lambda expression directly to a name.
      
      Okay: if foo == 'blah':\n    do_blah_thing()
      Okay: do_one()
      Okay: do_two()
      Okay: do_three()
      
      E701: if foo == 'blah': do_blah_thing()
      E701: for x in lst: total += x
      E701: while t < 10: t = delay()
      E701: if foo == 'blah': do_blah_thing()
      E701: else: do_non_blah_thing()
      E701: try: something()
      E701: finally: cleanup()
      E701: if foo == 'blah': one(); two(); three()
      E702: do_one(); do_two(); do_three()
      E703: do_four();  # useless semicolon
      E704: def f(x): return 2*x
      E731: f = lambda x: 2*x

      Rename function "initBtn" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
      Open

      def initBtn(event):
      Severity: Major
      Found in menu.py by sonar-python

      Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

      Noncompliant Code Example

      With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$

      def MyFunction(a,b):
          ...
      

      Compliant Solution

      def my_function(a,b):
          ...
      

      Rename function "writePlan" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
      Open

      def writePlan():
      Severity: Major
      Found in menu.py by sonar-python

      Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

      Noncompliant Code Example

      With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$

      def MyFunction(a,b):
          ...
      

      Compliant Solution

      def my_function(a,b):
          ...
      

      Rename function "loadConf" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
      Open

      def loadConf():
      Severity: Major
      Found in menu.py by sonar-python

      Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

      Noncompliant Code Example

      With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$

      def MyFunction(a,b):
          ...
      

      Compliant Solution

      def my_function(a,b):
          ...
      

      Rename function "saveBtn" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
      Open

      def saveBtn(btn):
      Severity: Major
      Found in menu.py by sonar-python

      Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

      Noncompliant Code Example

      With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$

      def MyFunction(a,b):
          ...
      

      Compliant Solution

      def my_function(a,b):
          ...
      

      Rename function "loadPlan" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
      Open

      def loadPlan(url):
      Severity: Major
      Found in menu.py by sonar-python

      Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

      Noncompliant Code Example

      With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$

      def MyFunction(a,b):
          ...
      

      Compliant Solution

      def my_function(a,b):
          ...
      

      Rename function "writeConf" to match the regular expression ^[a-z_][a-z0-9_]{2,}$.
      Open

      def writeConf():
      Severity: Major
      Found in menu.py by sonar-python

      Shared coding conventions allow teams to collaborate efficiently. This rule checks that all function names match a provided regular expression.

      Noncompliant Code Example

      With the default provided regular expression: ^[a-z_][a-z0-9_]{2,30}$

      def MyFunction(a,b):
          ...
      

      Compliant Solution

      def my_function(a,b):
          ...
      

      There are no issues that match your filters.

      Category
      Status