fbi-cde/crime-data-api

View on GitHub
crime_data/common/cdemodels.py

Summary

Maintainability
F
1 wk
Test Coverage

File cdemodels.py has 2104 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import abc
from collections import namedtuple
from flask_restful import abort
from sqlalchemy import and_, func, or_, UniqueConstraint, PrimaryKeyConstraint, Index
from sqlalchemy.exc import ArgumentError
Severity: Major
Found in crime_data/common/cdemodels.py - About 5 days to fix

    Cyclomatic complexity is too high in method get_field_table. (16)
    Open

        def get_field_table(self, field):
            if field in ['weapon_name']:
                return ('nibrs_weapon_type','weapon_name')
    
            if field in ['method_entry_code']:
    Severity: Minor
    Found in crime_data/common/cdemodels.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 get_field_table. (16)
    Open

        def get_field_table(self, field):
            if field in ['weapon_name']:
                return ('nibrs_weapon_type','weapon_name')
    
            if field in ['method_entry_code']:
    Severity: Minor
    Found in crime_data/common/cdemodels.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 base_query. (11)
    Open

        def base_query(self, field):
            if self.explorer_offense:
                query = 'SELECT  b.:field, SUM(a.count)::int AS count, SUM(a.stolen_value)::text AS stolen_value, SUM(a.recovered_value)::text AS recovered_value, :explorer_offense AS offense_name, b.year FROM (SELECT year::text, offense_name, :field, '
                query += 'count, stolen_value, recovered_value'
            else:
    Severity: Minor
    Found in crime_data/common/cdemodels.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 base_query. (11)
    Open

        def base_query(self, field):
    
            if self.explorer_offense:
                query = 'SELECT b.:field,  SUM(a.count)::int AS count, :explorer_offense AS offense_name, b.year FROM (SELECT year::text, offense_name, :field, count'
            else:
    Severity: Minor
    Found in crime_data/common/cdemodels.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 class OffenseSubCountView. (11)
    Open

    class OffenseSubCountView(object):
    
        def __init__(self, field, year=None, state_id=None, ori=None,
                     offense_name=None, state_abbr=None, explorer_offense=None, as_json=True):
    
    
    Severity: Minor
    Found in crime_data/common/cdemodels.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 base_query. (11)
    Open

        def base_query(self, field):
    
    
            if self.explorer_offense:
                query = 'SELECT b.year, :explorer_offense AS offense_name, b.:field, SUM(a.count)::int AS count from (SELECT year::text, offense_name, :field, count'
    Severity: Minor
    Found in crime_data/common/cdemodels.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 __init__. (9)
    Open

        def __init__(self, field, year=None, state_id=None, ori=None,
                     offense_name=None, state_abbr=None, explorer_offense=None, as_json=True):
    
            self.as_json = as_json
    
    
    Severity: Minor
    Found in crime_data/common/cdemodels.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 query. (8)
    Open

        def query(self, args):
            base_query = None
            qry = None
            param_dict = {}
            try:
    Severity: Minor
    Found in crime_data/common/cdemodels.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 base_query. (8)
    Open

        def base_query(self, field):
            select_query = 'SELECT b.:field, a.count, b.year FROM (SELECT :field , count, year::text'
            from_query = ' FROM :view_name'
            where_query = ' WHERE :field IS NOT NULL'
    
    
    Severity: Minor
    Found in crime_data/common/cdemodels.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 class MultiYearCountView. (7)
    Open

    class MultiYearCountView(object):
        """For materialized views that aren't split by year"""
    
        __abstract__ = True
    
    
    Severity: Minor
    Found in crime_data/common/cdemodels.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 __init__. (7)
    Open

        def __init__(self, field, year=None, state_id=None, state_abbr=None, ori=None, as_json=True):
    
            self.as_json = as_json
    
            if field is None:
    Severity: Minor
    Found in crime_data/common/cdemodels.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 base_query. (7)
    Open

        def base_query(self, field):
    
            query = 'SELECT b.:field, a.count, b.year FROM (SELECT :field ,stolen_value::text, recovered_value::text, year::text, count'
            query += ' FROM :view_name '
            where_query = ' WHERE :field IS NOT NULL'
    Severity: Minor
    Found in crime_data/common/cdemodels.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

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

        def get_field_table(self, field):
            if field in ['weapon_name']:
                return ('nibrs_weapon_type','weapon_name')
    
            if field in ['method_entry_code']:
    Severity: Minor
    Found in crime_data/common/cdemodels.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 get_field_table has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_field_table(self, field):
            if field in ['weapon_name']:
                return ('nibrs_weapon_type','weapon_name')
    
            if field in ['method_entry_code']:
    Severity: Minor
    Found in crime_data/common/cdemodels.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 base_query has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def base_query(self, field):
    
            if self.explorer_offense:
                query = 'SELECT b.:field,  SUM(a.count)::int AS count, :explorer_offense AS offense_name, b.year FROM (SELECT year::text, offense_name, :field, count'
            else:
    Severity: Minor
    Found in crime_data/common/cdemodels.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 base_query has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def base_query(self, field):
            if self.explorer_offense:
                query = 'SELECT  b.:field, SUM(a.count)::int AS count, SUM(a.stolen_value)::text AS stolen_value, SUM(a.recovered_value)::text AS recovered_value, :explorer_offense AS offense_name, b.year FROM (SELECT year::text, offense_name, :field, '
                query += 'count, stolen_value, recovered_value'
            else:
    Severity: Minor
    Found in crime_data/common/cdemodels.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 base_query has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def base_query(self, field):
    
    
            if self.explorer_offense:
                query = 'SELECT b.year, :explorer_offense AS offense_name, b.:field, SUM(a.count)::int AS count from (SELECT year::text, offense_name, :field, count'
    Severity: Minor
    Found in crime_data/common/cdemodels.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 __init__ has 8 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, field, year=None, state_id=None, ori=None,
    Severity: Major
    Found in crime_data/common/cdemodels.py - About 1 hr to fix

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

          def base_query(self, field):
              select_query = 'SELECT b.:field, a.count, b.year FROM (SELECT :field , count, year::text'
              from_query = ' FROM :view_name'
              where_query = ' WHERE :field IS NOT NULL'
      
      
      Severity: Minor
      Found in crime_data/common/cdemodels.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 query has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def query(self, args):
              base_query = None
              qry = None
              param_dict = {}
              try:
      Severity: Minor
      Found in crime_data/common/cdemodels.py - About 45 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 __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def __init__(self, field, year=None, state_id=None, state_abbr=None, ori=None, as_json=True):
      Severity: Minor
      Found in crime_data/common/cdemodels.py - About 45 mins to fix

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

            def base_query(self, field):
        
                query = 'SELECT b.:field, a.count, b.year FROM (SELECT :field ,stolen_value::text, recovered_value::text, year::text, count'
                query += ' FROM :view_name '
                where_query = ' WHERE :field IS NOT NULL'
        Severity: Minor
        Found in crime_data/common/cdemodels.py - About 45 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 __init__ has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def __init__(self, field, year=None, state_id=None, ori=None,
                         offense_name=None, state_abbr=None, explorer_offense=None, as_json=True):
        
                self.as_json = as_json
        
        
        Severity: Minor
        Found in crime_data/common/cdemodels.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

        Avoid too many return statements within this function.
        Open

                    return ('nibrs_offense_type','offense_name')
        Severity: Major
        Found in crime_data/common/cdemodels.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                      return ('nibrs_location_type','location_name')
          Severity: Major
          Found in crime_data/common/cdemodels.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return (None, None)
            Severity: Major
            Found in crime_data/common/cdemodels.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return ('nibrs_victim_type','victim_type_name')
              Severity: Major
              Found in crime_data/common/cdemodels.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return ('nibrs_resident_status_code','resident_status_code')
                Severity: Major
                Found in crime_data/common/cdemodels.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              return ('nibrs_victim_type','victim_type_name')
                  Severity: Major
                  Found in crime_data/common/cdemodels.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                                return ('ref_race','race_code')
                    Severity: Major
                    Found in crime_data/common/cdemodels.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                  return ('nibrs_sex_code','sex_code')
                      Severity: Major
                      Found in crime_data/common/cdemodels.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                    return ('nibrs_sex_code','sex_code')
                        Severity: Major
                        Found in crime_data/common/cdemodels.py - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                      return ('nibrs_age_num','age_num')
                          Severity: Major
                          Found in crime_data/common/cdemodels.py - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                        return ('nibrs_circumstances', 'circumstances_name')
                            Severity: Major
                            Found in crime_data/common/cdemodels.py - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                          return ('nibrs_prop_desc_type','prop_desc_name')
                              Severity: Major
                              Found in crime_data/common/cdemodels.py - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                            return ('nibrs_resident_status_code','resident_status_code')
                                Severity: Major
                                Found in crime_data/common/cdemodels.py - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                              return ('ref_race','race_code')
                                  Severity: Major
                                  Found in crime_data/common/cdemodels.py - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                                return ('nibrs_ethnicity','ethnicity_name')
                                    Severity: Major
                                    Found in crime_data/common/cdemodels.py - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                                  return ('nibrs_age_num','age_num')
                                      Severity: Major
                                      Found in crime_data/common/cdemodels.py - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                                    return ('nibrs_location_type','location_name')
                                        Severity: Major
                                        Found in crime_data/common/cdemodels.py - About 30 mins to fix

                                          Avoid too many return statements within this function.
                                          Open

                                                      return ('nibrs_relationship','relationship_name')
                                          Severity: Major
                                          Found in crime_data/common/cdemodels.py - About 30 mins to fix

                                            Avoid too many return statements within this function.
                                            Open

                                                    return (None, None)
                                            Severity: Major
                                            Found in crime_data/common/cdemodels.py - About 30 mins to fix

                                              Avoid too many return statements within this function.
                                              Open

                                                          return ('nibrs_relationship','relationship_name')
                                              Severity: Major
                                              Found in crime_data/common/cdemodels.py - About 30 mins to fix

                                                Avoid too many return statements within this function.
                                                Open

                                                            return ('nibrs_offense_type','offense_name')
                                                Severity: Major
                                                Found in crime_data/common/cdemodels.py - About 30 mins to fix

                                                  Avoid too many return statements within this function.
                                                  Open

                                                              return ('nibrs_circumstances', 'circumstances_name')
                                                  Severity: Major
                                                  Found in crime_data/common/cdemodels.py - About 30 mins to fix

                                                    Avoid too many return statements within this function.
                                                    Open

                                                                return ('nibrs_prop_desc_type','prop_desc_name')
                                                    Severity: Major
                                                    Found in crime_data/common/cdemodels.py - About 30 mins to fix

                                                      Avoid too many return statements within this function.
                                                      Open

                                                                  return ('nibrs_ethnicity','ethnicity_name')
                                                      Severity: Major
                                                      Found in crime_data/common/cdemodels.py - About 30 mins to fix

                                                        Function get has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                        Open

                                                            def get(ori=None, offense=None):
                                                                """
                                                                A method to find a Summarized Data by Agency and Offense
                                                                """
                                                                query = SummarizedDataAgency.query
                                                        Severity: Minor
                                                        Found in crime_data/common/cdemodels.py - About 25 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