fedspendingtransparency/usaspending-api

View on GitHub

Showing 118 of 226 total issues

File disaster_base.py has 504 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import json
from datetime import date
from functools import lru_cache
from typing import Dict, List, Optional

Severity: Major
Found in usaspending_api/disaster/v2/views/disaster_base.py - About 1 day to fix

    File conftest.py has 477 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import logging
    import os
    import sys
    import tempfile
    from pathlib import Path
    Severity: Minor
    Found in usaspending_api/conftest.py - About 7 hrs to fix

      File spending_by_geography.py has 477 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import copy
      import logging
      from decimal import Decimal
      from enum import Enum
      from typing import Dict, List, Optional
      Severity: Minor
      Found in usaspending_api/search/v2/views/spending_by_geography.py - About 7 hrs to fix

        File transaction_search.py has 471 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        from django.contrib.postgres.fields import ArrayField
        from django.db import models
        from django.db.models import Q
        
        from usaspending_api.common.custom_django_fields import NumericField
        Severity: Minor
        Found in usaspending_api/search/models/transaction_search.py - About 7 hrs to fix

          File spending_by_award.py has 469 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import copy
          from ast import literal_eval
          
          from sys import maxsize
          from typing import List
          Severity: Minor
          Found in usaspending_api/search/v2/views/spending_by_award.py - About 7 hrs to fix

            Function construct_es_response_for_prime_awards has a Cognitive Complexity of 57 (exceeds 15 allowed). Consider refactoring.
            Open

                def construct_es_response_for_prime_awards(self, response) -> dict:
                    results = []
                    should_return_display_award_id = "Award ID" in self.fields
                    should_return_recipient_id = "recipient_id" in self.fields
                    for res in response:
            Severity: Minor
            Found in usaspending_api/search/v2/views/spending_by_award.py - About 7 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 covid_faba_spending.py has 461 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            COVID_FABA_SPENDING_COLUMNS = {
                "id": {"delta": "INTEGER", "postgres": "INTEGER NOT NULL"},
                "spending_level": {"delta": "STRING", "postgres": "TEXT"},
                "funding_toptier_agency_id": {"delta": "STRING", "postgres": "TEXT"},
                "funding_toptier_agency_code": {"delta": "STRING", "postgres": "TEXT"},
            Severity: Minor
            Found in usaspending_api/disaster/delta_models/covid_faba_spending.py - About 7 hrs to fix

              Function initial_run has a Cognitive Complexity of 51 (exceeds 15 allowed). Consider refactoring.
              Open

                  def initial_run(self, next_last_load):
                      """
                      Procedure to create & set up transaction_id_lookup and award_id_lookup tables and create other tables in
                      int database that will be populated by subsequent calls.
                      """
              Severity: Minor
              Found in usaspending_api/etl/management/commands/load_transactions_in_delta.py - About 6 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 create_q_from_filter has a Cognitive Complexity of 50 (exceeds 15 allowed). Consider refactoring.
              Open

                  def create_q_from_filter(self, filt):
                      if "combine_method" in filt:
                          return self.create_q_from_filter_list(filt["filters"], filt["combine_method"])
                      else:
                          q_kwargs = {}
              Severity: Minor
              Found in usaspending_api/common/api_request_utils.py - About 6 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 populate_reporting_agency_overview.py has 420 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              import logging
              
              from enum import Enum
              
              from django.core.management import BaseCommand

                File spending_over_time.py has 415 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                import copy
                import logging
                from calendar import monthrange
                from collections import OrderedDict
                from datetime import datetime, timezone
                Severity: Minor
                Found in usaspending_api/search/v2/views/spending_over_time.py - About 5 hrs to fix

                  File test_award_index_elasticsearch.py has 413 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  import pytest
                  
                  from model_bakery import baker
                  
                  
                  
                  Severity: Minor
                  Found in usaspending_api/tests/integration/test_award_index_elasticsearch.py - About 5 hrs to fix

                    File recipients.py has 405 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    import logging
                    import uuid
                    
                    from decimal import Decimal
                    
                    
                    Severity: Minor
                    Found in usaspending_api/recipient/v2/views/recipients.py - About 5 hrs to fix

                      File transaction_fpds.py has 402 lines of code (exceeds 250 allowed). Consider refactoring.
                      Open

                      from usaspending_api.common.data_classes import TransactionColumn
                      
                      TRANSACTION_FPDS_COLUMN_INFO = [
                          TransactionColumn("a_76_fair_act_action", "a_76_fair_act_action", "STRING"),
                          TransactionColumn("a_76_fair_act_action_desc", "a_76_fair_act_action_desc", "STRING"),
                      Severity: Minor
                      Found in usaspending_api/transactions/delta_models/transaction_fpds.py - About 5 hrs to fix

                        File disaster_covid19_file_d1_awards.py has 391 lines of code (exceeds 250 allowed). Consider refactoring.
                        Open

                        d1_awards_sql_string = """
                        SELECT
                            award_search.generated_unique_award_id AS contract_award_unique_key,
                            award_search.piid AS award_id_piid,
                            latest_transaction.referenced_idv_agency_iden AS parent_award_agency_id,

                          File gsdm_maps.py has 381 lines of code (exceeds 250 allowed). Consider refactoring.
                          Open

                          """
                          This is a map of code enumerations, extracted from the GSDM
                          
                          Each should be named following this pattern:
                              - For a field that is unique among all models, <field>_map
                          Severity: Minor
                          Found in usaspending_api/data/gsdm_maps.py - About 5 hrs to fix

                            Function get_download_sources has a Cognitive Complexity of 44 (exceeds 15 allowed). Consider refactoring.
                            Open

                            def get_download_sources(
                                json_request: dict, download_job: DownloadJob = None, origination: Optional[str] = None
                            ) -> List[DownloadSource]:
                                download_sources = []
                                for download_type in json_request["download_types"]:
                            Severity: Minor
                            Found in usaspending_api/download/filestreaming/download_generation.py - About 5 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 field_mappings_fpds.py has 378 lines of code (exceeds 250 allowed). Consider refactoring.
                            Open

                            from usaspending_api.broker.helpers.award_category_helper import award_types
                            from usaspending_api.etl.transaction_loaders.derived_field_functions_fpds import (
                                calculate_fiscal_year,
                                calculate_awarding_agency,
                                calculate_funding_agency,
                            Severity: Minor
                            Found in usaspending_api/etl/transaction_loaders/field_mappings_fpds.py - About 5 hrs to fix

                              Function process_data has a Cognitive Complexity of 42 (exceeds 15 allowed). Consider refactoring.
                              Open

                                  def process_data(self):
                                      # Make sure we weren't flagged to exit
                                      while True:
                                          row = self.data_queue.get()
                                          # If row is none, we need to die.
                              Severity: Minor
                              Found in usaspending_api/common/threaded_data_loader.py - About 4 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 settings.py has 356 lines of code (exceeds 250 allowed). Consider refactoring.
                              Open

                              """
                              For more information on this file: https://docs.djangoproject.com/en/3.2/topics/settings/
                              For the full list of settings and their values: https://docs.djangoproject.com/en/3.2/ref/settings/
                              """
                              
                              
                              Severity: Minor
                              Found in usaspending_api/settings.py - About 4 hrs to fix
                                Severity
                                Category
                                Status
                                Source
                                Language