Skip to content

Commit

Permalink
Sk/replace cogbaseline (#4547)
Browse files Browse the repository at this point in the history
* Replace CognizantBaseline with General

* Replace CognizantBaseline with General

* Replace CognizantBaseline with General

* Replace CognizantBaseline with General

* Replace CognizantBaseline with General

* Replace CognizantBaseline with General

* Replace CognizantBaseline with General

* Replace CognizantBaseline with General

* Replace CognizantBaseline with General

* Replace CognizantBaseline with General

* Replace CognizantBaseline with General

* Replace CognizantBaseline with General

* Replace CognizantBaseline with General

* Replace CognizantBaseline with General

* Replace CognizantBaseline with General

* Replace CognizantBaseline with General

* Replace CognizantBaseline with General

* Querying General for cognizant agency

* Updates

* Tested test cases

* Tested test cases

* Removed comments, Fixed format

* Formatting

* Added source create_staffusers.sh

* Updated comments

* Added a test case

* Message update

* Added test case

* Updated lookup_latest_cog

* Updated lookup_latest_cog

* Removed source tools/seed_cogbaseline.sh
  • Loading branch information
gsa-suk authored Dec 20, 2024
1 parent dfd3a10 commit 31b9a6e
Show file tree
Hide file tree
Showing 18 changed files with 184 additions and 2,885 deletions.
7 changes: 0 additions & 7 deletions backend/.profile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ source tools/api_teardown.sh
source tools/migrate_app_tables.sh
source tools/api_standup.sh
source tools/run_collectstatic.sh
source tools/seed_cog_baseline.sh
source tools/materialized_views.sh
source tools/create_staffusers.sh

Expand Down Expand Up @@ -48,12 +47,6 @@ if [[ "$CF_INSTANCE_INDEX" == 0 ]]; then
# run_collectstatic
# gonogo "run_collectstatic"

#####
# SEED COG/OVER TABLES
# Setup tables for cog/over assignments
seed_cog_baseline
gonogo "seed_cog_baseline"

# materialized_views
# gonogo "materialized_views"

Expand Down
42 changes: 0 additions & 42 deletions backend/audit/management/commands/README.md

This file was deleted.

82 changes: 0 additions & 82 deletions backend/audit/management/commands/csv_to_pg.py

This file was deleted.

7 changes: 0 additions & 7 deletions backend/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ source tools/curation_audit_tracking_init.sh
source tools/api_teardown.sh
source tools/migrate_app_tables.sh
source tools/api_standup.sh
source tools/seed_cog_baseline.sh
source tools/create_staffusers.sh

#####
Expand Down Expand Up @@ -44,12 +43,6 @@ gonogo "api_standup"
curation_audit_tracking_init
gonogo "curation_audit_tracking_init"

#####
# SEED COG/OVER TABLES
# Setup tables for cog/over assignments
seed_cog_baseline
gonogo "seed_cog_baseline"

#####
# CREATE STAFF USERS
# Prepares staff users for Django admin
Expand Down
26 changes: 1 addition & 25 deletions backend/support/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from audit.models import SingleAuditChecklist
from dissemination.models import TribalApiAccessKeyIds
from users.models import UserPermission
from .models import CognizantBaseline, CognizantAssignment, AssignmentTypeCode
from .models import CognizantAssignment, AssignmentTypeCode

import json
from datetime import date
Expand All @@ -32,30 +32,6 @@ def has_delete_permission(self, request, obj=None):
return False


@admin.register(CognizantBaseline)
class CognizantBaselineAdmin(SupportAdmin):
list_display = [
"uei",
"cognizant_agency",
"date_assigned",
"ein",
"dbkey",
"is_active",
"source",
]
list_filter = [
"source",
"is_active",
"cognizant_agency",
]

def has_change_permission(self, request, obj=None):
return False

def has_add_permission(self, request, obj=None):
return False


@admin.register(CognizantAssignment)
class CognizantAssignmentAdmin(SupportAdmin):
date_hierarchy = "date_assigned"
Expand Down
50 changes: 35 additions & 15 deletions backend/support/cog_over.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.db.models.functions import Cast
from django.db.models import BigIntegerField, Q

from support.models import CognizantBaseline, CognizantAssignment
from support.models import CognizantAssignment
from dissemination.models import General, MigrationInspectionRecord, FederalAward

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -53,8 +53,8 @@ def compute_cog_over(
oversight_agency = agency
# logger.warning("Assigning an oversight agenct", oversight_agency)
return (cognizant_agency, oversight_agency)
base_year = calc_base_year(audit_year)
cognizant_agency = determine_hist_agency(auditee_ein, auditee_uei, base_year)

cognizant_agency = determine_hist_agency(auditee_ein, auditee_uei, audit_year)
if cognizant_agency:
return (cognizant_agency, oversight_agency)
cognizant_agency = agency
Expand Down Expand Up @@ -100,12 +100,13 @@ def determine_agency(total_amount_expended, max_total_agency, max_da_agency):
return agency


def determine_hist_agency(ein, uei, base_year):
def determine_hist_agency(ein, uei, audit_year):
base_year = calc_base_year(audit_year)
dbkey = None
if int(base_year) == FIRST_BASELINE_YEAR:
dbkey = get_dbkey(ein, uei)

cog_agency = lookup_baseline(ein, uei, dbkey)
cog_agency = lookup_latest_cog(ein, uei, dbkey, base_year, audit_year)
if cog_agency:
return cog_agency

Expand Down Expand Up @@ -150,17 +151,36 @@ def get_dbkey(ein, uei):
return dbkey


def lookup_baseline(ein, uei, dbkey):
def lookup_latest_cog(ein, uei, dbkey, base_year, audit_year):
# Note: In Census historical data,
# From 2016 through 2022, (dbkey, ein) is the identifier for audits through 2021.
# In 2022, entities transitioned from dbkey to uei. 2022 data contains dbkey, ein and uei.
# From 2022 on, (ein, uei) is the identifier for audits.
query_years = [str(year) for year in range(int(base_year), int(audit_year) + 1)]
cognizant_agency = None

first_base_year_query_section = (
Q(auditee_ein=ein)
& Q(report_id__icontains=dbkey)
& Q(report_id__icontains="CENSUS")
)
other_year_query_section = Q(auditee_ein=ein) & Q(auditee_uei=uei)

query_subsection = other_year_query_section
if (int(base_year) == FIRST_BASELINE_YEAR) and (dbkey is not None):
query_subsection = first_base_year_query_section

try:
cognizant_agency = CognizantBaseline.objects.values_list(
"cognizant_agency", flat=True
).get(
Q(is_active=True)
& ((Q(ein=ein) & Q(dbkey=dbkey)) | (Q(ein=ein) & Q(uei=uei)))
)[
:
]
except (CognizantBaseline.DoesNotExist, CognizantBaseline.MultipleObjectsReturned):
cognizant_agency = (
General.objects.filter(Q(audit_year__in=query_years) & (query_subsection))
.exclude(cognizant_agency__isnull=True)
.exclude(cognizant_agency__exact="")
.order_by("-audit_year")
.values_list("cognizant_agency", flat=True)[:]
)
if len(cognizant_agency) >= 1:
return cognizant_agency[0]
except General.DoesNotExist:
cognizant_agency = None
return cognizant_agency

Expand Down
Loading

0 comments on commit 31b9a6e

Please sign in to comment.