mangroveorg/datawinners

View on GitHub
datawinners/entity/geo_data.py

Summary

Maintainability
D
1 day
Test Coverage

Function geo_jsons has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

def geo_jsons(manager, entity_type, filters, details, specials, map_view = False, total_in_label = False):
    entity_fields = manager.view.registration_form_model_by_entity_type(key=[entity_type], include_docs=True)[0]["doc"]["json_fields"]

    geo_jsons = [{
        "name": entity_type.capitalize(),
Severity: Minor
Found in datawinners/entity/geo_data.py - About 3 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 _to_json_detail has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

def _to_json_detail(value, entity_field_labels, data=None, entity_type=None, fields_to_show_combined=None):
    detail_json = _to_json_point(value)
    detail_json['properties'] = _simplify_field_data(data, entity_field_labels, entity_type)
    if fields_to_show_combined != None:
        for ftsc in fields_to_show_combined:
Severity: Minor
Found in datawinners/entity/geo_data.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 _transform_filters has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

def _transform_filters(filters, entity_all_fields):
    d = dict((field['code'], field) for field in entity_all_fields)
    forward_filters = {}
    reverse_filters = {}
    for f in filters:
Severity: Minor
Found in datawinners/entity/geo_data.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 _simplify_field_data has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

def _simplify_field_data(data, entity_field_labels, entity_type=None):
    simple_data = OrderedDict()

    if entity_type is not None:
        simple_data['entity_type'] = {}
Severity: Minor
Found in datawinners/entity/geo_data.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 geo_jsons has 7 arguments (exceeds 4 allowed). Consider refactoring.
Open

def geo_jsons(manager, entity_type, filters, details, specials, map_view = False, total_in_label = False):
Severity: Major
Found in datawinners/entity/geo_data.py - About 50 mins to fix

    Avoid deeply nested control flow statements.
    Open

                        if len(value_string)>0:
                            value_string = value_string + ', '
                        value_string = value_string + details['value']
    Severity: Major
    Found in datawinners/entity/geo_data.py - About 45 mins to fix

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

      def _to_json_detail(value, entity_field_labels, data=None, entity_type=None, fields_to_show_combined=None):
      Severity: Minor
      Found in datawinners/entity/geo_data.py - About 35 mins to fix

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

        def _geo_json(dbm, entity_type, entity_fields, filters, details):
        Severity: Minor
        Found in datawinners/entity/geo_data.py - About 35 mins to fix

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

          def _geo_json(dbm, entity_type, entity_fields, filters, details):
              location_list = []
          
              try:
                  forward_filters, reverse_filters = _transform_filters(filters, entity_fields)
          Severity: Minor
          Found in datawinners/entity/geo_data.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

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

                      details_to_show_combined = [json.loads(d.replace("'", '"')) for d in details if is_json(d.replace("'", '"'))]
          Severity: Major
          Found in datawinners/entity/geo_data.py and 1 other location - About 1 hr to fix
          datawinners/public/views.py on lines 50..50

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

              entity_fields = manager.view.registration_form_model_by_entity_type(key=[entity_type], include_docs=True)[0]["doc"]["json_fields"]
          Severity: Major
          Found in datawinners/entity/geo_data.py and 2 other locations - About 1 hr to fix
          datawinners/project/views/views.py on lines 1043..1043
          datawinners/entity/views.py on lines 517..517

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

          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