Skip to content

Commit

Permalink
Merge branch 'develop' into feature/1610-frontend-parsing-status
Browse files Browse the repository at this point in the history
  • Loading branch information
jtimpe committed Sep 29, 2023
2 parents cd8538e + fb6cc5f commit 1e78ffe
Show file tree
Hide file tree
Showing 13 changed files with 273 additions and 47 deletions.
44 changes: 44 additions & 0 deletions tdrs-backend/tdpservice/parsers/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,50 @@ def manager_parse_line(line, schema_manager, generate_error, is_encrypted=False)
)
])]


def get_schema_manager_options(program_type):
"""Return the allowed schema options."""
match program_type:
case 'TAN':
return {
'A': {
'T1': schema_defs.tanf.t1,
'T2': schema_defs.tanf.t2,
'T3': schema_defs.tanf.t3,
},
'C': {
'T4': schema_defs.tanf.t4,
'T5': schema_defs.tanf.t5,
},
'G': {
'T6': schema_defs.tanf.t6,
},
'S': {
'T7': schema_defs.tanf.t7,
},
}
case 'SSP':
return {
'A': {
'M1': schema_defs.ssp.m1,
'M2': schema_defs.ssp.m2,
'M3': schema_defs.ssp.m3,
},
'C': {
# 'M4': schema_options.m4,
# 'M5': schema_options.m5,
},
'G': {
# 'M6': schema_options.m6,
},
'S': {
# 'M7': schema_options.m7,
},
}
# case tribal?
return None


def get_schema_manager(line, section, program_type):
"""Return the appropriate schema for the line."""
line_type = line[0:2]
Expand Down
2 changes: 2 additions & 0 deletions tdrs-backend/tdpservice/parsers/schema_defs/tanf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
from .t4 import t4
from .t5 import t5
from .t6 import t6
from .t7 import t7

