gfw-api/forest-change-analysis-elastic

View on GitHub

Showing 19 of 19 total issues

Function validate_agg has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

def validate_agg(func):
    """validate aggregate_by argument"""

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

def validate_period(minYear):
    today = datetime.datetime.now()
    period = request.args.get('period', None)

    if period:
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 format_dataset_query has 13 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def format_dataset_query(day_value, confidence, from_year, from_date, to_year, to_date, count_sql, from_sql,
Severity: Major
Found in gladanalysis/services/query_constructor_service.py - About 1 hr to fix

    Function validate_admin has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    def validate_admin(func):
        """validate admin arguments"""
    
        @wraps(func)
        def wrapper(*args, **kwargs):
    Severity: Minor
    Found in gladanalysis/validators.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

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

                standard_format["attributes"]["downloadUrls"][
                    "csv"] = "/download/" + dataset_id + download_sql + "&format=csv"
    Severity: Major
    Found in gladanalysis/services/response_service.py and 1 other location - About 1 hr to fix
    gladanalysis/services/response_service.py on lines 30..31

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 41.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

                standard_format["attributes"]["downloadUrls"][
                    "json"] = "/download/" + dataset_id + download_sql + "&format=json"
    Severity: Major
    Found in gladanalysis/services/response_service.py and 1 other location - About 1 hr to fix
    gladanalysis/services/response_service.py on lines 28..29

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 41.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Function format_dataset_query has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def format_dataset_query(day_value, confidence, from_year, from_date, to_year, to_date, count_sql, from_sql,
                                 select_sql, order_sql, groupby_sql, iso=None, state=None, dist=None):
    
            if (int(from_year) == int(to_year)):
                where_template = 'WHERE ((year = {y1} and {day} >= {d1} and {day} <= {d2}))' + confidence
    Severity: Minor
    Found in gladanalysis/services/query_constructor_service.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 create_time_table has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def create_time_table(dataset, data, agg_type):
    
            if not data['data']:
                return []
    
    
    Severity: Minor
    Found in gladanalysis/services/summary_service.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 standardize_response has 8 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def standardize_response(data, dataset_id, count=None, download_sql=None, area=None, geostore=None, agg=None,
    Severity: Major
    Found in gladanalysis/services/response_service.py - About 1 hr to fix

      Function format_terrai_sql has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def format_terrai_sql(from_year, from_date, to_year, to_date, iso=None, state=None, dist=None, agg_values=False):
      Severity: Major
      Found in gladanalysis/services/query_constructor_service.py - About 50 mins to fix

        Function analyze has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def analyze(area=None, geostore=None, iso=None, state=None, dist=None, geojson=None):
        Severity: Minor
        Found in gladanalysis/routes/api/v2/terrai_router.py - About 45 mins to fix

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

          def validate_geostore(func):
              """validate geostore argument"""
          
              @wraps(func)
              def wrapper(*args, **kwargs):
          Severity: Minor
          Found in gladanalysis/validators.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 make_analysis_request has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def make_analysis_request(dataset_id, sql, geostore, geojson, api_key, v2=False):
          Severity: Minor
          Found in gladanalysis/services/analysis_service.py - About 35 mins to fix

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

                def standardize_response(data, dataset_id, count=None, download_sql=None, area=None, geostore=None, agg=None,
                                         agg_by=None, period=None):
                    # Helper function to standardize API responses
                    standard_format = {}
                    standard_format["type"] = "terrai-alerts"
            Severity: Minor
            Found in gladanalysis/services/response_service.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 query_terrai has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            def query_terrai():
                """analyze terrai by geostore or geojson"""
            
                if request.method == 'GET':
                    logging.info('[ROUTER]: get Terra I by Geostore')
            Severity: Minor
            Found in gladanalysis/routes/api/v2/terrai_router.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 error(status=400, detail='Start date must be less than end date')
            Severity: Major
            Found in gladanalysis/validators.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return func(*args, **kwargs)
              Severity: Major
              Found in gladanalysis/validators.py - About 30 mins to fix

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

                def analyze(area=None, geostore=None, iso=None, state=None, dist=None, geojson=None):
                    """Analyze method to execute queries
                    This is designed to format the dates of the request, create the sql and download sql queries from
                    the dates, retrieve the data from the queries and send the data to a formatter service to format
                    the API response.
                Severity: Minor
                Found in gladanalysis/routes/api/v2/terrai_router.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

                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