76 lines
2.4 KiB
Python
76 lines
2.4 KiB
Python
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
|
|
|
|
# Compute FINAL_score based on conditions
|
|
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
|
|
|
|
logging.info(f"hd_score calculated: {hd_score}")
|
|
except Exception as e:
|
|
logging.error(f"Error processing hd_score calculations: {e}")
|
|
return {}
|
|
|
|
|
|
# Compute recommended_action
|
|
try:
|
|
recommended_action = "Decline Application" if hd_score > score_threshold else "Pass Application"
|
|
logging.info(f"recommended_action: {recommended_action}")
|
|
except Exception as e:
|
|
logging.error(f"Error assigning recommended_action: {e}")
|
|
return {}
|
|
|
|
# Compute 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"
|
|
)
|
|
logging.info(f"description: {description}")
|
|
except Exception as e:
|
|
logging.error(f"Error assigning description: {e}")
|
|
return {}
|
|
|
|
# Compute 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",
|
|
}
|
|
|
|
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}")
|
|
return {}
|
|
|
|
return {
|
|
"hd_score": hd_score,
|
|
"recommended_action": recommended_action,
|
|
"description": description,
|
|
"hd_action_reasoncode": hd_action_reasoncode,
|
|
}
|
|
|
|
|