forked from HHS/TANF-app
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2711-catch-rpt-month-year-mismatches (#2789)
* created pre-check error * corrected some of failing tests * corrected failing tests * two tests still failing * Passing tests * Update small_incorrect_file_cross_validator.txt * Update small_incorrect_file_cross_validator.txt * Update small_incorrect_file_cross_validator.txt * Update small_incorrect_file_cross_validator.txt * revert changes on test file * corrected the failing test * resolve circular import * merge conflict resolution * linting * correct failing tests * corrected t7 tests
- Loading branch information
1 parent
d5a44ff
commit 92b0a69
Showing
33 changed files
with
283 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
"""Aggregate methods for the parsers.""" | ||
from .row_schema import SchemaManager | ||
from .models import ParserError | ||
from .util import month_to_int, get_program_models, get_text_from_df, \ | ||
transform_to_months, fiscal_to_calendar, get_prog_from_section | ||
|
||
|
||
def case_aggregates_by_month(df, dfs_status): | ||
"""Return case aggregates by month.""" | ||
section = str(df.section) # section -> text | ||
program_type = get_prog_from_section(section) # section -> program_type -> text | ||
|
||
# from datafile year/quarter, generate short month names for each month in quarter ala 'Jan', 'Feb', 'Mar' | ||
calendar_year, calendar_qtr = fiscal_to_calendar(df.year, df.quarter) | ||
month_list = transform_to_months(calendar_qtr) | ||
|
||
short_section = get_text_from_df(df)['section'] | ||
schema_models_dict = get_program_models(program_type, short_section) | ||
schema_models = [model for model in schema_models_dict.values()] | ||
|
||
aggregate_data = {"months": [], "rejected": 0} | ||
for month in month_list: | ||
total = 0 | ||
cases_with_errors = 0 | ||
accepted = 0 | ||
month_int = month_to_int(month) | ||
rpt_month_year = int(f"{calendar_year}{month_int}") | ||
if dfs_status == "Rejected": | ||
# we need to be careful here on examples of bad headers or empty files, since no month will be found | ||
# but we can rely on the frontend submitted year-quarter to still generate the list of months | ||
aggregate_data["months"].append({"accepted_with_errors": "N/A", | ||
"accepted_without_errors": "N/A", | ||
"month": month}) | ||
continue | ||
|
||
case_numbers = set() | ||
for schema_model in schema_models: | ||
if isinstance(schema_model, SchemaManager): | ||
schema_model = schema_model.schemas[0] | ||
|
||
curr_case_numbers = set(schema_model.document.Django.model.objects.filter(datafile=df) | ||
.filter(RPT_MONTH_YEAR=rpt_month_year) | ||
.distinct("CASE_NUMBER").values_list("CASE_NUMBER", flat=True)) | ||
case_numbers = case_numbers.union(curr_case_numbers) | ||
|
||
total += len(case_numbers) | ||
cases_with_errors += ParserError.objects.filter(file=df).filter( | ||
case_number__in=case_numbers).distinct('case_number').count() | ||
accepted = total - cases_with_errors | ||
|
||
aggregate_data['months'].append({"month": month, | ||
"accepted_without_errors": accepted, | ||
"accepted_with_errors": cases_with_errors}) | ||
|
||
aggregate_data['rejected'] = ParserError.objects.filter(file=df).filter(case_number=None).count() | ||
|
||
return aggregate_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
tdrs-backend/tdpservice/parsers/test/data/tanf_section1_header_test.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
HEADER20204A06 TAN1 N | ||
T12020101111111111223003403361110213120000300000000000008730010000000000000000000000000000000000222222000000002229012 | ||
TRAILER0000001 |
Oops, something went wrong.