|
@@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.xm.Similarity;
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
import java.io.BufferedReader;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
@@ -28,6 +29,8 @@ import java.util.concurrent.Future;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static com.tzld.piaoquan.ad.engine.commons.math.Const.WILSON_ZSCORE;
|
|
|
+
|
|
|
@Slf4j
|
|
|
@Component
|
|
|
public class RankStrategyBy683 extends RankStrategyBasic {
|
|
@@ -46,6 +49,11 @@ public class RankStrategyBy683 extends RankStrategyBasic {
|
|
|
@ApolloJsonValue("${rank.score.neg_sample_rate:0.01}")
|
|
|
Double negSampleRate;
|
|
|
|
|
|
+ @PostConstruct
|
|
|
+ public void afterInit() {
|
|
|
+ this.readBucketFile();
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<AdRankItem> adItemRank(RankRecommendRequestParam request, ScoreParam scoreParam) {
|
|
|
|
|
@@ -183,7 +191,6 @@ public class RankStrategyBy683 extends RankStrategyBasic {
|
|
|
|
|
|
long time3 = System.currentTimeMillis();
|
|
|
// 分桶
|
|
|
- this.readBucketFile();
|
|
|
userFeatureMap = this.featureBucket(userFeatureMap);
|
|
|
CountDownLatch cdl4 = new CountDownLatch(adRankItems.size());
|
|
|
for (AdRankItem adRankItem : adRankItems) {
|
|
@@ -322,17 +329,19 @@ public class RankStrategyBy683 extends RankStrategyBasic {
|
|
|
double click = Double.parseDouble(feature.getOrDefault("ad_click_" + time, "0"));
|
|
|
double conver = Double.parseDouble(feature.getOrDefault("ad_conversion_" + time, "0"));
|
|
|
double income = Double.parseDouble(feature.getOrDefault("ad_income_" + time, "0"));
|
|
|
- double f2 = NumUtil.div(conver, view);
|
|
|
- double ecpm = NumUtil.div(income * 1000, view);
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_ctr", String.valueOf(NumUtil.div(click, view)));
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_ctcvr", String.valueOf(f2));
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_cvr", String.valueOf(NumUtil.div(conver, click)));
|
|
|
+ double cpc = NumUtil.div(income, click);
|
|
|
+ double ctr = NumUtil.divSmoothV1(click, view, WILSON_ZSCORE);
|
|
|
+ double ctcvr = NumUtil.divSmoothV1(conver, view, WILSON_ZSCORE);
|
|
|
+ double ecpm = ctr * cpc * 1000;
|
|
|
+ cidFeatureMap.put(prefix + "_" + time + "_ctr", String.valueOf(ctr));
|
|
|
+ cidFeatureMap.put(prefix + "_" + time + "_ctcvr", String.valueOf(ctcvr));
|
|
|
+ cidFeatureMap.put(prefix + "_" + time + "_cvr", String.valueOf(NumUtil.divSmoothV1(conver, click, WILSON_ZSCORE)));
|
|
|
cidFeatureMap.put(prefix + "_" + time + "_conver", String.valueOf(conver));
|
|
|
cidFeatureMap.put(prefix + "_" + time + "_ecpm", String.valueOf(ecpm));
|
|
|
|
|
|
cidFeatureMap.put(prefix + "_" + time + "_click", String.valueOf(click));
|
|
|
cidFeatureMap.put(prefix + "_" + time + "_conver*log(view)", String.valueOf(conver * NumUtil.log(view)));
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_conver*ctcvr", String.valueOf(conver * f2));
|
|
|
+ cidFeatureMap.put(prefix + "_" + time + "_conver*ctcvr", String.valueOf(conver * ctcvr));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -355,17 +364,19 @@ public class RankStrategyBy683 extends RankStrategyBasic {
|
|
|
double click = Double.parseDouble(feature.getOrDefault("ad_click_" + time, "0"));
|
|
|
double conver = Double.parseDouble(feature.getOrDefault("ad_conversion_" + time, "0"));
|
|
|
double income = Double.parseDouble(feature.getOrDefault("ad_income_" + time, "0"));
|
|
|
- double f2 = NumUtil.div(conver, view);
|
|
|
- double ecpm = NumUtil.div(income * 1000, view);
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_ctr", String.valueOf(NumUtil.div(click, view)));
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_ctcvr", String.valueOf(f2));
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_cvr", String.valueOf(NumUtil.div(conver, click)));
|
|
|
+ double cpc = NumUtil.div(income, click);
|
|
|
+ double ctr = NumUtil.divSmoothV1(click, view, WILSON_ZSCORE);
|
|
|
+ double ctcvr = NumUtil.divSmoothV1(conver, view, WILSON_ZSCORE);
|
|
|
+ double ecpm = ctr * cpc * 1000;
|
|
|
+ cidFeatureMap.put(prefix + "_" + time + "_ctr", String.valueOf(ctr));
|
|
|
+ cidFeatureMap.put(prefix + "_" + time + "_ctcvr", String.valueOf(ctcvr));
|
|
|
+ cidFeatureMap.put(prefix + "_" + time + "_cvr", String.valueOf(NumUtil.divSmoothV1(conver, click, WILSON_ZSCORE)));
|
|
|
cidFeatureMap.put(prefix + "_" + time + "_conver", String.valueOf(conver));
|
|
|
cidFeatureMap.put(prefix + "_" + time + "_ecpm", String.valueOf(ecpm));
|
|
|
|
|
|
cidFeatureMap.put(prefix + "_" + time + "_click", String.valueOf(click));
|
|
|
cidFeatureMap.put(prefix + "_" + time + "_conver*log(view)", String.valueOf(conver * NumUtil.log(view)));
|
|
|
- cidFeatureMap.put(prefix + "_" + time + "_conver*ctcvr", String.valueOf(conver * f2));
|
|
|
+ cidFeatureMap.put(prefix + "_" + time + "_conver*ctcvr", String.valueOf(conver * ctcvr));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -449,11 +460,13 @@ public class RankStrategyBy683 extends RankStrategyBasic {
|
|
|
double click = Double.parseDouble(d1Feature.getOrDefault("ad_click_" + prefix, "0"));
|
|
|
double conver = Double.parseDouble(d1Feature.getOrDefault("ad_conversion_" + prefix, "0"));
|
|
|
double income = Double.parseDouble(d1Feature.getOrDefault("ad_income_" + prefix, "0"));
|
|
|
- featureMap.put("d1_feature_" + prefix + "_ctr", String.valueOf(NumUtil.div(click, view)));
|
|
|
- featureMap.put("d1_feature_" + prefix + "_ctcvr", String.valueOf(NumUtil.div(conver, view)));
|
|
|
- featureMap.put("d1_feature_" + prefix + "_cvr", String.valueOf(NumUtil.div(conver, click)));
|
|
|
+ double cpc = NumUtil.div(income, click);
|
|
|
+ double ctr = NumUtil.divSmoothV1(click, view, WILSON_ZSCORE);
|
|
|
+ featureMap.put("d1_feature_" + prefix + "_ctr", String.valueOf(ctr));
|
|
|
+ featureMap.put("d1_feature_" + prefix + "_ctcvr", String.valueOf(NumUtil.divSmoothV1(conver, view, WILSON_ZSCORE)));
|
|
|
+ featureMap.put("d1_feature_" + prefix + "_cvr", String.valueOf(NumUtil.divSmoothV1(conver, click, WILSON_ZSCORE)));
|
|
|
featureMap.put("d1_feature_" + prefix + "_conver", String.valueOf(conver));
|
|
|
- featureMap.put("d1_feature_" + prefix + "_ecpm", String.valueOf(NumUtil.div(income * 1000, view)));
|
|
|
+ featureMap.put("d1_feature_" + prefix + "_ecpm", String.valueOf(ctr * cpc * 1000));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -596,7 +609,8 @@ public class RankStrategyBy683 extends RankStrategyBasic {
|
|
|
return;
|
|
|
}
|
|
|
synchronized (this) {
|
|
|
- InputStream resourceStream = RankStrategyBy683.class.getClassLoader().getResourceAsStream("20240718_ad_bucket_688.txt");
|
|
|
+ String bucketFile = "20250113_ad_bucket_688.txt";
|
|
|
+ InputStream resourceStream = RankStrategyBy683.class.getClassLoader().getResourceAsStream(bucketFile);
|
|
|
if (resourceStream != null) {
|
|
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(resourceStream))) {
|
|
|
Map<String, double[]> bucketsMap = new HashMap<>();
|
|
@@ -619,8 +633,9 @@ public class RankStrategyBy683 extends RankStrategyBasic {
|
|
|
this.bucketsMap = bucketsMap;
|
|
|
this.bucketsLen = bucketsLen;
|
|
|
} catch (IOException e) {
|
|
|
- log.error("something is wrong in parse bucket file:", e);
|
|
|
+ log.error("something is wrong in parse bucket file: ", e);
|
|
|
}
|
|
|
+ log.info("load bucket file success: {}", bucketFile);
|
|
|
} else {
|
|
|
log.error("no bucket file");
|
|
|
}
|