GeriLife/caregiving

View on GitHub
homes/models.py

Summary

Maintainability
C
1 day
Test Coverage
A
95%

Showing 8 of 8 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

    Cyclomatic complexity is too high in method get_resident_percents_by_activity_level_normalized. (10)
    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 by radon

    Cyclomatic complexity is too high in method resident_counts_by_activity_level. (6)
    Open

    @property
    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 by radon

    Cyclomatic complexity is too high in function _structure_resident_data. (6)
    Open

    def _structure_resident_data(
    pivot_result: pd.DataFrame,
    current_residents: QuerySet,
    date_range: list[datetime.date],
    ) -> dict:
    Severity: Minor
    Found in homes/models.py by radon

    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

      Refactor this function to reduce its Cognitive Complexity from 21 to the 15 allowed.
      Open

      def get_resident_percents_by_activity_level_normalized(self) -> dict[str, float]:
      Severity: Critical
      Found in homes/models.py by sonar-python

      There are no issues that match your filters.

      Category
      Status