18F/crime-data-api

View on GitHub
crime_data/common/cdemodels.py

Summary

Maintainability
F
1 wk
Test Coverage

Showing 48 of 48 total issues

File cdemodels.py has 1454 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 3 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 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 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 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 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 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 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 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 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 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 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 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

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

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

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

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

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

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

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

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

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

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_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_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 (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_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 ('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_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 ('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

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_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_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_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_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_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 ('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_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_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 (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_sex_code','sex_code')
Severity: Major
Found in crime_data/common/cdemodels.py - About 30 mins to fix
Category
Status