inasafe/inasafe

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

Summary

Maintainability
F
1 wk
Test Coverage

File aggregate_postprocessors.py has 563 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# coding=utf-8
"""Module used to generate context for aggregation postprocessors sections.
"""

from collections import OrderedDict
Severity: Major
Found in safe/report/extractors/aggregate_postprocessors.py - About 1 day to fix

    Function aggregation_postprocessors_extractor has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    def aggregation_postprocessors_extractor(impact_report, component_metadata):
        """Extracting aggregate result of demographic.
    
        :param impact_report: the impact report that acts as a proxy to fetch
            all the data that extractor needed
    Severity: Minor
    Found in safe/report/extractors/aggregate_postprocessors.py - About 1 hr to fix

      Function create_section_with_aggregation has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      def create_section_with_aggregation(
              aggregation_summary, analysis_layer, postprocessor_fields,
              section_header,
              units_label=None,
              use_rounding=True,
      Severity: Minor
      Found in safe/report/extractors/aggregate_postprocessors.py - About 1 hr to fix

        Function create_section has 8 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def create_section(
        Severity: Major
        Found in safe/report/extractors/aggregate_postprocessors.py - About 1 hr to fix

          Function create_section_without_aggregation has 7 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def create_section_without_aggregation(
          Severity: Major
          Found in safe/report/extractors/aggregate_postprocessors.py - About 50 mins to fix

            Function create_section_with_aggregation has 7 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def create_section_with_aggregation(
            Severity: Major
            Found in safe/report/extractors/aggregate_postprocessors.py - About 50 mins to fix

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

                  if zero_displaced:
                      context['sections']['gender'].append(
                          {
                              'header': gender_section_header,
                              'empty': True,
              Severity: Major
              Found in safe/report/extractors/aggregate_postprocessors.py and 2 other locations - About 1 day to fix
              safe/report/extractors/aggregate_postprocessors.py on lines 126..150
              safe/report/extractors/aggregate_postprocessors.py on lines 226..251

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

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

                      if zero_displaced:
                          context['sections']['vulnerability'].append(
                              {
                                  'header': vulnerability_section_header,
                                  'empty': True,
              Severity: Major
              Found in safe/report/extractors/aggregate_postprocessors.py and 2 other locations - About 1 day to fix
              safe/report/extractors/aggregate_postprocessors.py on lines 126..150
              safe/report/extractors/aggregate_postprocessors.py on lines 176..200

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

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

                  if zero_displaced:
                      context['sections']['age'].append(
                          {
                              'header': age_section_header,
                              'empty': True,
              Severity: Major
              Found in safe/report/extractors/aggregate_postprocessors.py and 2 other locations - About 1 day to fix
              safe/report/extractors/aggregate_postprocessors.py on lines 176..200
              safe/report/extractors/aggregate_postprocessors.py on lines 226..251

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

              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_label or output_field.get('unit'):
                          unit = None
                          if units_label:
                              unit = units_label[idx]
                          elif output_field.get('unit'):
              Severity: Major
              Found in safe/report/extractors/aggregate_postprocessors.py and 1 other location - About 7 hrs to fix
              safe/report/extractors/aggregate_postprocessors.py on lines 664..681

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

              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_label or output_field.get('unit'):
                          unit = None
                          if units_label:
                              unit = units_label[idx]
                          elif output_field.get('unit'):
              Severity: Major
              Found in safe/report/extractors/aggregate_postprocessors.py and 1 other location - About 7 hrs to fix
              safe/report/extractors/aggregate_postprocessors.py on lines 458..475

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

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

                      for field in vulnerability_items['fields']:
                          if field['key'] in analysis_layer_fields:
                              no_vulnerability_field = False
                              break
                      else:
              Severity: Major
              Found in safe/report/extractors/aggregate_postprocessors.py and 2 other locations - About 1 hr to fix
              safe/report/extractors/aggregate_postprocessors.py on lines 116..121
              safe/report/extractors/aggregate_postprocessors.py on lines 166..171

              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

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

                  for field in age_items['fields']:
                      if field['key'] in analysis_layer_fields:
                          no_age_field = False
                          break
                  else:
              Severity: Major
              Found in safe/report/extractors/aggregate_postprocessors.py and 2 other locations - About 1 hr to fix
              safe/report/extractors/aggregate_postprocessors.py on lines 166..171
              safe/report/extractors/aggregate_postprocessors.py on lines 217..222

              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

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

                  for field in gender_items['fields']:
                      if field['key'] in analysis_layer_fields:
                          no_gender_field = False
                          break
                  else:
              Severity: Major
              Found in safe/report/extractors/aggregate_postprocessors.py and 2 other locations - About 1 hr to fix
              safe/report/extractors/aggregate_postprocessors.py on lines 116..121
              safe/report/extractors/aggregate_postprocessors.py on lines 217..222

              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

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

                  age_items = {
                      'group': age_displaced_count_group,
                      'group_header': group_header_format.format(
                          header_name=age_displaced_count_group['header_name']),
                      'fields': [postprocessor_output_field(p) for p in age_postprocessors]
              Severity: Major
              Found in safe/report/extractors/aggregate_postprocessors.py and 1 other location - About 1 hr to fix
              safe/report/extractors/aggregate_postprocessors.py on lines 157..162

              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

                  gender_items = {
                      'group': gender_displaced_count_group,
                      'group_header': group_header_format.format(
                          header_name=gender_displaced_count_group['header_name']),
                      'fields': [
              Severity: Major
              Found in safe/report/extractors/aggregate_postprocessors.py and 1 other location - About 1 hr to fix
              safe/report/extractors/aggregate_postprocessors.py on lines 108..112

              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

                          if field.get('need_parameter'):
                              need = field['need_parameter']
                              if isinstance(need, ResourceParameter):
                                  unit_abbreviation = need.unit.abbreviation
                          elif field.get('unit'):
              Severity: Minor
              Found in safe/report/extractors/aggregate_postprocessors.py and 1 other location - About 30 mins to fix
              safe/report/expressions/infographic.py on lines 112..119

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

              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