PD v1 Post-Processing block
This commit is contained in:
parent
70590db6b5
commit
bd17146e63
12
README.md
12
README.md
@ -1 +1,11 @@
|
||||
**Hello world!!!**
|
||||
## Overview
|
||||
This block (`block.py`) is responsible for assigning grades.
|
||||
|
||||
## 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`.
|
||||
|
||||
|
||||
49
block.py
49
block.py
@ -1,21 +1,32 @@
|
||||
@flowx_block
|
||||
def example_function(request: dict) -> dict:
|
||||
import logging
|
||||
|
||||
# Processing logic here...
|
||||
# Configure logging
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format="%(asctime)s [%(levelname)s] %(name)s - %(message)s",
|
||||
)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
return {
|
||||
"meta_info": [
|
||||
{
|
||||
"name": "created_date",
|
||||
"type": "string",
|
||||
"value": "2024-11-05"
|
||||
}
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"name": "",
|
||||
"type": "",
|
||||
"value": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
def __main__(probability:float):
|
||||
logger.info("Received input: probability=%.8f", float(probability))
|
||||
|
||||
if not isinstance(probability, (int, float)):
|
||||
logger.error("Invalid input type: probability=%s", type(probability).__name__)
|
||||
raise ValueError("Input probability must be a number (int or float)")
|
||||
|
||||
if probability <= 0.219999999999999:
|
||||
grade = "A1"
|
||||
elif 0.219999999999999 < probability <= 0.339999999999999:
|
||||
grade = "A2"
|
||||
elif 0.339999999999999 < probability <= 0.419999999999999:
|
||||
grade = "B1"
|
||||
elif 0.419999999999999 < probability <= 0.514999999999999:
|
||||
grade = "B2"
|
||||
elif 0.514999999999999 < probability <= 0.559999999999999:
|
||||
grade = "C1"
|
||||
else:
|
||||
grade = "C2"
|
||||
|
||||
logger.info(f"PD V1 Grade {grade}")
|
||||
|
||||
return {"grade":grade}
|
||||
@ -1 +1,11 @@
|
||||
{}
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"probability": {
|
||||
"type": "number",
|
||||
"description": "PD v1 Model predicted score."
|
||||
}
|
||||
},
|
||||
"required": []
|
||||
}
|
||||
@ -1 +1 @@
|
||||
{}
|
||||
jsonschema==4.23.0
|
||||
@ -1 +1,10 @@
|
||||
{}
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"bin": {
|
||||
"type": "string",
|
||||
"description": "PD v1 grade."
|
||||
}
|
||||
}
|
||||
}
|
||||
15
test_block.py
Normal file
15
test_block.py
Normal file
@ -0,0 +1,15 @@
|
||||
import unittest
|
||||
from block import __main__
|
||||
|
||||
class TestBlock(unittest.TestCase):
|
||||
|
||||
def test_main_success(self):
|
||||
result = __main__(probability=0.20269478857517242)
|
||||
self.assertEqual(result, {"grade": "A1"})
|
||||
|
||||
def test_main_invalid_input(self):
|
||||
with self.assertRaises(ValueError):
|
||||
__main__(probability="0.20") # Invalid input type (string)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Loading…
x
Reference in New Issue
Block a user