Compare commits
1 Commits
main
...
repeat-v1-
| Author | SHA1 | Date | |
|---|---|---|---|
| edd9dd33de |
11
README.md
11
README.md
@ -1 +1,10 @@
|
|||||||
**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`.
|
||||||
|
|||||||
61
block.py
61
block.py
@ -1,21 +1,44 @@
|
|||||||
@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):
|
||||||
"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.3200099998:
|
||||||
"fields": [
|
bin = "1"
|
||||||
{
|
elif 0.3200099998 < probability <= 0.4459999998:
|
||||||
"name": "",
|
bin = "2"
|
||||||
"type": "",
|
elif 0.4459999998 < probability <= 0.5394999999:
|
||||||
"value": ""
|
bin = "3"
|
||||||
}
|
elif 0.5394999999 < probability <= 0.6186978508:
|
||||||
]
|
bin = "4"
|
||||||
}
|
elif 0.6186978508 < probability <= 0.6350320994:
|
||||||
|
bin = "5"
|
||||||
|
elif 0.6350320994 < probability <= 0.6553314835:
|
||||||
|
bin = "6"
|
||||||
|
elif 0.6553314835 < probability <= 0.6759955555:
|
||||||
|
bin = "7"
|
||||||
|
elif 0.6759955555 < probability <= 0.7399999999:
|
||||||
|
bin = "8"
|
||||||
|
elif 0.7399999999 < probability <= 0.7899992753:
|
||||||
|
bin = "9"
|
||||||
|
elif 0.7899992753 < probability <= 0.8199900001:
|
||||||
|
bin = "10"
|
||||||
|
elif 0.8199900001 < probability <= 0.8400000009:
|
||||||
|
bin = "11"
|
||||||
|
else:
|
||||||
|
bin = "12"
|
||||||
|
|
||||||
|
logger.info(f"Repeat V1 Bin: {bin}")
|
||||||
|
|
||||||
|
return {"bin":bin}
|
||||||
@ -1 +1,11 @@
|
|||||||
{}
|
{
|
||||||
|
"$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 +1,10 @@
|
|||||||
{}
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"bin": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Bin for the given input float."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
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.2707298696)
|
||||||
|
self.assertEqual(result, {"bin": "1"})
|
||||||
|
|
||||||
|
def test_main_invalid_input(self):
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
__main__(probability="0.27") # Invalid input type (string)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Loading…
x
Reference in New Issue
Block a user