diff --git a/README.md b/README.md index 59a3efc..59225c7 100644 --- a/README.md +++ b/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`. diff --git a/block.py b/block.py index 3b227f9..9d172eb 100644 --- a/block.py +++ b/block.py @@ -1,21 +1,44 @@ -@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.3200099998: + bin = "1" + elif 0.3200099998 < probability <= 0.4459999998: + bin = "2" + elif 0.4459999998 < probability <= 0.5394999999: + 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} \ No newline at end of file diff --git a/request_schema.json b/request_schema.json index 0967ef4..f391706 100644 --- a/request_schema.json +++ b/request_schema.json @@ -1 +1,11 @@ -{} +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "probability": { + "type": "number", + "description": "Model predicted score." + } + }, + "required": [] +} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 0967ef4..8c4acbc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -{} +jsonschema==4.23.0 \ No newline at end of file diff --git a/response_schema.json b/response_schema.json index 0967ef4..6092dfb 100644 --- a/response_schema.json +++ b/response_schema.json @@ -1 +1,10 @@ -{} +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "properties": { + "bin": { + "type": "string", + "description": "Bin for the given input float." + } + } + } \ No newline at end of file diff --git a/test_block.py b/test_block.py new file mode 100644 index 0000000..ca098c1 --- /dev/null +++ b/test_block.py @@ -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() \ No newline at end of file