18F/crime-data-api

View on GitHub

Showing 91 of 91 total issues

File models.py has 2390 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# coding: utf-8
import datetime
from decimal import Decimal
 
import flask_restful as restful
Severity: Major
Found in crime_data/common/models.py - About 6 days to fix

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

File marshmallow_schemas.py has 910 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# coding: utf-8
 
import os
 
from flask_marshmallow import Marshmallow
Severity: Major
Found in crime_data/common/marshmallow_schemas.py - About 2 days to fix

File newmodels.py has 460 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""Models for tables not included in UCR, generated for our system
 
`models.py` is meant to simply reflect the tables as they exist in UCR
itself; `cdemodels.py` extends those model classes. *These* models, on
the other hand, must actually be generated in our system.
Severity: Minor
Found in crime_data/common/newmodels.py - About 7 hrs to fix

File base.py has 405 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import json
import math
import os
import random
from urllib import parse
Severity: Minor
Found in crime_data/common/base.py - About 5 hrs to fix

File nibrs_counts.py has 319 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from webargs.flaskparser import use_args
from crime_data.extensions import DEFAULT_MAX_AGE
from flask.ext.cachecontrol import cache
from sqlalchemy import func
 
 
Severity: Minor
Found in crime_data/resources/nibrs_counts.py - About 3 hrs 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

Function add_resources has 86 lines of code (exceeds 25 allowed). Consider refactoring.
Open

def add_resources(app):
"""Register API routes and Swagger endpoints"""
api = restful.Api(app)
 
@api.representation('text/csv')
Severity: Major
Found in crime_data/app.py - About 3 hrs to fix

Cyclomatic complexity is too high in function urls. (14)
Open

@click.command()
@click.option('--url',
default=None,
help='Url to test (ex. /static/image.png)')
@click.option('--order',
Severity: Minor
Found in crime_data/commands.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

Function _serialize_dict has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

def _serialize_dict(self,
data,
accumulator={},
path=None,
aggregate_many=False):
Severity: Minor
Found in crime_data/common/base.py - About 2 hrs to fix

Cyclomatic complexity is too high in method with_metadata. (9)
Open

def with_metadata(self, results, args, schema = None):
"""Paginates results and wraps them in metadata."""
 
count = 0
try:
Severity: Minor
Found in crime_data/common/base.py by radon

Cyclomatic complexity is too high in method filtered. (9)
Open

@classmethod
def filtered(cls, filters, args=None):
args = args or []
qry = cls.query
 
 
Severity: Minor
Found in crime_data/common/newmodels.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 _serialize_dict. (9)
Open

def _serialize_dict(self,
data,
accumulator={},
path=None,
aggregate_many=False):
Severity: Minor
Found in crime_data/common/base.py by radon

File app.py has 262 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
"""The app module, containing the app factory function."""
import csv
import io
from os import getenv
Severity: Minor
Found in crime_data/app.py - About 2 hrs to fix
Severity
Category
Status
Source
Language