Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sk/replace cogbaseline #4547

Merged
merged 34 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e7383ce
Replace CognizantBaseline with General
gsa-suk Dec 6, 2024
27f90c9
Replace CognizantBaseline with General
gsa-suk Dec 6, 2024
cb37561
Replace CognizantBaseline with General
gsa-suk Dec 6, 2024
61e208b
Replace CognizantBaseline with General
gsa-suk Dec 6, 2024
8d89cce
Replace CognizantBaseline with General
gsa-suk Dec 6, 2024
1a2f26c
Replace CognizantBaseline with General
gsa-suk Dec 6, 2024
fc014a8
Replace CognizantBaseline with General
gsa-suk Dec 6, 2024
958c968
Replace CognizantBaseline with General
gsa-suk Dec 6, 2024
7aaf416
Replace CognizantBaseline with General
gsa-suk Dec 6, 2024
6fd25bf
Replace CognizantBaseline with General
gsa-suk Dec 6, 2024
091e5c7
Replace CognizantBaseline with General
gsa-suk Dec 6, 2024
7bfc7b8
Replace CognizantBaseline with General
gsa-suk Dec 6, 2024
f67d8e3
Replace CognizantBaseline with General
gsa-suk Dec 6, 2024
b046cbf
Replace CognizantBaseline with General
gsa-suk Dec 6, 2024
d8cc680
Replace CognizantBaseline with General
gsa-suk Dec 6, 2024
a462f9f
Replace CognizantBaseline with General
gsa-suk Dec 6, 2024
4007315
Replace CognizantBaseline with General
gsa-suk Dec 6, 2024
7f9a868
Querying General for cognizant agency
gsa-suk Dec 9, 2024
4d345f3
Merge branch 'main' of github.com:GSA-TTS/FAC into sk/replace_cogbase…
gsa-suk Dec 11, 2024
731f82e
Updates
gsa-suk Dec 11, 2024
2dd1a0f
Tested test cases
gsa-suk Dec 13, 2024
5e2cfe7
Tested test cases
gsa-suk Dec 13, 2024
cdf4e34
Merge branch 'main' of github.com:GSA-TTS/FAC into sk/replace_cogbase…
gsa-suk Dec 13, 2024
bbe2f45
Removed comments, Fixed format
gsa-suk Dec 13, 2024
fe61234
Formatting
gsa-suk Dec 16, 2024
1621e3f
Added source create_staffusers.sh
gsa-suk Dec 17, 2024
298402b
Updated comments
gsa-suk Dec 17, 2024
e8e1e31
Added a test case
gsa-suk Dec 17, 2024
6e24a3d
Message update
gsa-suk Dec 18, 2024
e29aa96
Merge branch 'sk/replace_cogbaseline' of github.com:GSA-TTS/FAC into …
gsa-suk Dec 18, 2024
4c3bac7
Added test case
gsa-suk Dec 18, 2024
d760c7b
Updated lookup_latest_cog
gsa-suk Dec 18, 2024
e171792
Updated lookup_latest_cog
gsa-suk Dec 18, 2024
966d756
Removed source tools/seed_cogbaseline.sh
gsa-suk Dec 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
gsa-suk marked this conversation as resolved.
Show resolved Hide resolved
# 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
Loading