resource-watch/prep-nexgddp

View on GitHub
nexgddp/routes/api/v1/nexgddp_router.py

Summary

Maintainability
D
3 days
Test Coverage
F
43%

File nexgddp_router.py has 510 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""API ROUTER"""
import io
import logging
import os

Severity: Major
Found in nexgddp/routes/api/v1/nexgddp_router.py - About 1 day to fix

    Function query has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
    Open

    def query(dataset_id, bbox, dataset):
        """NEXGDDP QUERY ENDPOINT"""
        logging.info('[ROUTER] Doing Query of dataset ' + dataset_id)
        # Get and deserialize
        table_name = dataset.get('tableName')
    Severity: Minor
    Found in nexgddp/routes/api/v1/nexgddp_router.py - About 6 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 get_tile has 12 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def get_tile(z, x, y, model, scenario, year, style, indicator, layer, compare_year=None, dset_b=None, no_data=None):
    Severity: Major
    Found in nexgddp/routes/api/v1/nexgddp_router.py - About 1 hr to fix

      Function get_sql_select has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      def get_sql_select(json_sql):
          select_sql = json_sql.get('select')
          logging.debug(f"select_sql: {select_sql}")
          select_sql
          select = None
      Severity: Minor
      Found in nexgddp/routes/api/v1/nexgddp_router.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 diff has 7 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def diff(dset_a, date_a, date_b, lat, lon, varnames, dset_b=None):
      Severity: Major
      Found in nexgddp/routes/api/v1/nexgddp_router.py - About 50 mins to fix

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

        def get_tile(z, x, y, model, scenario, year, style, indicator, layer, compare_year=None, dset_b=None, no_data=None):
            logging.info(f'Getting tile for {z} {x} {y}')
            logging.debug(compare_year)
            bbox = TileService.get_bbox(x, y, z)
            logging.debug(f"bbox: {bbox}")
        Severity: Minor
        Found in nexgddp/routes/api/v1/nexgddp_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=e.message)
        Severity: Major
        Found in nexgddp/routes/api/v1/nexgddp_router.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                      return error(status=400, detail=e.message)
          Severity: Major
          Found in nexgddp/routes/api/v1/nexgddp_router.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return error(status=400, detail='No coordinates provided. Include geostore or lat & lon')
            Severity: Major
            Found in nexgddp/routes/api/v1/nexgddp_router.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return error(status=400, detail=e.message)
              Severity: Major
              Found in nexgddp/routes/api/v1/nexgddp_router.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                            return error(status=400, detail=e.message)
                Severity: Major
                Found in nexgddp/routes/api/v1/nexgddp_router.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                      return jsonify(data=output), 200
                  Severity: Major
                  Found in nexgddp/routes/api/v1/nexgddp_router.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                            return error(status=404, detail='Table name not valid')
                    Severity: Major
                    Found in nexgddp/routes/api/v1/nexgddp_router.py - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                      return jsonify(data=query_results), 200
                      Severity: Major
                      Found in nexgddp/routes/api/v1/nexgddp_router.py - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                return jsonify(data=[result]), 200
                        Severity: Major
                        Found in nexgddp/routes/api/v1/nexgddp_router.py - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                      return error(status=400, detail=e.message)
                          Severity: Major
                          Found in nexgddp/routes/api/v1/nexgddp_router.py - About 30 mins to fix

                            There are no issues that match your filters.

                            Category
                            Status