Update Scores block processing and schema
All checks were successful
Build and Push Docker Image / test (push) Successful in 8s
Build and Push Docker Image / build_and_push (push) Successful in 17s

This commit is contained in:
Ankur Malik 2025-11-23 23:41:46 -05:00
parent d1e90e8a14
commit 20b2f4afdb
4 changed files with 80 additions and 34 deletions

View File

@ -14,6 +14,7 @@ def __main__(
hd_score_s1: float,
hd_score_s2: float,
hd_score_s3: float,
hd_score_iso_m2: float
) -> dict:
data = {
@ -22,6 +23,7 @@ def __main__(
"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,
}
final = processing(data)

View File

@ -21,6 +21,10 @@
"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

@ -10,61 +10,101 @@ logger = logging.getLogger(__name__)
def processing(data: dict) -> dict:
score_threshold = 1200
score_threshold2 = 1225
# Compute FINAL_score based on conditions
# ---- Compute hd_score1, hd_score2, final hd_score ----
try:
for key in ["hd_score_s1", "hd_score_s2", "hd_score_g1", "hd_score_s3"]:
if key in data and data[key] > score_threshold:
hd_score = data[key]
break
else:
hd_score = data.get("hd_score_m1", None) # Default if no conditions are met
hd_score1 = max([
data["hd_score_s1"],
data["hd_score_s2"],
data["hd_score_g1"],
data["hd_score_s3"],
data["hd_score_m1"],
])
hd_score2 = data["hd_score_iso_m2"]
if hd_score1 > score_threshold:
hd_score = hd_score1
elif hd_score2 >= score_threshold2:
hd_score = hd_score2
else:
hd_score = max(hd_score1, hd_score2)
# logging.info(f"Computed hd_score1={hd_score1}, hd_score2={hd_score2}, final hd_score={hd_score}")
logging.info(f"hd_score calculated: {hd_score}")
except Exception as e:
logging.error(f"Error processing hd_score calculations: {e}")
logging.error(f"Error calculating hd_score values: {e}")
return {}
# Compute recommended_action
# ---- recommended_action ----
try:
recommended_action = "Decline Application" if hd_score > score_threshold else "Pass Application"
if hd_score1 > score_threshold or hd_score2 >= score_threshold2:
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 {}
# Compute description
# ---- description ----
try:
description = (
f"HD Fraud Score is above the risk threshold {score_threshold}, Recommended action: Decline Application"
if hd_score > score_threshold
else f"HD Fraud Score is below the risk threshold {score_threshold}, Recommended action: Pass Application"
)
if hd_score1 > score_threshold:
description = (
f"HD Fraud Score is above the risk threshold {score_threshold}, "
f"Recommended action: Decline Application"
)
elif hd_score2 >= score_threshold2:
description = (
f"HD Fraud Score is above the risk threshold {score_threshold2}, "
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 assigning description: {e}")
logging.error(f"Error creating description: {e}")
return {}
# Compute action_reasoncode
# ---- hd_action_reasoncode ----
try:
action_reason_mapping = {
"hd_score_s1": "S1 Triggered",
"hd_score_s2": "S2 Triggered",
"hd_score_g1": "G1 Triggered",
"hd_score_s3": "S3 Triggered",
"hd_score_m1": "M1 Triggered",
}
reason_hierarchy = [
("hd_score_s1", "S1 Triggered"),
("hd_score_s2", "S2 Triggered"),
("hd_score_g1", "G1 Triggered"),
("hd_score_s3", "S3 Triggered"),
("hd_score_m1", "M1 Triggered"),
("hd_score_iso_m2", "M2 Triggered"), # NEW
]
hd_action_reasoncode = "Pass"
for key, reason in reason_hierarchy:
score = data[key]
if key == "hd_score_iso_m2":
if score >= score_threshold2:
hd_action_reasoncode = reason
break
else:
if score > score_threshold:
hd_action_reasoncode = reason
break
logging.info(f"hd_action_reasoncode: {hd_action_reasoncode}")
hd_action_reasoncode = next(
(reason for key, reason in action_reason_mapping.items() if data[key] > score_threshold),
"Pass"
)
logging.info(f"action_reasoncode: {hd_action_reasoncode}")
except Exception as e:
logging.error(f"Error compiling action_reasoncode: {e}")
logging.error(f"Error determining action_reasoncode: {e}")
return {}
# ---- Return only original 4 fields ----
return {
"hd_score": hd_score,
"recommended_action": recommended_action,

View File

@ -1,7 +1,7 @@
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}
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}
class TestBlock(unittest.TestCase):
def test_main_success(self):