Skip to content

Commit

Permalink
Sk/2422 cog date source (#2445)
Browse files Browse the repository at this point in the history
* Replacing auto_now_add with default, Census/GSA with CENSUS/GSAFAC

* support model updates

* Updated file per MJ

* Recreate migrations

* Migrations for model change

* Using timezone.now

* Formatted with black

* Tested GSAFAC assignments

* Updated default for CognizantBaseline

* Updated migrations

* Changes requested in PR review
  • Loading branch information
gsa-suk authored Oct 12, 2023
1 parent dd0c36d commit e6376d8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
12 changes: 6 additions & 6 deletions backend/support/management/commands/seed_cog_baseline.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ def update_cogbaseline_w_csv(filename):
logger.info(
f"At start - row count for CognizantBaseline = {CognizantBaseline.objects.count()}"
)
CognizantBaseline.objects.filter(source="Census", is_active=True).delete()
CognizantBaseline.objects.filter(source="CENSUS", is_active=True).delete()
logger.info(
f"After deleting active rows - row count for CognizantBaseline = {CognizantBaseline.objects.count()}"
)
df = creat_df_from_csv(filename)
cogbaseline_inactives = CognizantBaseline.objects.filter(
source="Census", is_active=False
source="CENSUS", is_active=False
)
for cogbaseline_inactive in cogbaseline_inactives:
df = df[
Expand All @@ -71,15 +71,15 @@ def update_cogbaseline_w_csv(filename):
& (df["uei"] == cogbaseline_inactive.uei)
)
]
save_df_to_cogbaseline(df, "Census")
save_df_to_cogbaseline(df)
logger.info(
f"At end - row count for CognizantBaseline = {CognizantBaseline.objects.count()}"
)
rows_updated_in_cogbaseline = df.shape[0]
return rows_updated_in_cogbaseline


def save_df_to_cogbaseline(df, source):
def save_df_to_cogbaseline(df):
data = df.to_dict("records")
for item in data:
CognizantBaseline(
Expand All @@ -89,11 +89,11 @@ def save_df_to_cogbaseline(df, source):
cognizant_agency=item["cognizant_agency"],
date_assigned=item["date_assigned"],
is_active=item["is_active"],
source=source, # "Census",
source="CENSUS",
).save()


def load_all_cog_from_csv(filename):
df = creat_df_from_csv(filename)
save_df_to_cogbaseline(df, "Census")
save_df_to_cogbaseline(df)
return CognizantBaseline.objects.count()
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.2.5 on 2023-10-10 21:23

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):
dependencies = [
("support", "0003_alter_cognizantassignment_report_id"),
]

operations = [
migrations.AlterField(
model_name="cognizantbaseline",
name="date_assigned",
field=models.DateTimeField(
default=django.utils.timezone.now,
null=True,
verbose_name="Date Assigned",
),
),
migrations.AlterField(
model_name="cognizantbaseline",
name="source",
field=models.CharField(
default="GSAFAC", max_length=10, verbose_name="Source"
),
),
]
19 changes: 10 additions & 9 deletions backend/support/models.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,47 @@
from django.db import models
from django.utils import timezone


class CognizantBaseline(models.Model):
dbkey = models.CharField(
# help_text = "Identifier for a submission along with audit_year in Census FAC",
help_text="Identifier for a submission along with audit_year in Census FAC",
null=True,
max_length=20,
verbose_name="dbkey",
)
ein = models.CharField(
# help_text = "Primary Employer Identification Number",
help_text="Primary Employer Identification Number",
null=True,
max_length=30,
verbose_name="EIN",
)
uei = models.CharField(
# help_text = "Unique Employer Identification Number",
help_text="Unique Employer Identification Number",
null=True,
max_length=30,
verbose_name="UEI",
)
cognizant_agency = models.CharField(
# help_text = "Two digit Federal agency prefix of the cognizant agency",
help_text="Two digit Federal agency prefix of the cognizant agency",
max_length=2,
verbose_name="Cog Agency",
)
date_assigned = models.DateTimeField(
# help_text = "Time when the cog agency was assigned to the entity",
help_text="Time when the cog agency was assigned to the entity",
null=True, # allow nulls in case history has nulls
auto_now_add=True,
default=timezone.now,
verbose_name="Date Assigned",
)
is_active = models.BooleanField(
# help_text = "Record to be ignored if this field is False",
help_text="Record to be ignored if this field is False",
default=True,
verbose_name="Active",
)
source = models.CharField(
# help_text = "Source of cognizant data",
help_text="Source of cognizant data",
max_length=10,
verbose_name="Source",
default="GSA",
default="GSAFAC",
)


Expand Down
4 changes: 3 additions & 1 deletion backend/support/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def post_cog_assignment(sender, instance, created, **kwargs):
baseline.is_active = False
baseline.save()
CognizantBaseline(
ein=ein, uei=uei, cognizant_agency=cognizant_agency, source="GSA"
ein=ein,
uei=uei,
cognizant_agency=cognizant_agency,
).save()

try:
Expand Down

0 comments on commit e6376d8

Please sign in to comment.