Compare commits

..

1 Commits

Author SHA1 Message Date
a58428db77 ETD Post Processing block
All checks were successful
Build and Push Docker Image / test (push) Successful in 8s
Build and Push Docker Image / build_and_push (push) Successful in 15s
2025-02-05 19:15:06 +00:00
6 changed files with 79 additions and 23 deletions

View File

@ -1 +1,11 @@
**Hello world!!!** ## Overview
This block (`block.py`) is responsible for assigning grade for the passed in probability.
## Key Inputs & Outputs
- **Request**: Refer to `request_schema.json` for detailed input fields and validation rules.
- **Response**: Refer to `response_schema.json` for the returned structure and data types.
## Implementation Details
- All core logic resides in `block.py` within the `__main__` function.
- Example usage and validation are demonstrated in `test_block.py`.

View File

@ -1,21 +1,33 @@
@flowx_block import logging
def example_function(request: dict) -> dict:
# Processing logic here... # Configure logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s - %(message)s",
)
logger = logging.getLogger(__name__)
return { def __main__(probability: float) -> dict:
"meta_info": [ logger.info("Received input: probability=%.8f", float(probability))
{
"name": "created_date", if not isinstance(probability, (int, float)):
"type": "string", logger.error("Invalid input type: probability=%s", type(probability).__name__)
"value": "2024-11-05" raise ValueError("Input probability must be a number (int or float)")
}
], if probability <= 0.33:
"fields": [ grade = "G1"
{ elif 0.33 < probability <= 0.41:
"name": "", grade = "G2"
"type": "", elif 0.41 < probability <= 0.48:
"value": "" grade = "G3"
} elif 0.48 < probability <= 0.61:
] grade = "G4"
} elif 0.61 < probability <= 0.65:
grade = "G5"
else:
grade = "G6"
result = {"grade": grade}
logger.info("Fraud V1 Grade: %s", result)
return result

View File

@ -1 +1,11 @@
{} {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"probability": {
"type": "number",
"description": "Fraud Model predicted score."
}
},
"required": []
}

View File

@ -1 +1 @@
{} jsonschema==4.23.0

View File

@ -1 +1,10 @@
{} {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"grade": {
"type": "string",
"description": "PD v2 grade."
}
}
}

15
test_block.py Normal file
View File

@ -0,0 +1,15 @@
import unittest
from block import __main__
class TestBlock(unittest.TestCase):
def test_main_success(self):
result = __main__(probability=0.3890174329280853)
self.assertEqual(result, {"grade": "G2"})
def test_main_invalid_input(self):
with self.assertRaises(ValueError):
__main__(probability="0.40") # Invalid input type (string)
if __name__ == "__main__":
unittest.main()