2025-03-12 16:13:29 +00:00
|
|
|
import logging
|
|
|
|
|
import math
|
2025-11-26 11:49:57 -05:00
|
|
|
from decimal import Decimal, ROUND_HALF_UP
|
2025-03-12 16:13:29 +00:00
|
|
|
|
|
|
|
|
# Configure logging
|
|
|
|
|
logging.basicConfig(
|
|
|
|
|
level=logging.INFO,
|
|
|
|
|
format="%(asctime)s [%(levelname)s] %(name)s - %(message)s",
|
|
|
|
|
)
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
2025-11-26 11:49:57 -05:00
|
|
|
|
|
|
|
|
def post_processing_g1(data):
|
2025-03-12 16:13:29 +00:00
|
|
|
try:
|
|
|
|
|
prediction = data.get("prediction", 0)
|
|
|
|
|
score_g1 = round(
|
|
|
|
|
min(prediction * 100 + 0.00001, 1) * 89 +
|
|
|
|
|
max(math.log2(prediction * 100 + 0.000001) * 193, 0),
|
|
|
|
|
0
|
|
|
|
|
)
|
|
|
|
|
data["hd_score_g1"] = score_g1
|
2025-11-26 11:49:57 -05:00
|
|
|
logger.info("score_g1 calculated: %s", score_g1)
|
2025-03-12 16:13:29 +00:00
|
|
|
except Exception as e:
|
2025-11-26 11:49:57 -05:00
|
|
|
logger.error("Error processing score_g1 calculations: %s", e)
|
2025-03-12 16:13:29 +00:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
key: data.get(key, None)
|
|
|
|
|
for key in [
|
|
|
|
|
"hd_score_m1", "hd_score_g1", "cluster_size_users_v2",
|
|
|
|
|
"target_connected_30_sum", "email_cnt", "rejected_app_count",
|
2025-11-23 23:35:24 -05:00
|
|
|
"app_dt_day_cnt", "hd_score_iso_m2"
|
2025-03-12 16:13:29 +00:00
|
|
|
]
|
|
|
|
|
}
|
2025-11-26 11:49:57 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def post_processing_g2(data):
|
|
|
|
|
prediction = data.get("prediction_g2", data.get("prediction"))
|
|
|
|
|
hd_score_g2 = None
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
if prediction is not None:
|
|
|
|
|
prediction_val = float(prediction)
|
|
|
|
|
raw_score = (prediction_val * 100) * 20 + math.log((prediction_val + 0.000001) * 100, 2) * 41.6
|
|
|
|
|
# SQL-like rounding (half up)
|
|
|
|
|
hd_score_g2 = int(Decimal(str(raw_score)).quantize(Decimal("1"), rounding=ROUND_HALF_UP))
|
|
|
|
|
hd_score_g2 = max(hd_score_g2, 0.0)
|
|
|
|
|
logger.info("score_g2 calculated: %s", hd_score_g2)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logger.error("Error processing score_g2 calculations: %s", e)
|
|
|
|
|
|
|
|
|
|
return {"hd_score_g2": hd_score_g2}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Backward compatibility alias
|
|
|
|
|
post_processing = post_processing_g1
|