scitran/core

View on GitHub
api/handlers/dataexplorerhandler.py

Summary

Maintainability
F
3 days
Test Coverage

File dataexplorerhandler.py has 710 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import copy
import json

from elasticsearch import ElasticsearchException, TransportError, RequestError, helpers

Severity: Major
Found in api/handlers/dataexplorerhandler.py - About 1 day to fix

    Function _parse_request has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring.
    Open

        def _parse_request(self, request_type='search'):
    
            try:
                request = self.request.json_body
            except (ValueError):
    Severity: Minor
    Found in api/handlers/dataexplorerhandler.py - About 7 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 _handle_properties has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

        def _handle_properties(cls, properties, current_field_name):
    
            ignore_fields = [
                '_all', 'dynamic_templates', 'analysis_reference', 'file_reference',
                'parent', 'container_type', 'origin', 'permissions', '_id',
    Severity: Minor
    Found in api/handlers/dataexplorerhandler.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 index_field_names has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def index_field_names(self):
    
            try:
                if not config.es.indices.exists('data_explorer'):
                    self.abort(404, 'data_explorer index not yet available')
    Severity: Minor
    Found in api/handlers/dataexplorerhandler.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 aggregate_field_values has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def aggregate_field_values(self):
            """
            Return list of type ahead values for a key given a value
            that the user has already started to type in for the value of
            a custom string field or a set of statistics if the field type is
    Severity: Minor
    Found in api/handlers/dataexplorerhandler.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

    Avoid deeply nested control flow statements.
    Open

                            if isinstance(v, list):
                                v.remove("null")
                            elif isinstance(v, str):
                                v = None
                            null_filter = {
    Severity: Major
    Found in api/handlers/dataexplorerhandler.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if len(k.split('.')) > 1:
                                  null_filter['bool']['should'][0]['bool']['must'].append({'exists': {'field': k.split('.')[0]}})
                              if v:
      Severity: Major
      Found in api/handlers/dataexplorerhandler.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if v:
                                    null_filter['bool']['should'].append({'terms': {k+'.raw': v}})
                                modified_filters.append(null_filter)
        Severity: Major
        Found in api/handlers/dataexplorerhandler.py - About 45 mins to fix

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

                  size = config.es.search(
          Severity: Major
          Found in api/handlers/dataexplorerhandler.py and 1 other location - About 1 hr to fix
          api/handlers/dataexplorerhandler.py on lines 539..539

          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 39.

          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

                  results = config.es.search(
          Severity: Major
          Found in api/handlers/dataexplorerhandler.py and 1 other location - About 1 hr to fix
          api/handlers/dataexplorerhandler.py on lines 520..520

          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 39.

          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

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

                              aggs = config.es.search(
          Severity: Minor
          Found in api/handlers/dataexplorerhandler.py and 1 other location - About 35 mins to fix
          api/handlers/dataexplorerhandler.py on lines 471..471

          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 33.

          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

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

                  aggs = config.es.search(
          Severity: Minor
          Found in api/handlers/dataexplorerhandler.py and 1 other location - About 35 mins to fix
          api/handlers/dataexplorerhandler.py on lines 793..793

          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 33.

          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

          There are no issues that match your filters.

          Category
          Status