|
@@ -13,6 +13,7 @@ import com.tzld.piaoquan.ad.engine.service.feature.Feature;
|
|
|
import com.tzld.piaoquan.ad.engine.service.feature.FeatureService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.collections4.MapUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
@@ -38,8 +39,7 @@ public abstract class RankStrategyBasic implements RankStrategy {
|
|
|
@Autowired
|
|
|
protected AdRedisHelper adRedisHelper;
|
|
|
|
|
|
- String key = "ad:platform:guarantee:data:{date}:{adrId}";
|
|
|
-
|
|
|
+ String adPlatformGuaranteeKey = "ad:platform:guarantee:data:{date}:{adverId}";
|
|
|
|
|
|
|
|
|
protected Feature getFeature(ScoreParam param, RankRecommendRequestParam request) {
|
|
@@ -113,27 +113,46 @@ public abstract class RankStrategyBasic implements RankStrategy {
|
|
|
|
|
|
protected Map<String, GuaranteeView> getGuaranteeViewMap(RankRecommendRequestParam request, ScoreParam scoreParam) {
|
|
|
Map<String, GuaranteeView> map = new HashMap<>();
|
|
|
- if (scoreParam.getExpCodeSet().contains(guaranteeExp)) {
|
|
|
- String thatDayDateString = DateUtils.getThatDayDateString();
|
|
|
- String redisKey = key.replace("{date}", thatDayDateString);
|
|
|
- List<String> adVerIds = request.getAdIdList().stream().map(AdPlatformCreativeDTO::getAdVerId).distinct()
|
|
|
- .filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
- List<String> redisKeys = adVerIds.stream().map(e -> redisKey.replace("{adrId}", e)).collect(Collectors.toList());
|
|
|
- List<String> values = adRedisHelper.mget(redisKeys);
|
|
|
- if (CollectionUtils.isNotEmpty(values)) {
|
|
|
- for (int i = 0; i < redisKeys.size(); i++) {
|
|
|
- String value = values.get(i);
|
|
|
- if (value != null) {
|
|
|
- GuaranteeView guaranteeView = JSONObject.parseObject(value, GuaranteeView.class);
|
|
|
- map.put(adVerIds.get(i), guaranteeView);
|
|
|
+ try {
|
|
|
+ if (scoreParam.getExpCodeSet().contains(guaranteeExp)) {
|
|
|
+ String thatDayDateString = DateUtils.getThatDayDateString();
|
|
|
+ String redisKey = adPlatformGuaranteeKey.replace("{date}", thatDayDateString);
|
|
|
+ List<String> adVerIds = request.getAdIdList().stream().map(AdPlatformCreativeDTO::getAdVerId).distinct()
|
|
|
+ .filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
+ List<String> redisKeys = adVerIds.stream().map(e -> redisKey.replace("{adverId}", e)).collect(Collectors.toList());
|
|
|
+ List<String> values = adRedisHelper.mget(redisKeys);
|
|
|
+ if (CollectionUtils.isNotEmpty(values)) {
|
|
|
+ for (int i = 0; i < redisKeys.size(); i++) {
|
|
|
+ String value = values.get(i);
|
|
|
+ if (value != null) {
|
|
|
+ GuaranteeView guaranteeView = JSONObject.parseObject(value, GuaranteeView.class);
|
|
|
+ map.put(adVerIds.get(i), guaranteeView);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("getGuaranteeViewMap error", e);
|
|
|
}
|
|
|
+
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
- protected double getGuaranteeWeight(GuaranteeView guaranteeView) {
|
|
|
+ protected void setGuaranteeWeight(Map<String, GuaranteeView> map, String adVerId, Map<String, Object> ext) {
|
|
|
+ if (MapUtils.isNotEmpty(map)) {
|
|
|
+ GuaranteeView guaranteeView = map.get(adVerId);
|
|
|
+ if (guaranteeView != null) {
|
|
|
+ double guaranteeWeight = calculateGuaranteedWeight(guaranteeView);
|
|
|
+ ext.put("guaranteeView", guaranteeView.toString());
|
|
|
+ ext.put("guaranteeWeight", guaranteeWeight);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ protected double calculateGuaranteedWeight(GuaranteeView guaranteeView) {
|
|
|
+ if (guaranteeView == null) {
|
|
|
+ return 1.0;
|
|
|
+ }
|
|
|
double guaranteeWeight;
|
|
|
if (guaranteeView.getGuaranteeNum() == null || guaranteeView.getGuaranteeNum() == 0
|
|
|
|| guaranteeView.getGuaranteeRate() == null || guaranteeView.getGuaranteeRate() == 0.0) {
|
|
@@ -143,9 +162,11 @@ public abstract class RankStrategyBasic implements RankStrategy {
|
|
|
guaranteeView.getGuaranteeNum() <= guaranteeView.getAdrAlgoViewNum()) {
|
|
|
guaranteeWeight = 0.0;
|
|
|
} else {
|
|
|
- int allViewNum = guaranteeView.getAllAlgoViewNum() == null || guaranteeView.getAllAlgoViewNum() == 0 ? 1 : guaranteeView.getAllAlgoViewNum();
|
|
|
- int adrAlogViewNum = guaranteeView.getAdrAlgoViewNum() == null || guaranteeView.getAdrAlgoViewNum() == 0 ? 1 : guaranteeView.getAdrAlgoViewNum();
|
|
|
- //guaranteeView.getGuaranteeRate() 是百分之几 要成0.01
|
|
|
+ int allViewNum = guaranteeView.getAllAlgoViewNum() == null || guaranteeView.getAllAlgoViewNum() == 0 ?
|
|
|
+ 1 : guaranteeView.getAllAlgoViewNum();
|
|
|
+ int adrAlogViewNum = guaranteeView.getAdrAlgoViewNum() == null || guaranteeView.getAdrAlgoViewNum() == 0 ?
|
|
|
+ 1 : guaranteeView.getAdrAlgoViewNum();
|
|
|
+ //guaranteeView.getGuaranteeRate() 是百分之几 要乘0.01
|
|
|
guaranteeWeight = guaranteeView.getGuaranteeRate() * 0.01 * allViewNum / adrAlogViewNum;
|
|
|
if (guaranteeWeight < 0.5) {
|
|
|
guaranteeWeight = 0.5;
|
|
@@ -157,4 +178,16 @@ public abstract class RankStrategyBasic implements RankStrategy {
|
|
|
}
|
|
|
return guaranteeWeight;
|
|
|
}
|
|
|
+
|
|
|
+ protected double getGuaranteeScoreCoefficient(ScoreParam scoreParam, Map<String, Object> ext) {
|
|
|
+ if (scoreParam.getExpCodeSet().contains(guaranteeExp)) {
|
|
|
+ if (ext.get("guaranteeWeight") == null) {
|
|
|
+ return 1.0;
|
|
|
+ } else {
|
|
|
+ return Math.pow((double) ext.get("guaranteeWeight"), alpha);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return 1.0;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|