Repeat v1 Processing block
This commit is contained in:
parent
70590db6b5
commit
b2d3b31b7a
11
README.md
11
README.md
@ -1 +1,10 @@
|
|||||||
**Hello world!!!**
|
## Overview
|
||||||
|
This block (`block.py`) is responsible for loading and scoring the model.
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
|
||||||
|
|||||||
92
block.py
92
block.py
@ -1,21 +1,75 @@
|
|||||||
@flowx_block
|
import logging
|
||||||
def example_function(request: dict) -> dict:
|
import requests
|
||||||
|
|
||||||
# Processing logic here...
|
# Configure logging
|
||||||
|
logging.basicConfig(
|
||||||
|
level=logging.INFO,
|
||||||
|
format="%(asctime)s [%(levelname)s] %(name)s - %(message)s",
|
||||||
|
)
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
return {
|
url = "http://centurion-h2o-server.default.svc.cluster.local:8000/scoring"
|
||||||
"meta_info": [
|
# url = "http://localhost:8000/scoring"
|
||||||
{
|
headers = {
|
||||||
"name": "created_date",
|
"accept": "application/json",
|
||||||
"type": "string",
|
"Content-Type": "application/json"
|
||||||
"value": "2024-11-05"
|
}
|
||||||
}
|
|
||||||
],
|
def __main__(score_results:float, AT34B:int, AT12S:int, revolving_amount_percent_available_credit:float, AT28A:int, record_counts_total_trade_count:int, record_counts_negative_trade_count:int, record_counts_revolving_trade_count:int, AT33A:int, AT35A:int,
|
||||||
"fields": [
|
record_counts_total_inquiry_count:int, IN20S:int, RE102S:int, installment_amount_monthly_payment:float, S061S:int,
|
||||||
{
|
record_counts_installment_trade_count:int, BR02S:int, AGG103:float, ALL231:float, G069S:int, AT24S:int, BI02S:int)->dict:
|
||||||
"name": "",
|
input_data = {
|
||||||
"type": "",
|
"score_results": score_results,
|
||||||
"value": ""
|
"AT34B": AT34B,
|
||||||
}
|
"AT12S": AT12S,
|
||||||
]
|
"revolving_amount_percent_available_credit": revolving_amount_percent_available_credit,
|
||||||
}
|
"AT28A": AT28A,
|
||||||
|
"record_counts_total_trade_count": record_counts_total_trade_count,
|
||||||
|
"record_counts_negative_trade_count": record_counts_negative_trade_count,
|
||||||
|
"record_counts_revolving_trade_count": record_counts_revolving_trade_count,
|
||||||
|
"AT33A": AT33A,
|
||||||
|
"AT35A": AT35A,
|
||||||
|
"record_counts_total_inquiry_count": record_counts_total_inquiry_count,
|
||||||
|
"IN20S": IN20S,
|
||||||
|
"RE102S": RE102S,
|
||||||
|
"installment_amount_monthly_payment": installment_amount_monthly_payment,
|
||||||
|
"S061S": S061S,
|
||||||
|
"record_counts_installment_trade_count": record_counts_installment_trade_count,
|
||||||
|
"BR02S": BR02S,
|
||||||
|
"AGG103": AGG103,
|
||||||
|
"ALL231": ALL231,
|
||||||
|
"G069S": G069S,
|
||||||
|
"AT24S": AT24S,
|
||||||
|
"BI02S": BI02S
|
||||||
|
}
|
||||||
|
|
||||||
|
filtered_data = {key: value for key, value in input_data.items() if value is not None}
|
||||||
|
data = {
|
||||||
|
"model_name": "repeat_v1",
|
||||||
|
"features": filtered_data
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
response = requests.post(url, headers=headers, json=data)
|
||||||
|
response.raise_for_status() # Raise an error for HTTP issues
|
||||||
|
|
||||||
|
# Parse the response and return the "" value
|
||||||
|
response_data = response.json()
|
||||||
|
_value = response_data.get("prediction", {}).get("p1")
|
||||||
|
except requests.RequestException as error:
|
||||||
|
logger.error(f"Error while predicting: {error}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
if _value is not None:
|
||||||
|
logger.info(f"Prediction : {_value}")
|
||||||
|
return {'probability': float(_value)}
|
||||||
|
else:
|
||||||
|
logger.error("Response does not contain ''")
|
||||||
|
return None
|
||||||
|
|
||||||
|
except Exception as error:
|
||||||
|
logger.error(f"Error while predicting: {error}")
|
||||||
|
return {'error': str(error)}
|
||||||
|
|
||||||
|
# finally:
|
||||||
|
# h2o.cluster().shutdown()
|
||||||
@ -1 +1,95 @@
|
|||||||
{}
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"score_results": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "transunion score"
|
||||||
|
},
|
||||||
|
"AT34B": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Utilization for open trades verified in past 12 months (excluding mortgage and home equity)"
|
||||||
|
},
|
||||||
|
"AT12S": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Number of open trades verified in past 12 months"
|
||||||
|
},
|
||||||
|
"revolving_amount_percent_available_credit": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "The percentage of available credit that has been utilized in revolving credit accounts"
|
||||||
|
},
|
||||||
|
"AT28A": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Total credit line of open trades verified in past 12 months"
|
||||||
|
},
|
||||||
|
"record_counts_total_trade_count": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Total number of trade-related (transaction) records"
|
||||||
|
},
|
||||||
|
"record_counts_negative_trade_count": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Number of financial transaction that resulted in a negative impact"
|
||||||
|
},
|
||||||
|
"record_counts_revolving_trade_count": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Records in the database related to revolving trade accounts (a credit card account)"
|
||||||
|
},
|
||||||
|
"AT33A": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Total balance of open trades verified in past 12 months"
|
||||||
|
},
|
||||||
|
"AT35A": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Average balance of open trades verified in past 12 months"
|
||||||
|
},
|
||||||
|
"record_counts_total_inquiry_count": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Number of times user done inquiry"
|
||||||
|
},
|
||||||
|
"IN20S": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Months since oldest installment trade opened"
|
||||||
|
},
|
||||||
|
"RE102S": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Average credit line of open revolving trades verified in past 12 months"
|
||||||
|
},
|
||||||
|
"installment_amount_monthly_payment": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "The monthly payment amount for installment credit accounts"
|
||||||
|
},
|
||||||
|
"S061S": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Months since most recent 60 or more days past due"
|
||||||
|
},
|
||||||
|
"record_counts_installment_trade_count": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "The total count of installment trade records (fixed repayment schedules)"
|
||||||
|
},
|
||||||
|
"BR02S": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Number of open bank revolving trades"
|
||||||
|
},
|
||||||
|
"AGG103": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "Aggregate non-mortgage balances for month 3"
|
||||||
|
},
|
||||||
|
"ALL231": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "Aggregate excess payment for all accounts over the past month"
|
||||||
|
},
|
||||||
|
"G069S": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Number of trades 90 or more days past due in past 12 months"
|
||||||
|
},
|
||||||
|
"AT24S": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Number of currently open and satisfactory trades 6 months or older"
|
||||||
|
},
|
||||||
|
"BI02S": {
|
||||||
|
"type": ["integer", "null"],
|
||||||
|
"description": "Number of open bank installment trades"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": []
|
||||||
|
}
|
||||||
|
|||||||
@ -1 +1,2 @@
|
|||||||
{}
|
jsonschema==4.23.0
|
||||||
|
requests==2.32.3
|
||||||
@ -1 +1,10 @@
|
|||||||
{}
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"probability": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "Model predicted score."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user