|
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.tzld.longarticle.recommend.server.model.Content;
|
|
|
import com.tzld.longarticle.recommend.server.service.score.*;
|
|
|
import com.tzld.longarticle.recommend.server.util.CommonCollectionUtils;
|
|
|
+import com.tzld.longarticle.recommend.server.util.NormalizationUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
|
@@ -12,6 +13,7 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -23,6 +25,13 @@ public class ViewMultiplierStrategy implements ScoreStrategy {
|
|
|
|
|
|
@Autowired
|
|
|
NamedParameterJdbcTemplate programDataJdbcTemplate;
|
|
|
+ private JSONObject jsonObject;
|
|
|
+
|
|
|
+ @PostConstruct
|
|
|
+ public void init() {
|
|
|
+ String cardJSON = ResourceUtil.readUtf8Str("file/AccountInfo.json");
|
|
|
+ jsonObject = JSONObject.parseObject(cardJSON);
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public List<Score> score(ScoreParam param) {
|
|
@@ -43,9 +52,9 @@ public class ViewMultiplierStrategy implements ScoreStrategy {
|
|
|
if (Objects.nonNull(articleDTO) && Objects.nonNull(datastatDTO)) {
|
|
|
double avgReadCount = getAvgReadCount(articleDTO.getAccountId(), articleDTO.getItemIndex());
|
|
|
Integer readCount = datastatDTO.getReadCount();
|
|
|
- score.setScore(readCount / avgReadCount);
|
|
|
+ score.setScore(NormalizationUtils.min(readCount / avgReadCount - 1));
|
|
|
} else {
|
|
|
- score.setScore(0.0);
|
|
|
+ score.setScore(-1.0);
|
|
|
}
|
|
|
score.setStrategy(this);
|
|
|
return score;
|
|
@@ -82,9 +91,7 @@ public class ViewMultiplierStrategy implements ScoreStrategy {
|
|
|
}
|
|
|
|
|
|
private double getAvgReadCount(String ghId, Integer index) {
|
|
|
- String cardJSON = ResourceUtil.readUtf8Str("file/AccountInfo.json");
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(cardJSON);
|
|
|
AvgReadDTO dto = jsonObject.getObject(ghId + "_" + index, AvgReadDTO.class);
|
|
|
- return dto.getReadAvg();
|
|
|
+ return dto == null ? 1.0 : dto.getReadAvg();
|
|
|
}
|
|
|
}
|