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

Tribal Section 1 Parsing & Validation #2742

Merged
merged 112 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 85 commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
f8a4d54
Added formating for header and autofit columns
raftmsohani Oct 19, 2023
29fd04c
Formatted the headers
raftmsohani Oct 20, 2023
699245c
added year/month to the columns
raftmsohani Oct 20, 2023
5310946
Added contants - translation column
raftmsohani Oct 23, 2023
0269728
added friendly names to T1 and T2
raftmsohani Oct 25, 2023
ac120a6
added friendly name to m1 and m2
raftmsohani Oct 26, 2023
a7c1207
added friendly name to m3
raftmsohani Oct 26, 2023
d460fe2
added friendly_name to t3
raftmsohani Oct 27, 2023
2bb6622
added friendly_name to t4 and t5
raftmsohani Oct 27, 2023
c90ce75
added friendly_name to t7
raftmsohani Oct 27, 2023
9dfd6f8
correct missing friendly_name
raftmsohani Oct 27, 2023
90aea2f
correction on failing tests
raftmsohani Oct 27, 2023
8f210cd
addedfriendly name to excel report
raftmsohani Oct 30, 2023
a093aa0
linting
raftmsohani Oct 30, 2023
8ea36c6
linting
raftmsohani Oct 30, 2023
85da10b
linting
raftmsohani Oct 30, 2023
ac95c41
delete contants.py
raftmsohani Oct 30, 2023
d75ba04
added test for json field in error model
raftmsohani Oct 30, 2023
ea5aa30
linting
raftmsohani Oct 31, 2023
b4d0549
linting
raftmsohani Oct 31, 2023
8ce83ce
linting
raftmsohani Oct 31, 2023
7719e85
- Added Tribal models, docs, admin refs
elipe17 Oct 31, 2023
0408123
- Update t1 field validators
elipe17 Oct 31, 2023
d1a9407
- t2/t3 field validators
elipe17 Oct 31, 2023
c75bb7e
2599-added friendly name to postparsing validators
raftmsohani Nov 1, 2023
179a81c
- Updated cat3 validators
elipe17 Nov 1, 2023
77acd5a
- Updated how we detect tribe code
elipe17 Nov 1, 2023
2eb688f
- Added error handling for inconsistent header info wrt tribe code
elipe17 Nov 1, 2023
df77436
- Updated test
elipe17 Nov 1, 2023
8da540e
- Grammar fix
elipe17 Nov 1, 2023
b8671dc
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Nov 6, 2023
1dce7d4
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Nov 6, 2023
0ec8f16
refining the validator tests
raftmsohani Nov 7, 2023
3f9bfce
- Format with Black
elipe17 Nov 7, 2023
c8607b2
- Fix lint
elipe17 Nov 7, 2023
164af6a
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Nov 7, 2023
359dae0
added returning fields names to validators
raftmsohani Nov 8, 2023
8ed0b4a
added friendly_name to error field
raftmsohani Nov 13, 2023
c57a2d5
Merge branch 'develop' into 2599-error-report-corrections-impact-wpr-…
raftmsohani Nov 14, 2023
812a2dd
linting
raftmsohani Nov 14, 2023
96634b2
corrections on views/tests
raftmsohani Nov 14, 2023
0be491f
corrections for fields
raftmsohani Nov 15, 2023
02ce7d0
failing test corrected
raftmsohani Nov 15, 2023
aa8a534
failing test corrected
raftmsohani Nov 15, 2023
19926ea
correcting test failures
raftmsohani Nov 15, 2023
6b7c86e
linting
raftmsohani Nov 16, 2023
94ef180
corrected the excel fiel generator
raftmsohani Nov 16, 2023
b6eee03
removed excessive space in validator
raftmsohani Nov 20, 2023
49dc398
linting
raftmsohani Nov 20, 2023
b0fd38a
Merge branch 'develop' into 2599-error-report-corrections-impact-wpr-…
raftmsohani Nov 20, 2023
b869b19
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Nov 20, 2023
92a549f
- Updated based on review feedback
elipe17 Nov 20, 2023
f4e6bfa
- removing debug assert
elipe17 Nov 20, 2023
3699cdf
- Fix lint
elipe17 Nov 20, 2023
700a965
listing
raftmsohani Nov 20, 2023
8aae444
Merge branch 'develop' into 2599-error-report-corrections-impact-wpr-…
raftmsohani Nov 21, 2023
a32fde6
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Nov 21, 2023
7d1eb79
- deconflicting migrations
elipe17 Nov 21, 2023
41cada2
- Fixing test
elipe17 Nov 21, 2023
9636854
added m6
raftmsohani Nov 21, 2023
5c2e819
lint
raftmsohani Nov 21, 2023
763c09b
corrected new line break
raftmsohani Nov 22, 2023
3e73dbc
refactored validator logic
raftmsohani Nov 22, 2023
4f6039b
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Nov 22, 2023
8161b4c
- resolving conflict
elipe17 Nov 22, 2023
8a5665a
- Fix lint errors
elipe17 Nov 22, 2023
2d68b52
- Resolve conflict
elipe17 Nov 22, 2023
e1c9c9a
Merge branch 'develop' into 2599-error-report-corrections-impact-wpr-…
raftmsohani Nov 25, 2023
dcc1dca
linting and correction on t1
raftmsohani Nov 25, 2023
741b442
Merge branch 'develop' into 2599-error-report-corrections-impact-wpr-…
raftmsohani Nov 25, 2023
28c9636
friendly_name correction from comments
raftmsohani Nov 25, 2023
091e716
Merge branch '2599-error-report-corrections-impact-wpr-metrics' of ht…
raftmsohani Nov 25, 2023
3e19f2d
friendly_name correction
raftmsohani Nov 25, 2023
c2501f8
corrected failing test for m5
raftmsohani Nov 25, 2023
b04df52
refactor the field_json creation DRY
raftmsohani Nov 27, 2023
cda507d
- Renamed tribal files
elipe17 Nov 27, 2023
f79364f
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Nov 27, 2023
1838bf8
- Reduced file size
elipe17 Nov 27, 2023
7ae9054
- Fix lint errors
elipe17 Nov 27, 2023
ad17b56
friendly_name corrections
raftmsohani Nov 30, 2023
efc15bd
Merge branch 'develop' into 2599-error-report-corrections-impact-wpr-…
raftmsohani Nov 30, 2023
71daf97
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Dec 4, 2023
a3a835b
Merge branch '2599-error-report-corrections-impact-wpr-metrics' of ht…
elipe17 Dec 4, 2023
fdd3b72
- Adding friendly names to tribal
elipe17 Dec 4, 2023
7d06746
- Fixing typo
elipe17 Dec 4, 2023
d2d443d
linting and cleaning errors
raftmsohani Dec 4, 2023
573a056
linting
raftmsohani Dec 4, 2023
b1be7bb
correction on friendly_names
raftmsohani Dec 4, 2023
cad9173
corrected friendly_name for test_util
raftmsohani Dec 4, 2023
aa6a5ad
Merge branch 'develop' into 2599-error-report-corrections-impact-wpr-…
raftmsohani Dec 4, 2023
4bce93d
correction child care - number of months
raftmsohani Dec 4, 2023
d29ed8e
Merge branch '2599-error-report-corrections-impact-wpr-metrics' of ht…
raftmsohani Dec 4, 2023
bd29c09
fixed a few more typos and some spacing. (#2767)
George-Hudson Dec 5, 2023
beda306
Merge branch 'develop' into 2599-error-report-corrections-impact-wpr-…
raftmsohani Dec 6, 2023
cfec7f2
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Dec 11, 2023
55ce817
- knowledge center
elipe17 Dec 11, 2023
58e3324
- Integrating Jans changes. Parametrizing values_is_empty
elipe17 Dec 11, 2023
395e786
Merge branch '2599-error-report-corrections-impact-wpr-metrics' of ht…
elipe17 Dec 11, 2023
05b0b8b
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Dec 18, 2023
06ca2ab
- Update based on review feedback
elipe17 Dec 20, 2023
bce13b4
- Updated length checks
elipe17 Dec 21, 2023
729a4d2
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Dec 21, 2023
7152df2
- removing fips code
elipe17 Dec 28, 2023
e84b01f
Update tdrs-backend/tdpservice/parsers/schema_defs/tribal_tanf/t2.py
elipe17 Dec 28, 2023
5e29f46
Update tdrs-backend/tdpservice/parsers/schema_defs/tribal_tanf/t3.py
elipe17 Dec 28, 2023
f4477ce
Update tdrs-backend/tdpservice/parsers/schema_defs/tribal_tanf/t3.py
elipe17 Dec 28, 2023
4e1fed7
Update tdrs-backend/tdpservice/parsers/schema_defs/tribal_tanf/t3.py
elipe17 Dec 28, 2023
1d9070d
- update based on review
elipe17 Dec 28, 2023
120274b
Merge branch '1114-tribal-s1' of https://github.com/raft-tech/TANF-ap…
elipe17 Dec 28, 2023
a5e9cf3
- Fix migration
elipe17 Dec 28, 2023
5850dc8
- Fixed name clash on PARENT_MINOR_CHILD
elipe17 Dec 29, 2023
c15d92d
Revert "- Fixed name clash on PARENT_MINOR_CHILD"
elipe17 Dec 29, 2023
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
2 changes: 1 addition & 1 deletion tdrs-backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ django-elasticsearch-dsl = "==7.3"
django-elasticsearch-dsl-drf = "==0.22.5"
requests-aws4auth = "==1.1.2"
cerberus = "==1.3.4"
xlsxwriter = "==3.0.1"
xlsxwriter = "==3.1.9"
sendgrid = "==6.10.0"

[requires]
Expand Down
719 changes: 387 additions & 332 deletions tdrs-backend/Pipfile.lock

Large diffs are not rendered by default.

45 changes: 34 additions & 11 deletions tdrs-backend/tdpservice/parsers/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

logger = logging.getLogger(__name__)


def value_is_empty(value, length):
"""Handle 'empty' values as field inputs."""
empty_values = [
' '*length, # ' '
'#'*length, # '#####'
'_'*length, # '_____'
" " * length, # ' '
"#" * length, # '#####'
"_" * length, # '_____'
]

return value is None or value in empty_values
Expand All @@ -18,9 +19,20 @@ def value_is_empty(value, length):
class Field:
"""Provides a mapping between a field name and its position."""

def __init__(self, item, name, type, startIndex, endIndex, required=True, validators=[]):
def __init__(
self,
item,
name,
friendly_name,
type,
startIndex,
endIndex,
required=True,
validators=[],
):
self.item = item
self.name = name
self.friendly_name = friendly_name
self.type = type
self.startIndex = startIndex
self.endIndex = endIndex
Expand All @@ -37,32 +49,43 @@ def __repr__(self):

def parse_value(self, line):
"""Parse the value for a field given a line, startIndex, endIndex, and field type."""
value = line[self.startIndex:self.endIndex]
value = line[self.startIndex: self.endIndex]

if value_is_empty(value, self.endIndex-self.startIndex):
logger.debug(f"Field: '{self.name}' at position: [{self.startIndex}, {self.endIndex}) is empty.")
if value_is_empty(value, self.endIndex - self.startIndex):
logger.debug(
f"Field: '{self.name}' at position: [{self.startIndex}, {self.endIndex}) is empty."
)
return None

match self.type:
case 'number':
case "number":
try:
value = int(value)
return value
except ValueError:
logger.error(f"Error parsing field value: {value} to integer.")
return None
case 'string':
case "string":
return value
case _:
logger.warn(f"Unknown field type: {self.type}.")
return None


class TransformField(Field):
"""Represents a field that requires some transformation before serializing."""

def __init__(self, transform_func, item, name, type, startIndex, endIndex, required=True,
def __init__(self, transform_func, item, name, friendly_name, type, startIndex, endIndex, required=True,
validators=[], **kwargs):
super().__init__(item, name, type, startIndex, endIndex, required, validators)
super().__init__(
item=item,
name=name,
type=type,
friendly_name=friendly_name,
startIndex=startIndex,
endIndex=endIndex,
required=required,
validators=validators)
self.transform_func = transform_func
self.kwargs = kwargs

Expand Down
24 changes: 22 additions & 2 deletions tdrs-backend/tdpservice/parsers/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,31 @@ def parse_datafile(datafile):
bulk_create_errors({1: header_errors}, 1, flush=True)
return errors

is_encrypted = util.contains_encrypted_indicator(header_line, schema_defs.header.get_field_by_name("encryption"))
field_values = schema_defs.header.get_field_values_by_names(header_line,
{"encryption", "tribe_code", "state_fips"})

# Validate tribe code in submission across program type and fips code
generate_error = util.make_generate_parser_error(datafile, 1)
tribe_is_valid, tribe_error = validators.validate_tribe_fips_program_agree(header['program_type'],
field_values["tribe_code"],
field_values["state_fips"],
generate_error)

if not tribe_is_valid:
logger.info(f"Tribe Code ({field_values['tribe_code']}) inconsistency with Program Type " +
f"({header['program_type']}) and FIPS Code ({field_values['state_fips']}).",)
errors['header'] = [tribe_error]
bulk_create_errors({1: [tribe_error]}, 1, flush=True)
return errors

is_encrypted = field_values["encryption"] == "E"
is_tribal = util.is_string_field_valid(field_values["tribe_code"], 3)

logger.debug(f"Datafile has encrypted fields: {is_encrypted}.")
logger.debug(f"Datafile: {datafile.__repr__()}, is Tribal: {is_tribal}.")

# ensure file section matches upload section
program_type = header['program_type']
program_type = f"Tribal {header['program_type']}" if is_tribal else header['program_type']
section = header['type']
logger.debug(f"Program type: {program_type}, Section: {section}.")

Expand Down
14 changes: 12 additions & 2 deletions tdrs-backend/tdpservice/parsers/row_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,31 @@ def run_postparsing_validators(self, instance, generate_error):
errors = []

for validator in self.postparsing_validators:
validator_is_valid, validator_error = validator(instance)
validator_is_valid, validator_error, field_names = validator(instance)
is_valid = False if not validator_is_valid else is_valid
if validator_error:
# get field from field name
fields = [self.get_field_by_name(name) for name in field_names]
errors.append(
generate_error(
schema=self,
error_category=ParserErrorCategoryChoices.VALUE_CONSISTENCY,
error_message=validator_error,
record=instance,
field=None
field=fields,
)
)

return is_valid, errors

def get_field_values_by_names(self, line, names={}):
"""Return dictionary of field values keyed on their name."""
field_values = {}
for field in self.fields:
if field.name in names:
field_values[field.name] = field.parse_value(line)
return field_values

def get_field_by_name(self, name):
elipe17 marked this conversation as resolved.
Show resolved Hide resolved
"""Get field by it's name."""
for field in self.fields:
Expand Down
2 changes: 2 additions & 0 deletions tdrs-backend/tdpservice/parsers/schema_defs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from .header import header
from .trailer import trailer
from . import tanf
from . import tribal_tanf
from . import ssp

header = header
trailer = trailer
tanf = tanf
tribal_tanf = tribal_tanf
ssp = ssp
75 changes: 18 additions & 57 deletions tdrs-backend/tdpservice/parsers/schema_defs/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Field(
item="2",
name="title",
friendly_name="title",
type="string",
startIndex=0,
endIndex=6,
Expand All @@ -31,6 +32,7 @@
Field(
item="4",
name="year",
friendly_name="year",
type="number",
startIndex=6,
endIndex=10,
Expand All @@ -40,6 +42,7 @@
Field(
item="5",
name="quarter",
friendly_name="quarter",
type="string",
startIndex=10,
endIndex=11,
Expand All @@ -49,6 +52,7 @@
Field(
item="6",
name="type",
friendly_name="type",
type="string",
startIndex=11,
endIndex=12,
Expand All @@ -58,74 +62,27 @@
Field(
item="1",
name="state_fips",
friendly_name="state fips",
type="string",
startIndex=12,
endIndex=14,
required=True,
validators=[
validators.oneOf(
(
"01",
"02",
"04",
"05",
"06",
"08",
"09",
"10",
"11",
"12",
"13",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"23",
"24",
"25",
"26",
"27",
"28",
"29",
"30",
"31",
"32",
"33",
"34",
"35",
"36",
"37",
"38",
"39",
"40",
"41",
"42",
"44",
"45",
"46",
"47",
"48",
"49",
"50",
"51",
"53",
"54",
"55",
"56",
"66",
"72",
"78",
)
validators.or_validators(
validators.isInStringRange(0, 2),
elipe17 marked this conversation as resolved.
Show resolved Hide resolved
validators.isInStringRange(4, 6),
validators.isInStringRange(8, 13),
validators.isInStringRange(15, 42),
validators.isInStringRange(44, 51),
validators.isInStringRange(53, 56),
validators.oneOf(["66", "72", "78"]),
elipe17 marked this conversation as resolved.
Show resolved Hide resolved
)
],
),
Field(
item="3",
name="tribe_code",
friendly_name="tribe code",
type="string",
startIndex=14,
endIndex=17,
Expand All @@ -135,6 +92,7 @@
Field(
item="7",
name="program_type",
friendly_name="program type",
type="string",
startIndex=17,
endIndex=20,
Expand All @@ -144,6 +102,7 @@
Field(
item="8",
name="edit",
friendly_name="edit",
type="string",
startIndex=20,
endIndex=21,
Expand All @@ -153,6 +112,7 @@
Field(
item="9",
name="encryption",
friendly_name="encryption",
type="string",
startIndex=21,
endIndex=22,
Expand All @@ -162,6 +122,7 @@
Field(
item="10",
name="update",
friendly_name="update",
type="string",
startIndex=22,
endIndex=23,
Expand Down
Loading
Loading