Compare commits

..

No commits in common. "score-v-1" and "main" have entirely different histories.

7 changed files with 23 additions and 216 deletions

View File

@ -1 +1 @@
# Block for assigning a composite score
**Hello world!!!**

View File

@ -1,37 +1,21 @@
import logging
from score_processing import processing
@flowx_block
def example_function(request: dict) -> dict:
# Configure logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s - %(message)s",
)
logger = logging.getLogger(__name__)
# Processing logic here...
def __main__(
hd_score_m1: float,
hd_score_g1: float,
hd_score_s1: float,
hd_score_s2: float,
hd_score_s3: float,
hd_score_iso_m2: float,
hd_score_g2: float
) -> dict:
data = {
"hd_score_m1": hd_score_m1,
"hd_score_g1": hd_score_g1,
"hd_score_s1": hd_score_s1,
"hd_score_s2": hd_score_s2,
"hd_score_s3": hd_score_s3,
"hd_score_iso_m2": hd_score_iso_m2,
"hd_score_g2": hd_score_g2
}
final = processing(data)
logger.info(f"Scores of application: {final}")
return final
# testing :
# __main__
return {
"meta_info": [
{
"name": "created_date",
"type": "string",
"value": "2024-11-05"
}
],
"fields": [
{
"name": "",
"type": "",
"value": ""
}
]
}

View File

@ -1,35 +1 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"hd_score_m1": {
"type": ["number", "null"],
"description": "HD Fraud Score M1"
},
"hd_score_g1": {
"type": ["number", "null"],
"description": "HD Fraud Score G1"
},
"hd_score_g2": {
"type": ["number", "null"],
"description": "HD Fraud Score G1"
},
"hd_score_s1": {
"type": ["number", "null"],
"description": "HD Fraud Score S1"
},
"hd_score_s2": {
"type": ["number", "null"],
"description": "HD Fraud Score S2"
},
"hd_score_s3": {
"type": ["number", "null"],
"description": "HD Fraud Score S3"
},
"hd_score_iso_m2": {
"type": ["number", "null"],
"description": "HD Fraud Score M2"
}
},
"required": []
}
{}

View File

@ -1 +1 @@
{}

View File

@ -1,25 +1 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"hd_score": {
"type": ["number", "null"],
"description": "HD fraud Score"
},
"recommended_action": {
"type": ["string", "null"],
"description": "Recommended Action"
},
"description": {
"type": ["string", "null"],
"description": "Description of Recommended Action"
},
"hd_action_reasoncode": {
"type": ["string", "null"],
"description": "HD Action Reasoncode"
}
}
}
{}

View File

@ -1,102 +0,0 @@
import logging
# Configure logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s [%(levelname)s] %(name)s - %(message)s",
)
logger = logging.getLogger(__name__)
def processing(data: dict) -> dict:
score_threshold = 1200
score_threshold2 = 1225
# ---- Compute hd_score based on hierarchy ----
try:
reason_hierarchy = [
("hd_score_s1", "S1 Triggered", score_threshold, True),
("hd_score_s2", "S2 Triggered", score_threshold, True),
("hd_score_g1", "G1 Triggered", score_threshold, True),
("hd_score_s3", "S3 Triggered", score_threshold, True),
("hd_score_m1", "M1 Triggered", score_threshold, True),
("hd_score_iso_m2", "M2 Triggered", score_threshold2, False),
("hd_score_g2", "G2 Triggered", score_threshold2, False),
]
winning_score = None
winning_reason = "Pass"
winning_threshold = None
for key, reason, threshold, use_gt in reason_hierarchy:
score = data.get(key)
if score is None:
continue
passes = (score > threshold) if use_gt else (score >= threshold)
if passes:
winning_score = score
winning_reason = reason
winning_threshold = threshold
break
if winning_score is None:
winning_score = max([
data.get("hd_score_s1", 0),
data.get("hd_score_s2", 0),
data.get("hd_score_g1", 0),
data.get("hd_score_s3", 0),
data.get("hd_score_m1", 0),
data.get("hd_score_iso_m2", 0),
data.get("hd_score_g2", 0),
])
winning_reason = "Pass"
hd_score = winning_score
except Exception as e:
logging.error(f"Error calculating hd_score values: {e}")
return {}
# ---- recommended_action ----
try:
if winning_reason != "Pass":
recommended_action = "Decline Application"
else:
recommended_action = "Pass Application"
logging.info(f"recommended_action: {recommended_action}")
except Exception as e:
logging.error(f"Error assigning recommended_action: {e}")
return {}
# ---- description ----
try:
if winning_reason != "Pass":
threshold_used = winning_threshold if winning_threshold is not None else score_threshold
description = (
f"HD Fraud Score is above the risk threshold {threshold_used}, "
f"Recommended action: Decline Application"
)
else:
description = (
"HD Fraud Score is below the risk threshold, Recommended action: Pass Application"
)
logging.info(f"description: {description}")
except Exception as e:
logging.error(f"Error creating description: {e}")
return {}
# ---- hd_action_reasoncode ----
hd_action_reasoncode = winning_reason
logging.info(f"hd_action_reasoncode: {hd_action_reasoncode}")
# ---- Return only original 4 fields ----
return {
"hd_score": hd_score,
"recommended_action": recommended_action,
"description": description,
"hd_action_reasoncode": hd_action_reasoncode,
}

View File

@ -1,17 +0,0 @@
import unittest
from block import __main__
data = {'hd_score_m1': 1173.0, 'hd_score_g1': 1203.0, 'hd_score_s1': 1240.0, 'hd_score_s2': 0, 'hd_score_s3': 0, 'hd_score_iso_m2': 1001.0, 'hd_score_g2': 0.0}
class TestBlock(unittest.TestCase):
def test_main_success(self):
# blockResult = main(data)
blockResult = __main__(**data)
# breakpoint()
self.assertIsInstance(blockResult, dict, "Result should be a dictionary.")
self.assertIn("hd_score", blockResult, "Result dictionary should contain 'hd_score' if success.")
if __name__ == "__main__":
unittest.main()