inasafe/inasafe

View on GitHub
safe/report/extractors/analysis_detail.py

Summary

Maintainability
F
3 days
Test Coverage

File analysis_detail.py has 453 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# coding=utf-8

"""Module used to generate context for analysis detail section."""


Severity: Minor
Found in safe/report/extractors/analysis_detail.py - About 6 hrs to fix

    Function analysis_detail_extractor has 72 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    def analysis_detail_extractor(impact_report, component_metadata):
        """Extracting analysis result from the impact layer.
    
        :param impact_report: The impact report that acts as a proxy to fetch
            all the data that extractor needed.
    Severity: Major
    Found in safe/report/extractors/analysis_detail.py - About 2 hrs to fix

      Avoid deeply nested control flow statements.
      Open

                          if currency_unit == unit['key']:
                              current_unit = unit['name']
                              break
                      if not current_unit:
      Severity: Major
      Found in safe/report/extractors/analysis_detail.py - About 45 mins to fix

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

                    if group_key:
                        if field == total_affected_field:
                            row.insert(
                                affected_header_index,
                                {
        Severity: Major
        Found in safe/report/extractors/analysis_detail.py and 1 other location - About 4 hrs to fix
        safe/report/extractors/analysis_detail.py on lines 430..451

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

        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

                if group_key:
                    if field == total_affected_field:
                        footers.insert(
                            affected_header_index,
                            {
        Severity: Major
        Found in safe/report/extractors/analysis_detail.py and 1 other location - About 4 hrs to fix
        safe/report/extractors/analysis_detail.py on lines 288..309

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

        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

            if units:
                unit = units[0]
                abbreviation = unit['abbreviation']
                if abbreviation:
                    unit_string = '({abbreviation})'.format(abbreviation=abbreviation)
        Severity: Major
        Found in safe/report/extractors/analysis_detail.py and 1 other location - About 2 hrs to fix
        safe/report/extractors/aggregate_result.py on lines 233..241

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

        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

                try:
                    # retrieve dynamic field name from analysis_fields keywords
                    # will cause key error if no hazard count for that particular
                    # class
                    field_name = analysis_layer_fields[field_key_name]
        Severity: Major
        Found in safe/report/extractors/analysis_detail.py and 1 other location - About 1 hr to fix
        safe/report/extractors/general_report.py on lines 289..297

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

        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 4 locations. Consider refactoring.
        Open

                    for key, group in list(header_hazard_group.items()):
                        if field['name'] in group['total']:
                            group_key = key
                            break
        Severity: Major
        Found in safe/report/extractors/analysis_detail.py and 3 other locations - About 1 hr to fix
        safe/report/extractors/analysis_detail.py on lines 233..236
        safe/report/extractors/analysis_detail.py on lines 366..369
        safe/report/extractors/analysis_detail.py on lines 421..424

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

        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 4 locations. Consider refactoring.
        Open

                for key, group in list(header_hazard_group.items()):
                    if hazard_class['name'] in group['hazards']:
                        group_key = key
                        break
        Severity: Major
        Found in safe/report/extractors/analysis_detail.py and 3 other locations - About 1 hr to fix
        safe/report/extractors/analysis_detail.py on lines 233..236
        safe/report/extractors/analysis_detail.py on lines 268..271
        safe/report/extractors/analysis_detail.py on lines 421..424

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

        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 4 locations. Consider refactoring.
        Open

                    for key, group in list(header_hazard_group.items()):
                        if hazard_class['name'] in group['hazards']:
                            group_key = key
                            break
        Severity: Major
        Found in safe/report/extractors/analysis_detail.py and 3 other locations - About 1 hr to fix
        safe/report/extractors/analysis_detail.py on lines 268..271
        safe/report/extractors/analysis_detail.py on lines 366..369
        safe/report/extractors/analysis_detail.py on lines 421..424

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

        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 4 locations. Consider refactoring.
        Open

                for key, group in list(header_hazard_group.items()):
                    if field['name'] in group['total']:
                        group_key = key
                        break
        Severity: Major
        Found in safe/report/extractors/analysis_detail.py and 3 other locations - About 1 hr to fix
        safe/report/extractors/analysis_detail.py on lines 233..236
        safe/report/extractors/analysis_detail.py on lines 268..271
        safe/report/extractors/analysis_detail.py on lines 366..369

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

        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

                for i, _exposure_class in enumerate(exposure_classes_lists):
                    if _class_key == _exposure_class['key']:
                        index = i
                        break
                else:
        Severity: Major
        Found in safe/report/extractors/analysis_detail.py and 1 other location - About 1 hr to fix
        safe/report/extractors/aggregate_result.py on lines 98..103

        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

        There are no issues that match your filters.

        Category
        Status