gfw-api/glad-analysis-tiled

View on GitHub

Showing 13 of 13 total issues

Function validate_period has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

def validate_period():
    # validate period
    today = datetime.datetime.now()
    period = request.args.get('period', None)
    minYear = 2015
Severity: Minor
Found in gladAnalysis/validators.py - About 2 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 validate_geojson has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

def validate_geojson(func):
    """validate input geojson"""

    @wraps(func)
    def wrapper(*args, **kwargs):
Severity: Minor
Found in gladAnalysis/validators.py - About 2 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 calc_stats has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

def calc_stats(geojson, request, geostore_id):
    """Given an input geojson and (optionally) some params
       (period, agg_by, etc), calculate the # of alerts in an AOI"""

    geom = shape(geojson['features'][0]['geometry'])
Severity: Minor
Found in gladAnalysis/services/custom_geom_queries.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 format_alerts_admin has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

def format_alerts_admin(request, glad_alerts):
    # take the glad alerts format and strip out some attributes
    agg_by = request.args.get('aggregate_by', None)

    for elem in glad_alerts['data']['attributes']['value']:
Severity: Minor
Found in gladAnalysis/utils/util.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_geojson has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

def get_geojson(func):
    """Grab geojson any way it comes - with geostore ID,
       with wdpa ID or use ID, or just POSTed geojson.
       Convert this into a dictionary object and return
       it as the variable `geojson`
Severity: Minor
Found in gladAnalysis/middleware.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 process_tile has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

def process_tile(tile_list, aoi):
    # main function to compare a list of tiles to an input geometry
    # will eventually return a list of tiles completely within the aoi (all zoom levels possible)
    # and tiles that intersect the aoi (must be of max_z because that's as low as we go)

Severity: Minor
Found in gladAnalysis/utils/tile_geometry.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 build_download_urls has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def build_download_urls(id_tuple, geostore_id, agg_values, agg_by, period, conf):
    # id_tuple looks like this: (iso, adm1, adm2)
    if id_tuple:

        # unpack it
Severity: Minor
Found in gladAnalysis/serializers.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 build_download_urls has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

def build_download_urls(id_tuple, geostore_id, agg_values, agg_by, period, conf):
Severity: Minor
Found in gladAnalysis/serializers.py - About 45 mins to fix

    Function serialize_response has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def serialize_response(request, glad_alerts, aoi_area_ha, geostore_id=None, id_tuple=None):
    Severity: Minor
    Found in gladAnalysis/serializers.py - About 35 mins to fix

      Function format_alerts_geom has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      def format_alerts_geom(rows, request):
          agg_by = request.args.get('aggregate_by')
      
          # pull first row from sql response [(<alert_date>, <alert_count>), ()]
          if rows:
      Severity: Minor
      Found in gladAnalysis/utils/aggregate_response.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

      Function validate_aggregate has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      def validate_aggregate():
          # validate aggregate
          agg_by = request.args.get('aggregate_by')
          agg_values = request.args.get('aggregate_values')
      
      
      Severity: Minor
      Found in gladAnalysis/validators.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

      Function grouped_and_to_rows has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      def grouped_and_to_rows(keys, vals, agg_type):
          # source: https://jakevdp.github.io/blog/2017/03/22/group-by-from-scratch/
          count = defaultdict(int)
          for key, val in zip(keys, vals):
              count[key] += val
      Severity: Minor
      Found in gladAnalysis/utils/aggregate_response.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

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

      def worker_int(worker):
          worker.log.info("worker received INT or QUIT signal")
      
          ## get traceback info
          import threading, sys, traceback
      Severity: Minor
      Found in gunicorn.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

      Severity
      Category
      Status
      Source
      Language