twschiller/open-synthesis

View on GitHub

Showing 36 of 36 total issues

File models.py has 618 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""Analysis of Competing Hypotheses Django Application Model Configuration.

For more information, please see:
    https://docs.djangoproject.com/en/1.10/topics/db/models/
"""
Severity: Major
Found in openach/models.py - About 1 day to fix

    File boards.py has 390 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import itertools
    import json
    import logging
    import random
    from collections import defaultdict
    Severity: Minor
    Found in openach/views/boards.py - About 5 hrs to fix

      File settings.py has 336 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      """
      Django settings for openintel project.
      
      Generated by 'django-admin startproject' using Django 1.10.
      
      
      Severity: Minor
      Found in openintel/settings.py - About 4 hrs to fix

        File teams.py has 307 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        from django.conf import settings
        from django.contrib import messages
        from django.contrib.auth.decorators import login_required
        from django.contrib.auth.models import User
        from django.contrib.sites.shortcuts import get_current_site
        Severity: Minor
        Found in openach/views/teams.py - About 3 hrs to fix

          Cyclomatic complexity is too high in function detail. (15)
          Open

          @require_safe
          @account_required
          @cache_if_anon(PAGE_CACHE_TIMEOUT_SECONDS)
          def detail(request, board_id, dummy_board_slug=None):
              """Return a detail view for the given board.
          Severity: Minor
          Found in openach/views/boards.py by radon

          Cyclomatic Complexity

          Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

          Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

          Construct Effect on CC Reasoning
          if +1 An if statement is a single decision.
          elif +1 The elif statement adds another decision.
          else +0 The else statement does not cause a new decision. The decision is at the if.
          for +1 There is a decision at the start of the loop.
          while +1 There is a decision at the while statement.
          except +1 Each except branch adds a new conditional path of execution.
          finally +0 The finally block is unconditionally executed.
          with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
          assert +1 The assert statement internally roughly equals a conditional statement.
          Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
          Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

          Source: http://radon.readthedocs.org/en/latest/intro.html

          Cyclomatic complexity is too high in function evaluate. (14)
          Open

          @require_http_methods(["HEAD", "GET", "POST"])
          @login_required
          def evaluate(request, board_id, evidence_id):
              """Return a view for assessing a piece of evidence against all hypotheses.
          
          
          Severity: Minor
          Found in openach/views/boards.py by radon

          Cyclomatic Complexity

          Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

          Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

          Construct Effect on CC Reasoning
          if +1 An if statement is a single decision.
          elif +1 The elif statement adds another decision.
          else +0 The else statement does not cause a new decision. The decision is at the if.
          for +1 There is a decision at the start of the loop.
          while +1 There is a decision at the while statement.
          except +1 Each except branch adds a new conditional path of execution.
          finally +0 The finally block is unconditionally executed.
          with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
          assert +1 The assert statement internally roughly equals a conditional statement.
          Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
          Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

          Source: http://radon.readthedocs.org/en/latest/intro.html

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

          @receiver(post_save, sender=User)
          def init_user_settings(sender, **kwargs):
              """Link existing benchmark countries to newly created countries."""
              instance = kwargs["instance"]
              if kwargs["created"]:
          Severity: Major
          Found in openach/signals.py and 1 other location - About 2 hrs to fix
          openach/signals.py on lines 7..12

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

          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

          @receiver(post_save, sender=Board)
          def init_board_permissions(sender, **kwargs):
              """Link existing benchmark countries to newly created countries."""
              instance = kwargs["instance"]
              if kwargs["created"]:
          Severity: Major
          Found in openach/signals.py and 1 other location - About 2 hrs to fix
          openach/signals.py on lines 15..20

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

          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 comparison_style has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

          def comparison_style(user, aggregate):
              """Return the CSS class name for the analysis cell given a user evaluation and the consensus evaluation.
          
              Requires that the user disagrees with the consensus. If the user roughly agrees, return the weak consistent
              or inconsistent CSS class. Otherwise, return the dispute style depending on the distance between the evaluations.
          Severity: Minor
          Found in openach/templatetags/board_extras.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 handle has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              def handle(self, *args, **options):
                  """Handle the command invocation."""
                  if options["frequency"] == "daily":
                      self.report(send_digest_emails(DigestFrequency.daily))
                  elif options["frequency"] == "weekly":
          Severity: Minor
          Found in openach/management/commands/senddigest.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 edit_board has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

          def edit_board(request, board_id):
              """Return a board edit view, or handle the form submission."""
              board = get_object_or_404(Board, pk=board_id)
          
              if "edit_board" not in board.permissions.for_user(request.user):
          Severity: Minor
          Found in openach/views/boards.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

              AUTH_CHOICES_REGISTERED = [
                  (AuthLevels.board_creator.key, _("Only Me")),
                  (AuthLevels.collaborators.key, _("Collaborators")),
                  (AuthLevels.registered.key, _("Registered Users")),
          Severity: Major
          Found in openach/models.py and 1 other location - About 1 hr to fix
          openach/models.py on lines 767..770

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

          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 evaluate has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

          def evaluate(request, board_id, evidence_id):
              """Return a view for assessing a piece of evidence against all hypotheses.
          
              Take a couple measures to reduce bias: (1) do not show the analyst their previous assessment, and (2) show
              the hypotheses in a random order.
          Severity: Minor
          Found in openach/views/boards.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

              DIGEST_FREQUENCY = (
                  (DigestFrequency.never.key, _("Never")),
                  (DigestFrequency.daily.key, _("Daily")),
                  (DigestFrequency.weekly.key, _("Weekly")),
          Severity: Major
          Found in openach/models.py and 1 other location - About 1 hr to fix
          openach/models.py on lines 337..340

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

          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

          Consider simplifying this complex logical expression.
          Open

                  if user.is_staff or is_owner:
                      return set(max_allowed)
                  else:
                      is_user_collaborator = self.collaborators.filter(pk=user.id).exists()
                      is_team_collaborator = self.teams.filter(members__pk=user.id).exists()
          Severity: Major
          Found in openach/models.py - About 1 hr to fix

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

                def for_user(self, user):
                    """Return board authorization scheme for the given user.
            
                    If user is not authenticated, only the read_board and read_comments can be made available. NOTE: global public
                    access should be controlled via the ACCOUNT_REQUIRED settings.
            Severity: Minor
            Found in openach/models.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 add_evidence has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

            def add_evidence(request, board_id):
                """Return a view of adding evidence (with a source), or handle the form submission."""
                board = get_object_or_404(Board, pk=board_id)
            
                if "add_elements" not in board.permissions.for_user(request.user):
            Severity: Minor
            Found in openach/views/evidence.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

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

                if team.owner_id is None or team.owner_id != request.user.id:
                    raise SuspiciousOperation(_("User is not the owner of the team"))
            Severity: Minor
            Found in openach/views/teams.py and 1 other location - About 55 mins to fix
            openach/views/teams.py on lines 73..74

            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

                if team.owner_id is None or team.owner_id != request.user.id:
                    raise SuspiciousOperation(_("User is not the owner of the team"))
            Severity: Minor
            Found in openach/views/teams.py and 1 other location - About 55 mins to fix
            openach/views/teams.py on lines 53..54

            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 detail has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

            def detail(request, board_id, dummy_board_slug=None):
                """Return a detail view for the given board.
            
                Evidence is sorted in order of diagnosticity. Hypotheses are sorted in order of consistency.
                """
            Severity: Minor
            Found in openach/views/boards.py - About 45 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

            Severity
            Category
            Status
            Source
            Language