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
Function simulate
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
def simulate():
'''
具体调用方法可见各个函数的参数说明
'''
tasks = []
- Read upRead up
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'):
- Read upRead up
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')
Function menu
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def menu():
global window
global buffer
loadConf()
sg.theme('LightBlue2')
- Read upRead up
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文件
- Read upRead up
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():
- Read upRead up
- Exclude checks
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):
- Read upRead up
- Exclude checks
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';
- Read upRead up
- Exclude checks
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):
- Read upRead up
- Exclude checks
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():
- Read upRead up
- Exclude checks
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():
- Read upRead up
- Exclude checks
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):
- Read upRead up
- Exclude checks
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):
- Read upRead up
- Exclude checks
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():
- Read upRead up
- Exclude checks
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): ...