-
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
Changes from 4 commits
75e8af3
9bfb49d
85bac65
fd5ab4a
314e771
68d5114
ffc4a12
b7d304e
e0307cd
5c51999
232fe29
a8f7185
3c4d2a1
1e1bef2
b4481c7
aedd46b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,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 | ||
|
@@ -83,7 +83,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") | ||
|
@@ -95,3 +95,29 @@ async def validate_and_update_submission(period_code: str, lei: str, submission: | |
submission.state = SubmissionState.SUBMISSION_UPLOAD_MALFORMED | ||
await update_submission(submission) | ||
raise HTTPException(status_code=HTTPStatus.UNPROCESSABLE_ENTITY, detail=re) | ||
|
||
|
||
def build_validation_results(result): | ||
val_json = json.loads(df_to_json(result[1])) | ||
val_res = {} | ||
|
||
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"]) | ||
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. Just like below, this section can be shortened to just: |
||
else: | ||
val_res = { | ||
"syntax_errors": {"count": 0, "details": []}, | ||
"logic_errors": {"count": 0, "details": []}, | ||
"logic_warnings": {"count": 0, "details": []}, | ||
} | ||
for v in val_json: | ||
if v["validation"]["severity"] == Severity.WARNING.value: | ||
val_res["logic_warnings"]["details"].append(v) | ||
elif v["validation"]["severity"] == Severity.ERROR.value: | ||
val_res["logic_errors"]["details"].append(v) | ||
lchen-2101 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
val_res["logic_warnings"]["count"], val_res["logic_errors"]["count"] = len( | ||
val_res["logic_warnings"]["details"] | ||
), len(val_res["logic_errors"]["details"]) | ||
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. using tuple destructuring doesn't add much value here... you save 1 keystroke of not having to type out an additional |
||
|
||
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. |
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.
these can just be assigned directly instead of having an inititializing step.