t1 = t1
t2 = t2
t3 = t3
t4 = t4
t5 = t5
t6 = t6
t7 = t7
65 changes: 65 additions & 0 deletions tdrs-backend/tdpservice/parsers/schema_defs/tanf/t7.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""Schema for TANF T7 Row."""

from ...util import SchemaManager
from ...fields import Field, TransformField
from ...row_schema import RowSchema
from ...transforms import calendar_quarter_to_rpt_month_year
from ... import validators
from tdpservice.search_indexes.models.tanf import TANF_T7

schemas = []

validator_index = 7
section_ind_index = 7
stratum_index = 8
families_index = 10
for i in range(1, 31):
month_index = (i - 1) % 3
sub_item_labels = ['A', 'B', 'C']
families_value_item_number = f"6{sub_item_labels[month_index]}"

schemas.append(
RowSchema(
model=TANF_T7,
quiet_preparser_errors=i > 1,
preparsing_validators=[
validators.notEmpty(0, 7),
validators.notEmpty(validator_index, validator_index + 24),
],
postparsing_validators=[],
fields=[
Field(item="0", name="RecordType", type='string', startIndex=0, endIndex=2,
required=True, validators=[]),
Field(item="3", name='CALENDAR_QUARTER', type='number', startIndex=2, endIndex=7,
required=True, validators=[validators.dateYearIsLargerThan(1998),
validators.quarterIsValid()]),
TransformField(
transform_func=calendar_quarter_to_rpt_month_year(month_index),
item="3A",
name='RPT_MONTH_YEAR',
type='number',
startIndex=2,
endIndex=7,
required=True,
validators=[
validators.dateYearIsLargerThan(1998),
validators.dateMonthIsValid()
]
),
Field(item="4", name='TDRS_SECTION_IND', type='string', startIndex=section_ind_index,
endIndex=section_ind_index + 1, required=True, validators=[validators.oneOf(['1', '2'])]),
Field(item="5", name='STRATUM', type='string', startIndex=stratum_index,
endIndex=stratum_index + 2, required=True, validators=[validators.isInStringRange(1, 99)]),
Field(item=families_value_item_number, name='FAMILIES_MONTH', type='number', startIndex=families_index,
endIndex=families_index + 7, required=True, validators=[validators.isInLimits(0, 9999999)]),
]
)
)

index_offset = 0 if i % 3 != 0 else 24
validator_index += index_offset
section_ind_index += index_offset
stratum_index += index_offset
families_index += 7 if i % 3 != 0 else 10

t7 = SchemaManager(schemas=schemas)
3 changes: 3 additions & 0 deletions tdrs-backend/tdpservice/parsers/test/data/ADS.E2J.FTP4.TS06
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
HEADER20204S06 TAN1 N
T720204101006853700680540068454103000312400037850003180104000347400036460003583106000044600004360000325299000506200036070003385202000039100002740000499
TRAILER0000001
14 changes: 14 additions & 0 deletions tdrs-backend/tdpservice/parsers/test/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,17 @@ class Meta:
NUM_BIRTHS = 1
NUM_OUTWEDLOCK_BIRTHS = 1
NUM_CLOSED_CASES = 1

class TanfT7Factory(factory.django.DjangoModelFactory):
"""Generate TANF T7 record for testing."""

class Meta:
"""Hardcoded meta data for TANF_T7."""

model = "search_indexes.TANF_T7"

CALENDAR_QUARTER = 20204
RPT_MONTH_YEAR = 202011
TDRS_SECTION_IND = '1'
STRATUM = '01'
FAMILIES_MONTH = 1
31 changes: 30 additions & 1 deletion tdrs-backend/tdpservice/parsers/test/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from .. import parse
from ..models import ParserError, ParserErrorCategoryChoices, DataFileSummary
from tdpservice.search_indexes.models.tanf import TANF_T1, TANF_T2, TANF_T3, TANF_T4, TANF_T5, TANF_T6
from tdpservice.search_indexes.models.tanf import TANF_T1, TANF_T2, TANF_T3, TANF_T4, TANF_T5, TANF_T6, TANF_T7
from tdpservice.search_indexes.models.ssp import SSP_M1, SSP_M2, SSP_M3
from .factories import DataFileSummaryFactory
from tdpservice.data_files.models import DataFile
Expand Down Expand Up @@ -833,3 +833,32 @@ def test_parse_tanf_section3_file(tanf_section3_file):
assert first.NUM_CLOSED_CASES == 3884
assert second.NUM_CLOSED_CASES == 3881
assert third.NUM_CLOSED_CASES == 5453

@pytest.fixture
def tanf_section4_file(stt_user, stt):
"""Fixture for ADS.E2J.FTP4.TS06."""
return util.create_test_datafile('ADS.E2J.FTP4.TS06', stt_user, stt, "Stratum Data")

@pytest.mark.django_db()
def test_parse_tanf_section4_file(tanf_section4_file):
"""Test parsing TANF Section 4 submission."""
parse.parse_datafile(tanf_section4_file)

assert TANF_T7.objects.all().count() == 18

parser_errors = ParserError.objects.filter(file=tanf_section4_file)
assert parser_errors.count() == 0

t7_objs = TANF_T7.objects.all().order_by('FAMILIES_MONTH')

first = t7_objs.first()
sixth = t7_objs[5]

assert first.RPT_MONTH_YEAR == 202011
assert sixth.RPT_MONTH_YEAR == 202012

assert first.TDRS_SECTION_IND == '2'
assert sixth.TDRS_SECTION_IND == '2'

assert first.FAMILIES_MONTH == 274
assert sixth.FAMILIES_MONTH == 499
2 changes: 1 addition & 1 deletion tdrs-backend/tdpservice/parsers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def get_schema_options(program, section, query=None, model=None, model_name=None
'S': {
'section': DataFile.Section.STRATUM_DATA,
'models': {
# 'T7': schema_defs.tanf.t7,
'T7': schema_defs.tanf.t7,
}
}
},
Expand Down
8 changes: 6 additions & 2 deletions tdrs-backend/tdpservice/scheduling/parser_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ def parse(data_file_id):
dfs = DataFileSummary.objects.create(datafile=data_file, status=DataFileSummary.Status.PENDING)
errors = parse_datafile(data_file)
dfs.status = dfs.get_status()
dfs.case_aggregates = case_aggregates_by_month(data_file, dfs.status)

if "Case Data" in data_file.section:
dfs.case_aggregates = case_aggregates_by_month(data_file, dfs.status)

dfs.save()
logger.info(f"DataFile parsing finished with status {dfs.status} and {len(errors)} errors: {errors}")

logger.info(f"Parsing finished for file -> {repr(data_file)} with status {dfs.status} and {len(errors)} errors.")
11 changes: 8 additions & 3 deletions tdrs-backend/tdpservice/search_indexes/admin/tanf.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,17 @@ class TANF_T7Admin(admin.ModelAdmin):
"""ModelAdmin class for parsed T7 data files."""

list_display = [
'record',
'rpt_month_year',
'RecordType',
'CALENDAR_QUARTER',
'RPT_MONTH_YEAR',
'TDRS_SECTION_IND',
'STRATUM',
'FAMILIES_MONTH',
'datafile',
]

list_filter = [
'CALENDAR_QUARTER',
CreationDateFilter,
'rpt_month_year',
'RPT_MONTH_YEAR',
]
13 changes: 6 additions & 7 deletions tdrs-backend/tdpservice/search_indexes/documents/tanf.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,10 @@ class Django:

model = TANF_T7
fields = [
'record',
'rpt_month_year',
'fips_code',
'calendar_quarter',
'tdrs_section_ind',
'stratum',
'families',
"RecordType",
"CALENDAR_QUARTER",
"RPT_MONTH_YEAR",
"TDRS_SECTION_IND",
"STRATUM",
"FAMILIES_MONTH",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Generated by Django 3.2.15 on 2023-09-20 18:46

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('search_indexes', '0017_auto_20230914_1720'),
]

operations = [
migrations.RemoveField(
model_name='tanf_t7',
name='calendar_quarter',
),
migrations.RemoveField(
model_name='tanf_t7',
name='families',
),
migrations.RemoveField(
model_name='tanf_t7',
name='fips_code',
),
migrations.RemoveField(
model_name='tanf_t7',
name='record',
),
migrations.RemoveField(
model_name='tanf_t7',
name='rpt_month_year',
),
migrations.RemoveField(
model_name='tanf_t7',
name='stratum',
),
migrations.RemoveField(
model_name='tanf_t7',
name='tdrs_section_ind',
),
migrations.AddField(
model_name='tanf_t7',
name='CALENDAR_QUARTER',
field=models.IntegerField(blank=True, null=True),
),
migrations.AddField(
model_name='tanf_t7',
name='FAMILIES_MONTH',
field=models.IntegerField(null=True),
),
migrations.AddField(
model_name='tanf_t7',
name='RPT_MONTH_YEAR',
field=models.IntegerField(null=True),
),
migrations.AddField(
model_name='tanf_t7',
name='RecordType',
field=models.CharField(max_length=156, null=True),
),
migrations.AddField(
model_name='tanf_t7',
name='STRATUM',
field=models.CharField(max_length=2, null=True),
),
migrations.AddField(
model_name='tanf_t7',
name='TDRS_SECTION_IND',
field=models.CharField(max_length=1, null=True),
),
]
16 changes: 7 additions & 9 deletions tdrs-backend/tdpservice/search_indexes/models/tanf.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,13 @@ class TANF_T7(models.Model):
related_name='t7_parent'
)

record = models.CharField(max_length=156, null=False, blank=False)
rpt_month_year = models.IntegerField(null=False, blank=False)
fips_code = models.CharField(max_length=100, null=False, blank=False)

calendar_quarter = models.IntegerField(null=False, blank=False)
tdrs_section_ind = models.CharField(
RecordType = models.CharField(max_length=156, null=True, blank=False)
CALENDAR_QUARTER = models.IntegerField(null=True, blank=True)
RPT_MONTH_YEAR = models.IntegerField(null=True, blank=False)
TDRS_SECTION_IND = models.CharField(
max_length=1,
null=False,
null=True,
blank=False
)
stratum = models.CharField(max_length=2, null=False, blank=False)
families = models.IntegerField(null=False, blank=False)
STRATUM = models.CharField(max_length=2, null=True, blank=False)
FAMILIES_MONTH = models.IntegerField(null=True, blank=False)
Loading

0 comments on commit 1e78ffe

Please sign in to comment.