generated from cfpb/open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
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
140 validation metadata #165
Merged
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
75e8af3
Added validator json metadata and updated dao and dto
guffee23 9bfb49d
Merge branch 'main' into 140_validation_metadata
guffee23 85bac65
Fixed formatting
guffee23 fd5ab4a
Fixed tests
guffee23 314e771
Code reformatting
guffee23 68d5114
Merge branch 'main' into 140_validation_metadata
guffee23 ffc4a12
Lined left in after main merge
guffee23 b7d304e
Added test coverage for json validation
guffee23 e0307cd
Merge branch 'main' into 140_validation_metadata
guffee23 5c51999
Merge branch 'main' into 140_validation_metadata
guffee23 232fe29
Added mock dataframes for tests
guffee23 a8f7185
Formatting
guffee23 3c4d2a1
Refactored code and added build validation tests
guffee23 1e1bef2
Merge branch 'main' into 140_validation_metadata
guffee23 b4481c7
Small change
guffee23 aedd46b
Cleaned syntax json code
guffee23 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
from io import BytesIO | ||
from fastapi import UploadFile | ||
from regtech_data_validator.create_schemas import validate_phases | ||
from regtech_data_validator.create_schemas import validate_phases, ValidationPhase | ||
from regtech_data_validator.data_formatters import df_to_json, df_to_download | ||
from regtech_data_validator.checks import Severity | ||
import pandas as pd | ||
|
@@ -105,7 +105,7 @@ async def validate_and_update_submission(period_code: str, lei: str, submission: | |
) | ||
else: | ||
submission.state = SubmissionState.VALIDATION_SUCCESSFUL | ||
submission.validation_json = json.loads(df_to_json(result[1])) | ||
submission.validation_json = build_validation_results(result) | ||
submission_report = df_to_download(result[1]) | ||
await upload_to_storage( | ||
period_code, lei, str(submission.id) + REPORT_QUALIFIER, submission_report.encode("utf-8") | ||
|
@@ -116,7 +116,6 @@ async def validate_and_update_submission(period_code: str, lei: str, submission: | |
log.error("The file is malformed", re, exc_info=True, stack_info=True) | ||
submission.state = SubmissionState.SUBMISSION_UPLOAD_MALFORMED | ||
await update_submission(submission) | ||
|
||
except Exception as e: | ||
log.error( | ||
f"Validation for submission {submission.id} did not complete due to an unexpected error.", | ||
|
@@ -126,3 +125,22 @@ async def validate_and_update_submission(period_code: str, lei: str, submission: | |
) | ||
submission.state = SubmissionState.VALIDATION_ERROR | ||
await update_submission(submission) | ||
|
||
|
||
def build_validation_results(result): | ||
val_json = json.loads(df_to_json(result[1])) | ||
|
||
if result[2] == ValidationPhase.SYNTACTICAL.value: | ||
val_res = {"syntax_errors": {"count": 0, "details": []}} | ||
val_res["syntax_errors"]["details"] = val_json | ||
val_res["syntax_errors"]["count"] = len(val_res["syntax_errors"]["details"]) | ||
else: | ||
errors_list = [e for e in val_json if e["validation"]["severity"] == Severity.ERROR.value] | ||
warnings_list = [w for w in val_json if w["validation"]["severity"] == Severity.WARNING.value] | ||
val_res = { | ||
"syntax_errors": {"count": 0, "details": []}, | ||
"logic_errors": {"count": len(errors_list), "details": errors_list}, | ||
"logic_warnings": {"count": len(warnings_list), "details": warnings_list}, | ||
} | ||
|
||
return val_res | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This else block can be even further refined to:
to avoid looping and appending. List comprehension in python is faster on large data sets. |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just like below, this section can be shortened to just:
val_res = {"syntax_errors": {"count": len(val_json), "details": val_json}}