|
|
@@ -364,7 +364,7 @@ public class RankStrategyBy897 extends RankStrategyBasic {
|
|
|
double maxCopc = NumberUtils.toDouble(paramsMap.getOrDefault("maxCopc", "2.5"));
|
|
|
List<AdRankItem> layerTargetCopcFallbackItems = calibrationCidCtcvr(result, calibModelName, reqFeature,
|
|
|
minValidCopc, maxValidCopc, minCopc, maxCopc);
|
|
|
- calculateLayerTargetCopc(layerTargetCopcFallbackItems, calibModelName, reqFeature);
|
|
|
+ calculateLayerTargetCopc(layerTargetCopcFallbackItems, calibModelName, reqFeature, scoreParam.getPqtId());
|
|
|
if (CollectionUtils.isEmpty(result)) {
|
|
|
log.error("calculateCtcvrScore result is empty");
|
|
|
}
|
|
|
@@ -1159,14 +1159,28 @@ public class RankStrategyBy897 extends RankStrategyBasic {
|
|
|
return fallbackItems;
|
|
|
}
|
|
|
|
|
|
- private void calculateLayerTargetCopc(List<AdRankItem> items, String modelName, Map<String, String> reqFeature) {
|
|
|
+ private void calculateLayerTargetCopc(List<AdRankItem> items, String modelName,
|
|
|
+ Map<String, String> reqFeature, String pqtId) {
|
|
|
+ String layer = MapUtils.isEmpty(reqFeature) ? null : reqFeature.get("layer_l6");
|
|
|
+ int itemSize = CollectionUtils.isEmpty(items) ? 0 : items.size();
|
|
|
+ log.info("RankStrategyBy897 calculateLayerTargetCopc start, pqtId={}, modelName={}, layer={}, itemSize={}",
|
|
|
+ pqtId, modelName, layer, itemSize);
|
|
|
try {
|
|
|
- if (CollectionUtils.isEmpty(items) || StringUtils.isBlank(modelName) || MapUtils.isEmpty(reqFeature)) {
|
|
|
+ if (CollectionUtils.isEmpty(items)) {
|
|
|
+ log.info("RankStrategyBy897 calculateLayerTargetCopc stop, pqtId={}, reason=items_empty", pqtId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(modelName)) {
|
|
|
+ log.info("RankStrategyBy897 calculateLayerTargetCopc stop, pqtId={}, reason=model_name_blank", pqtId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (MapUtils.isEmpty(reqFeature)) {
|
|
|
+ log.info("RankStrategyBy897 calculateLayerTargetCopc stop, pqtId={}, reason=req_feature_empty", pqtId);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- String layer = reqFeature.get("layer_l6");
|
|
|
if (StringUtils.isBlank(layer)) {
|
|
|
+ log.info("RankStrategyBy897 calculateLayerTargetCopc stop, pqtId={}, reason=layer_l6_blank", pqtId);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -1176,11 +1190,20 @@ public class RankStrategyBy897 extends RankStrategyBasic {
|
|
|
.replace("{layer}", layer);
|
|
|
|
|
|
Map<String, List<AdRankItem>> itemsByRedisKey = new LinkedHashMap<>();
|
|
|
+ int missingDimensionItemSize = 0;
|
|
|
for (AdRankItem item : items) {
|
|
|
- if (item == null
|
|
|
- || StringUtils.isBlank(item.getProfession())
|
|
|
+ if (item == null) {
|
|
|
+ missingDimensionItemSize++;
|
|
|
+ log.info("RankStrategyBy897 calculateLayerTargetCopc skip item, pqtId={}, reason=item_null", pqtId);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(item.getProfession())
|
|
|
|| item.getLandingPageType() == null
|
|
|
|| StringUtils.isBlank(item.getTargetingConversion())) {
|
|
|
+ missingDimensionItemSize++;
|
|
|
+ log.info("RankStrategyBy897 calculateLayerTargetCopc skip item, pqtId={}, cid={}, profession={}, " +
|
|
|
+ "landingPageType={}, targetingConversion={}, reason=dimension_missing",
|
|
|
+ pqtId, item.getAdId(), item.getProfession(), item.getLandingPageType(), item.getTargetingConversion());
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
@@ -1192,23 +1215,36 @@ public class RankStrategyBy897 extends RankStrategyBasic {
|
|
|
}
|
|
|
|
|
|
if (itemsByRedisKey.isEmpty()) {
|
|
|
+ log.info("RankStrategyBy897 calculateLayerTargetCopc stop, pqtId={}, reason=redis_keys_empty, " +
|
|
|
+ "itemSize={}, missingDimensionItemSize={}",
|
|
|
+ pqtId, itemSize, missingDimensionItemSize);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
List<String> redisKeys = new ArrayList<>(itemsByRedisKey.keySet());
|
|
|
+ log.info("RankStrategyBy897 calculateLayerTargetCopc mget start, pqtId={}, redisKeySize={}, redisKeys={}",
|
|
|
+ pqtId, redisKeys.size(), redisKeys);
|
|
|
List<String> redisValues = algRedisHelper.mget(redisKeys);
|
|
|
if (redisValues == null) {
|
|
|
+ log.info("RankStrategyBy897 calculateLayerTargetCopc stop, pqtId={}, reason=redis_values_null, " +
|
|
|
+ "redisKeySize={}", pqtId, redisKeys.size());
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
int resultSize = Math.min(redisKeys.size(), redisValues.size());
|
|
|
+ int redisHitSize = 0;
|
|
|
+ int correctedItemSize = 0;
|
|
|
+ int coefficientSkippedItemSize = 0;
|
|
|
for (int i = 0; i < resultSize; i++) {
|
|
|
String value = redisValues.get(i);
|
|
|
if (StringUtils.isEmpty(value)) {
|
|
|
+ log.info("RankStrategyBy897 calculateLayerTargetCopc redis miss, pqtId={}, redisKey={}, reason=value_empty",
|
|
|
+ pqtId, redisKeys.get(i));
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
+ redisHitSize++;
|
|
|
JSONObject json = JSONObject.parseObject(value);
|
|
|
CalibrationModelCtcvrDataV2 calibrationData = new CalibrationModelCtcvrDataV2();
|
|
|
calibrationData.setRealCtcvr(json.getDouble("ctcvr"));
|
|
|
@@ -1221,41 +1257,79 @@ public class RankStrategyBy897 extends RankStrategyBasic {
|
|
|
? json.getDouble("modelCtcvrCopc") : json.getDouble("copc2"));
|
|
|
|
|
|
Double coefficient = calibrationData.getModelCtcvrCopc();
|
|
|
+ String coefficientSource = "modelCtcvrCopc";
|
|
|
if (coefficient == null
|
|
|
&& calibrationData.getRealCtcvr() != null
|
|
|
&& calibrationData.getPCtcvr() != null
|
|
|
&& calibrationData.getPCtcvr() > 0) {
|
|
|
coefficient = calibrationData.getRealCtcvr() / calibrationData.getPCtcvr();
|
|
|
+ coefficientSource = "realCtcvr_div_pCtcvr";
|
|
|
}
|
|
|
+ log.info("RankStrategyBy897 calculateLayerTargetCopc redis hit, pqtId={}, redisKey={}, " +
|
|
|
+ "calibrationData={}, coefficient={}, coefficientSource={}",
|
|
|
+ pqtId, redisKeys.get(i), JSONObject.toJSONString(calibrationData), coefficient, coefficientSource);
|
|
|
|
|
|
for (AdRankItem item : itemsByRedisKey.get(redisKeys.get(i))) {
|
|
|
item.getExt().put("calibrationLayerTargetCtcvrData", JSONObject.toJSONString(calibrationData));
|
|
|
item.getScoreMap().put("layerTargetCopcCoefficient", 1.0);
|
|
|
- if (coefficient == null
|
|
|
- || coefficient <= 0
|
|
|
- || coefficient.isNaN()
|
|
|
- || coefficient.isInfinite()
|
|
|
- || Math.abs(coefficient - 1) < 0.1) {
|
|
|
+ String skipReason = getLayerTargetCopcSkipReason(coefficient);
|
|
|
+ if (skipReason != null) {
|
|
|
+ coefficientSkippedItemSize++;
|
|
|
+ log.info("RankStrategyBy897 calculateLayerTargetCopc skip correction, pqtId={}, cid={}, " +
|
|
|
+ "redisKey={}, coefficient={}, lrScore={}, reason={}",
|
|
|
+ pqtId, item.getAdId(), redisKeys.get(i), coefficient, item.getLrScore(), skipReason);
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
+ double beforeCtcvrScore = item.getLrScore();
|
|
|
double calibratedCtcvrScore = item.getLrScore() * coefficient;
|
|
|
item.getScoreMap().put("layerTargetCopcCoefficient", coefficient);
|
|
|
item.getScoreMap().put("layerTargetCtcvrScore", calibratedCtcvrScore);
|
|
|
item.getScoreMap().put("ctcvrScore", calibratedCtcvrScore);
|
|
|
item.setLrScore(calibratedCtcvrScore);
|
|
|
+ correctedItemSize++;
|
|
|
+ log.info("RankStrategyBy897 calculateLayerTargetCopc corrected, pqtId={}, cid={}, redisKey={}, " +
|
|
|
+ "coefficient={}, beforeCtcvrScore={}, afterCtcvrScore={}",
|
|
|
+ pqtId, item.getAdId(), redisKeys.get(i), coefficient,
|
|
|
+ beforeCtcvrScore, calibratedCtcvrScore);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- log.warn("RankStrategyBy897 parse layer target COPC failed, redisKey={}, value={}", redisKeys.get(i), value, e);
|
|
|
+ log.warn("RankStrategyBy897 parse layer target COPC failed, pqtId={}, redisKey={}, value={}",
|
|
|
+ pqtId, redisKeys.get(i), value, e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (redisValues.size() != redisKeys.size()) {
|
|
|
- log.warn("RankStrategyBy897 layer target COPC mget size mismatch, keySize={}, valueSize={}",
|
|
|
- redisKeys.size(), redisValues.size());
|
|
|
+ log.warn("RankStrategyBy897 layer target COPC mget size mismatch, pqtId={}, keySize={}, valueSize={}",
|
|
|
+ pqtId, redisKeys.size(), redisValues.size());
|
|
|
}
|
|
|
+ log.info("RankStrategyBy897 calculateLayerTargetCopc finish, pqtId={}, itemSize={}, " +
|
|
|
+ "missingDimensionItemSize={}, redisKeySize={}, redisHitSize={}, " +
|
|
|
+ "coefficientSkippedItemSize={}, correctedItemSize={}",
|
|
|
+ pqtId, itemSize, missingDimensionItemSize, redisKeys.size(), redisHitSize,
|
|
|
+ coefficientSkippedItemSize, correctedItemSize);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("RankStrategyBy897 calculateLayerTargetCopc error", e);
|
|
|
+ log.error("RankStrategyBy897 calculateLayerTargetCopc error, pqtId={}, modelName={}, layer={}, itemSize={}",
|
|
|
+ pqtId, modelName, layer, itemSize, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getLayerTargetCopcSkipReason(Double coefficient) {
|
|
|
+ if (coefficient == null) {
|
|
|
+ return "coefficient_null";
|
|
|
+ }
|
|
|
+ if (coefficient <= 0) {
|
|
|
+ return "coefficient_non_positive";
|
|
|
+ }
|
|
|
+ if (coefficient.isNaN()) {
|
|
|
+ return "coefficient_nan";
|
|
|
+ }
|
|
|
+ if (coefficient.isInfinite()) {
|
|
|
+ return "coefficient_infinite";
|
|
|
+ }
|
|
|
+ if (Math.abs(coefficient - 1) < 0.1) {
|
|
|
+ return "coefficient_within_no_correction_range";
|
|
|
}
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|