Add hd_score_g2 support and reason-based scoring
This commit is contained in:
parent
20b2f4afdb
commit
b3be1ebf66
4
block.py
4
block.py
@ -14,7 +14,8 @@ def __main__(
|
|||||||
hd_score_s1: float,
|
hd_score_s1: float,
|
||||||
hd_score_s2: float,
|
hd_score_s2: float,
|
||||||
hd_score_s3: float,
|
hd_score_s3: float,
|
||||||
hd_score_iso_m2: float
|
hd_score_iso_m2: float,
|
||||||
|
hd_score_g2: float
|
||||||
) -> dict:
|
) -> dict:
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
@ -24,6 +25,7 @@ def __main__(
|
|||||||
"hd_score_s2": hd_score_s2,
|
"hd_score_s2": hd_score_s2,
|
||||||
"hd_score_s3": hd_score_s3,
|
"hd_score_s3": hd_score_s3,
|
||||||
"hd_score_iso_m2": hd_score_iso_m2,
|
"hd_score_iso_m2": hd_score_iso_m2,
|
||||||
|
"hd_score_g2": hd_score_g2
|
||||||
}
|
}
|
||||||
|
|
||||||
final = processing(data)
|
final = processing(data)
|
||||||
|
|||||||
@ -10,6 +10,10 @@
|
|||||||
"type": ["number", "null"],
|
"type": ["number", "null"],
|
||||||
"description": "HD Fraud Score G1"
|
"description": "HD Fraud Score G1"
|
||||||
},
|
},
|
||||||
|
"hd_score_g2": {
|
||||||
|
"type": ["number", "null"],
|
||||||
|
"description": "HD Fraud Score G1"
|
||||||
|
},
|
||||||
"hd_score_s1": {
|
"hd_score_s1": {
|
||||||
"type": ["number", "null"],
|
"type": ["number", "null"],
|
||||||
"description": "HD Fraud Score S1"
|
"description": "HD Fraud Score S1"
|
||||||
|
|||||||
@ -12,26 +12,46 @@ def processing(data: dict) -> dict:
|
|||||||
score_threshold = 1200
|
score_threshold = 1200
|
||||||
score_threshold2 = 1225
|
score_threshold2 = 1225
|
||||||
|
|
||||||
# ---- Compute hd_score1, hd_score2, final hd_score ----
|
# ---- Compute hd_score based on hierarchy ----
|
||||||
try:
|
try:
|
||||||
hd_score1 = max([
|
reason_hierarchy = [
|
||||||
data["hd_score_s1"],
|
("hd_score_s1", "S1 Triggered", score_threshold, True),
|
||||||
data["hd_score_s2"],
|
("hd_score_s2", "S2 Triggered", score_threshold, True),
|
||||||
data["hd_score_g1"],
|
("hd_score_g1", "G1 Triggered", score_threshold, True),
|
||||||
data["hd_score_s3"],
|
("hd_score_s3", "S3 Triggered", score_threshold, True),
|
||||||
data["hd_score_m1"],
|
("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),
|
||||||
|
]
|
||||||
|
|
||||||
hd_score2 = data["hd_score_iso_m2"]
|
winning_score = None
|
||||||
|
winning_reason = "Pass"
|
||||||
|
winning_threshold = None
|
||||||
|
|
||||||
if hd_score1 > score_threshold:
|
for key, reason, threshold, use_gt in reason_hierarchy:
|
||||||
hd_score = hd_score1
|
score = data.get(key)
|
||||||
elif hd_score2 >= score_threshold2:
|
if score is None:
|
||||||
hd_score = hd_score2
|
continue
|
||||||
else:
|
passes = (score > threshold) if use_gt else (score >= threshold)
|
||||||
hd_score = max(hd_score1, hd_score2)
|
if passes:
|
||||||
|
winning_score = score
|
||||||
|
winning_reason = reason
|
||||||
|
winning_threshold = threshold
|
||||||
|
break
|
||||||
|
|
||||||
# logging.info(f"Computed hd_score1={hd_score1}, hd_score2={hd_score2}, final hd_score={hd_score}")
|
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:
|
except Exception as e:
|
||||||
logging.error(f"Error calculating hd_score values: {e}")
|
logging.error(f"Error calculating hd_score values: {e}")
|
||||||
@ -39,7 +59,7 @@ def processing(data: dict) -> dict:
|
|||||||
|
|
||||||
# ---- recommended_action ----
|
# ---- recommended_action ----
|
||||||
try:
|
try:
|
||||||
if hd_score1 > score_threshold or hd_score2 >= score_threshold2:
|
if winning_reason != "Pass":
|
||||||
recommended_action = "Decline Application"
|
recommended_action = "Decline Application"
|
||||||
else:
|
else:
|
||||||
recommended_action = "Pass Application"
|
recommended_action = "Pass Application"
|
||||||
@ -52,14 +72,10 @@ def processing(data: dict) -> dict:
|
|||||||
|
|
||||||
# ---- description ----
|
# ---- description ----
|
||||||
try:
|
try:
|
||||||
if hd_score1 > score_threshold:
|
if winning_reason != "Pass":
|
||||||
|
threshold_used = winning_threshold if winning_threshold is not None else score_threshold
|
||||||
description = (
|
description = (
|
||||||
f"HD Fraud Score is above the risk threshold {score_threshold}, "
|
f"HD Fraud Score is above the risk threshold {threshold_used}, "
|
||||||
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"
|
f"Recommended action: Decline Application"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@ -74,35 +90,8 @@ def processing(data: dict) -> dict:
|
|||||||
return {}
|
return {}
|
||||||
|
|
||||||
# ---- hd_action_reasoncode ----
|
# ---- hd_action_reasoncode ----
|
||||||
try:
|
hd_action_reasoncode = winning_reason
|
||||||
reason_hierarchy = [
|
logging.info(f"hd_action_reasoncode: {hd_action_reasoncode}")
|
||||||
("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}")
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"Error determining action_reasoncode: {e}")
|
|
||||||
return {}
|
|
||||||
|
|
||||||
# ---- Return only original 4 fields ----
|
# ---- Return only original 4 fields ----
|
||||||
return {
|
return {
|
||||||
@ -111,5 +100,3 @@ def processing(data: dict) -> dict:
|
|||||||
"description": description,
|
"description": description,
|
||||||
"hd_action_reasoncode": hd_action_reasoncode,
|
"hd_action_reasoncode": hd_action_reasoncode,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import unittest
|
import unittest
|
||||||
from block import __main__
|
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}
|
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):
|
class TestBlock(unittest.TestCase):
|
||||||
def test_main_success(self):
|
def test_main_success(self):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user