resource-watch/aqueduct-analysis-microservice

View on GitHub
aqueduct/routes/api/v1/ps_router.py

Summary

Maintainability
D
1 day
Test Coverage
F
41%

File ps_router.py has 459 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""API ROUTER"""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
Severity: Minor
Found in aqueduct/routes/api/v1/ps_router.py - About 7 hrs to fix

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

    def analyze(**kwargs):
        """Analyze water risk data
        ---
        get:
            summary: Allow  water risk atlas analysis. Pasing this params as 'application/json' on a Post
    Severity: Minor
    Found in aqueduct/routes/api/v1/ps_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 get_supply_chain_analysis has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_supply_chain_analysis(user_indicator, threshold, **kwargs):
        try:
            # check if the post request has the file part
            if "data" not in request.files:
                logging.error("[ROUTER]: No input file provided")
    Severity: Minor
    Found in aqueduct/routes/api/v1/ps_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

    Avoid too many return statements within this function.
    Open

            return error(status=500, detail=str(e))
    Severity: Major
    Found in aqueduct/routes/api/v1/ps_router.py - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

                  return error(
      Severity: Major
      Found in aqueduct/routes/api/v1/ps_router.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return jsonify(payload), 500, {}
        Severity: Major
        Found in aqueduct/routes/api/v1/ps_router.py - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                  return error(status=500, detail=str(e))
          Severity: Major
          Found in aqueduct/routes/api/v1/ps_router.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return error(status=500, detail="Generic Error")
            Severity: Major
            Found in aqueduct/routes/api/v1/ps_router.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                          return jsonify(analyzer.results()), 200, {}
              Severity: Major
              Found in aqueduct/routes/api/v1/ps_router.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        return error(status=500, detail=str(e))
                Severity: Major
                Found in aqueduct/routes/api/v1/ps_router.py - About 30 mins to fix

                  There are no issues that match your filters.

                  Category
                  Status