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

2599-error-report-excel-format #2734

Merged
merged 81 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
81 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
c75bb7e
2599-added friendly name to postparsing validators
raftmsohani Nov 1, 2023
0ec8f16
refining the validator tests
raftmsohani 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
700a965
listing
raftmsohani Nov 20, 2023
8aae444
Merge branch 'develop' into 2599-error-report-corrections-impact-wpr-…
raftmsohani 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
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
ad17b56
friendly_name corrections
raftmsohani Nov 30, 2023
efc15bd
Merge branch 'develop' into 2599-error-report-corrections-impact-wpr-…
raftmsohani Nov 30, 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
583de19
fields_json Backward compatibility
raftmsohani Dec 13, 2023
bfd324f
Merge branch 'develop' into 2599-error-report-corrections-impact-wpr-…
raftmsohani Dec 13, 2023
d6d18a3
remove PATCH from black list
raftmsohani Dec 13, 2023
beaa713
Merge branch '2599-error-report-corrections-impact-wpr-metrics' of ht…
raftmsohani Dec 13, 2023
04deb46
backward compatibility
raftmsohani Dec 13, 2023
2b5fbfe
linting
raftmsohani Dec 13, 2023
03aa202
add PATCH to allowed
raftmsohani Dec 13, 2023
8c6bc90
readded internal_name
raftmsohani Dec 13, 2023
5cd7d39
added a function
raftmsohani Dec 13, 2023
71d48c7
remove NoneType from fields_json
raftmsohani Dec 13, 2023
2b6c399
linting
raftmsohani Dec 13, 2023
ff62d46
Merge branch 'develop' into 2599-error-report-corrections-impact-wpr-…
raftmsohani Dec 13, 2023
bc28868
Update tdrs-backend/tdpservice/parsers/schema_defs/tanf/t5.py
raftmsohani Dec 16, 2023
8409585
Update tdrs-backend/tdpservice/parsers/schema_defs/ssp/m5.py
raftmsohani Dec 16, 2023
c16ec07
corrections on friendly names
raftmsohani Dec 16, 2023
f0aa319
Update tdrs-backend/tdpservice/parsers/schema_defs/ssp/m2.py
raftmsohani Dec 16, 2023
085a7da
Update tdrs-backend/tdpservice/parsers/schema_defs/ssp/m5.py
raftmsohani Dec 16, 2023
399e677
correction on friendly names
raftmsohani Dec 16, 2023
3c6d025
Merge branch '2599-error-report-corrections-impact-wpr-metrics' of gi…
raftmsohani Dec 16, 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
6 changes: 4 additions & 2 deletions tdrs-backend/tdpservice/parsers/row_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,18 @@ 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,
)
)

Expand Down
73 changes: 15 additions & 58 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,23 @@
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.oneOf(("01", "02", "04", "05", "06", "08", "09", "10", "11", "12", "13", "15",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might create a conflict with @elipe17 's PR or the other way around, depending on which gets merged first. We can cross that bridge when we get to it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think his branch is touching header file, so when we merge this, his branch can pull develop and should be ok

"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"))
],
),
Field(
item="3",
name="tribe_code",
friendly_name="tribe code",
type="string",
startIndex=14,
endIndex=17,
Expand All @@ -135,6 +88,7 @@
Field(
item="7",
name="program_type",
friendly_name="program type",
type="string",
startIndex=17,
endIndex=20,
Expand All @@ -144,6 +98,7 @@
Field(
item="8",
name="edit",
friendly_name="edit",
type="string",
startIndex=20,
endIndex=21,
Expand All @@ -153,6 +108,7 @@
Field(
item="9",
name="encryption",
friendly_name="encryption",
type="string",
startIndex=21,
endIndex=22,
Expand All @@ -162,6 +118,7 @@
Field(
item="10",
name="update",
friendly_name="update",
type="string",
startIndex=22,
endIndex=23,
Expand Down
Loading
Loading