fedspendingtransparency/usaspending-api

View on GitHub

Showing 118 of 226 total issues

File download_column_historical_lookups.py has 3065 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Sets up mappings from column names used in downloads to the query paths used to get the data from django.

Not in use while we pull CSV data from the non-historical tables. Until we switch to pulling CSV downloads from the
historical tables TransactionFPDS and TransactionFABS, import download_column_lookups.py instead.
Severity: Major
Found in usaspending_api/download/v2/download_column_historical_lookups.py - About 1 wk to fix

    Function matview_search_filter has a Cognitive Complexity of 176 (exceeds 15 allowed). Consider refactoring.
    Open

    def matview_search_filter(filters, model, for_downloads=False):
        queryset = model.objects.all()
    
        recipient_scope_q = Q(recipient_location_country_code="USA") | Q(recipient_location_country_name="UNITED STATES")
        pop_scope_q = Q(pop_country_code="USA") | Q(pop_country_name="UNITED STATES")
    Severity: Minor
    Found in usaspending_api/awards/v2/filters/search.py - About 3 days 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 load_transactions_in_delta.py has 1270 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import copy
    import logging
    import re
    
    from contextlib import contextmanager
    Severity: Major
    Found in usaspending_api/etl/management/commands/load_transactions_in_delta.py - About 3 days to fix

      File conftest_spark.py has 1200 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import json
      import logging
      import uuid
      from datetime import datetime
      from pathlib import Path
      Severity: Major
      Found in usaspending_api/tests/conftest_spark.py - About 3 days to fix

        Function subaward_filter has a Cognitive Complexity of 144 (exceeds 15 allowed). Consider refactoring.
        Open

        def subaward_filter(filters, for_downloads=False):
            queryset = SubawardSearch.objects.all()
        
            recipient_scope_q = Q(sub_legal_entity_country_code="USA") | Q(sub_legal_entity_country_name="UNITED STATES")
            pop_scope_q = Q(sub_place_of_perform_country_co="USA") | Q(sub_place_of_perform_country_name="UNITED STATES")
        Severity: Minor
        Found in usaspending_api/awards/v2/filters/sub_award.py - About 2 days 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 download_annotation_functions.py has 863 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import datetime
        from typing import List, Optional
        
        from django.db.models.functions import Cast, Coalesce
        from django.db.models import (
        Severity: Major
        Found in usaspending_api/download/helpers/download_annotation_functions.py - About 2 days to fix

          Function post has a Cognitive Complexity of 110 (exceeds 15 allowed). Consider refactoring.
          Open

              def post(self, request, pk, format=None):
                  # create response
                  response = {"results": {}}
          
                  # get federal account id from url
          Severity: Minor
          Found in usaspending_api/accounts/views/federal_accounts_v2.py - About 2 days 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 sqs_work_dispatcher.py has 825 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import logging
          import inspect
          import json
          import os
          
          
          Severity: Major
          Found in usaspending_api/common/sqs/sqs_work_dispatcher.py - About 1 day to fix

            File query_with_filters.py has 784 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            import copy
            import itertools
            import logging
            import re
            from datetime import datetime
            Severity: Major
            Found in usaspending_api/common/query_with_filters.py - About 1 day to fix

              Function validate_post_request has a Cognitive Complexity of 96 (exceeds 15 allowed). Consider refactoring.
              Open

                  def validate_post_request(self, request):
                      if "filters" in request:
                          for filt in request["filters"]:
                              if "combine_method" in filt:
                                  try:
              Severity: Minor
              Found in usaspending_api/common/api_request_utils.py - About 1 day 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 request_validations.py has 723 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              import json
              from copy import deepcopy
              from datetime import datetime, MINYEAR, MAXYEAR
              from django.conf import settings
              from typing import Optional
              Severity: Major
              Found in usaspending_api/download/v2/request_validations.py - About 1 day to fix

                File swap_in_new_table.py has 672 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                import json
                import logging
                import re
                
                from datetime import datetime
                Severity: Major
                Found in usaspending_api/etl/management/commands/swap_in_new_table.py - About 1 day to fix

                  Function get_business_categories_fpds has a Cognitive Complexity of 83 (exceeds 15 allowed). Consider refactoring.
                  Open

                  def get_business_categories_fpds(row):
                      # This function is supposed to be invoked as a Spark UDF with a named_struct containing the necessary
                      # fields passed to it.
                  
                      def row_get(row, col_name):
                  Severity: Minor
                  Found in usaspending_api/broker/helpers/get_business_categories.py - About 1 day 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 spark.py has 639 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  """
                  Spark utility functions that could be used as stages or steps of an ETL job (aka "data pipeline")
                  
                  NOTE: This is distinguished from the usaspending_api.common.helpers.spark_helpers module, which holds mostly boilerplate
                  functions for setup and configuration of the spark environment
                  Severity: Major
                  Found in usaspending_api/common/etl/spark.py - About 1 day to fix

                    Function build_elasticsearch_result has a Cognitive Complexity of 81 (exceeds 15 allowed). Consider refactoring.
                    Open

                        def build_elasticsearch_result(self, response: dict) -> Dict[str, dict]:
                            results = {}
                            geo_info_buckets = response.get("group_by_agg_key", {}).get("buckets", [])
                    
                            for bucket in geo_info_buckets:
                    Severity: Minor
                    Found in usaspending_api/disaster/v2/views/spending_by_geography.py - About 1 day 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 download_generation.py has 631 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    import json
                    import logging
                    import multiprocessing
                    import os
                    from copy import deepcopy
                    Severity: Major
                    Found in usaspending_api/download/filestreaming/download_generation.py - About 1 day to fix

                      File award_search.py has 631 lines of code (exceeds 250 allowed). Consider refactoring.
                      Open

                      from usaspending_api.awards.v2.lookups.lookups import award_type_mapping
                      
                      AWARD_SEARCH_COLUMNS = {
                          "treasury_account_identifiers": {"delta": "ARRAY<INTEGER>", "postgres": "INTEGER[]", "gold": False},
                          "award_id": {"delta": "LONG NOT NULL", "postgres": "BIGINT NOT NULL", "gold": False},
                      Severity: Major
                      Found in usaspending_api/search/delta_models/award_search.py - About 1 day to fix

                        File federal_accounts_v2.py has 626 lines of code (exceeds 250 allowed). Consider refactoring.
                        Open

                        import ast
                        from collections import OrderedDict
                        from typing import List
                        
                        from django.db.models import DecimalField, Exists, F, Func, OuterRef, Q, Subquery, Sum
                        Severity: Major
                        Found in usaspending_api/accounts/views/federal_accounts_v2.py - About 1 day to fix

                          File delete_data.py has 560 lines of code (exceeds 250 allowed). Consider refactoring.
                          Open

                          import logging
                          from time import perf_counter
                          from typing import Any, Dict, List, Optional, Union
                          
                          import pandas as pd
                          Severity: Major
                          Found in usaspending_api/etl/elasticsearch_loader_helpers/delete_data.py - About 1 day to fix

                            Function type_filter has a Cognitive Complexity of 67 (exceeds 15 allowed). Consider refactoring.
                            Open

                            def type_filter(_type, filters, limit=None):
                                _types = [
                                    "budget_function",
                                    "budget_subfunction",
                                    "federal_account",
                            Severity: Minor
                            Found in usaspending_api/spending_explorer/v2/filters/type_filter.py - About 1 day 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