Compare commits
No commits in common. "pd-v2-post-processing" and "main" have entirely different histories.
pd-v2-post
...
main
12
README.md
12
README.md
@ -1,11 +1 @@
|
|||||||
## Overview
|
**Hello world!!!**
|
||||||
This block (`block.py`) is responsible for assigning grades 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`.
|
|
||||||
|
|
||||||
|
|||||||
49
block.py
49
block.py
@ -1,32 +1,21 @@
|
|||||||
import logging
|
@flowx_block
|
||||||
|
def example_function(request: dict) -> dict:
|
||||||
|
|
||||||
# Configure logging
|
# Processing logic here...
|
||||||
logging.basicConfig(
|
|
||||||
level=logging.INFO,
|
|
||||||
format="%(asctime)s [%(levelname)s] %(name)s - %(message)s",
|
|
||||||
)
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
def __main__(probability:float):
|
return {
|
||||||
logger.info("Received input: probability=%.8f", float(probability))
|
"meta_info": [
|
||||||
|
{
|
||||||
if not isinstance(probability, (int, float)):
|
"name": "created_date",
|
||||||
logger.error("Invalid input type: probability=%s", type(probability).__name__)
|
"type": "string",
|
||||||
raise ValueError("Input probability must be a number (int or float)")
|
"value": "2024-11-05"
|
||||||
|
}
|
||||||
if probability <= 0.26:
|
],
|
||||||
grade = "A1"
|
"fields": [
|
||||||
elif 0.26 < probability <= 0.38:
|
{
|
||||||
grade = "A2"
|
"name": "",
|
||||||
elif 0.38 < probability <= 0.52:
|
"type": "",
|
||||||
grade = "B1"
|
"value": ""
|
||||||
elif 0.52 < probability <= 0.652:
|
}
|
||||||
grade = "B2"
|
]
|
||||||
elif 0.652 < probability <= 0.7:
|
}
|
||||||
grade = "C1"
|
|
||||||
else:
|
|
||||||
grade = "C2"
|
|
||||||
|
|
||||||
logger.info(f"PD V2 Grade: {grade}")
|
|
||||||
|
|
||||||
return {"grade":grade}
|
|
||||||
|
|||||||
@ -1,11 +1 @@
|
|||||||
{
|
{}
|
||||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"probability": {
|
|
||||||
"type": "number",
|
|
||||||
"description": "Model predicted score."
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": []
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
jsonschema==4.23.0
|
{}
|
||||||
|
|||||||
@ -1,10 +1 @@
|
|||||||
{
|
{}
|
||||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"grade": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "PD v2 grade."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -1,15 +0,0 @@
|
|||||||
import unittest
|
|
||||||
from block import __main__
|
|
||||||
|
|
||||||
class TestBlock(unittest.TestCase):
|
|
||||||
|
|
||||||
def test_main_success(self):
|
|
||||||
result = __main__(probability=0.40)
|
|
||||||
self.assertEqual(result, {"grade": "B1"})
|
|
||||||
|
|
||||||
def test_main_invalid_input(self):
|
|
||||||
with self.assertRaises(ValueError):
|
|
||||||
__main__(probability="0.40")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
unittest.main()
|
|
||||||
Loading…
x
Reference in New Issue
Block a user