resource-watch/aqueduct-analysis-microservice

View on GitHub

Showing 49 of 49 total issues

Function precalc_present_benefits has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def precalc_present_benefits(self, model):
        """
        Inputs:
            prot_start_unit = present_day protection standard (assumed to beong to 0th year in list of years)
        Output:
Severity: Minor
Found in aqueduct/services/cba_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

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

    json_path = os.path.abspath(os.path.join(BASE_DIR, 'microservice')) + '/' + name + '.json'
Severity: Major
Found in aqueduct/utils/files.py and 1 other location - About 1 hr to fix
aqueduct/utils/files.py on lines 17..17

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

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

    json_path = os.path.abspath(os.path.join(BASE_DIR, 'microservice')) + '/' + name + '.json'
Severity: Major
Found in aqueduct/utils/files.py and 1 other location - About 1 hr to fix
aqueduct/utils/files.py on lines 11..11

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

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 compute_benefits has 9 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def compute_benefits(self, model, annual_risk_pres, annual_risk_fut, annual_pop_pres, annual_pop_fut,
Severity: Major
Found in aqueduct/services/cba_service.py - About 1 hr to fix

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

        def run_stats(self, dataframe):
            """
            Purpose: Finds the average, min, and max impact for all impact types
            Input:
                dataframe: Data associated with flood, geography, exposure type for all climate models
    Severity: Minor
    Found in aqueduct/services/risk_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

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

                self.df_admnames["AQID"] = self.df_admnames["AQID"].apply(
                    lambda x: ast.literal_eval(x)
    Severity: Major
    Found in aqueduct/services/food_supply_chain_service.py and 1 other location - About 1 hr to fix
    aqueduct/services/food_supply_chain_service.py on lines 302..303

    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

                self.df_admnames["PFAF_ID"] = self.df_admnames["PFAF_ID"].apply(
                    lambda x: ast.literal_eval(x)
    Severity: Major
    Found in aqueduct/services/food_supply_chain_service.py and 1 other location - About 1 hr to fix
    aqueduct/services/food_supply_chain_service.py on lines 305..306

    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

    Function run has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def run(self):
            try:
                # b = os.path.getsize(self.user_input)
                # f = open(self.user_input, 'rb')
                # first_bytes = f.read(50)
    Severity: Minor
    Found in aqueduct/services/food_supply_chain_service.py - About 55 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 compute_rp_change has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def compute_rp_change(self, rps, ref_impact, target_impact, rp, min_rp=2, max_rp=1000):
    Severity: Minor
    Found in aqueduct/services/cba_service.py - About 45 mins to fix

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

          def fuzzy_merge(self, df_1, df_2, key1, key2, threshold=90, limit=1):
      Severity: Minor
      Found in aqueduct/services/food_supply_chain_service.py - About 45 mins to fix

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

            def risk_evolution(self, impact_cc, impact_urb, impact_pop, impact_gdp, prot, prot_idx):
        Severity: Minor
        Found in aqueduct/services/cba_service.py - About 45 mins to fix

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

              def find_impact(self, impact_cc, impact_soc, impact_sub, impact_cc_soc, impact_urb, model):
          Severity: Minor
          Found in aqueduct/services/risk_service.py - About 45 mins to fix

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

                def select_projection_data(self, dataframe, climate, model, socioecon, year):
            Severity: Minor
            Found in aqueduct/services/risk_service.py - About 35 mins to fix

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

                  def compute_rp_change(self, ref_impact, target_impact, rp, min_rp=2, max_rp=1000):
              Severity: Minor
              Found in aqueduct/services/risk_service.py - About 35 mins to fix

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

                    def user_selections(self):
                        """
                        Purpose: Gather all neccesary inputs to run any analysis
                
                        Output:
                Severity: Minor
                Found in aqueduct/services/cba_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

                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
                          Severity
                          Category
                          Status
                          Source
                          Language