GeriLife/caregiving

View on GitHub

Showing 6 of 160 total issues

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

import datetime
from typing import TYPE_CHECKING
from django.contrib.auth import get_user_model
from django.db.models import Count, Q, QuerySet
from django.utils import timezone
Severity: Minor
Found in homes/models.py - About 5 hrs to fix

    Function get_resident_percents_by_activity_level_normalized has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_resident_percents_by_activity_level_normalized(self) -> dict[str, float]:
            """Returns the resident counts by activity level annotated with a
            percent.
    
            The percent values, when rounded to the nearest integer, should
    Severity: Minor
    Found in homes/models.py - About 2 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

    File charts.py has 262 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    from django.db.models import Sum
    from django.utils.translation import gettext as _
    
    import pandas as pd
    import plotly.express as px
    Severity: Minor
    Found in homes/charts.py - About 2 hrs to fix

      Function post has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

          def post(self, request, *args, **kwargs):
              """Override the post method to add the resident activity in the same
              transaction as the activity."""
              form = self.get_form()
              is_form_valid = form.is_valid()
      Severity: Minor
      Found in activities/views.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

      Avoid deeply nested control flow statements.
      Open

                              if rounded_percents.sum() == 100:
                                  break
      
                  # Update the activity_counts dictionary with the adjusted percentages
                  keys = [
      Severity: Major
      Found in homes/models.py - About 45 mins to fix

        Function resident_counts_by_activity_level has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def resident_counts_by_activity_level(self) -> dict[str, int]:
                """Returns a dictionary of counts of residents by activity level."""
        
                annotated_residents = self.residents_with_recent_activity_counts
        
        
        Severity: Minor
        Found in homes/models.py - About 25 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