|
@@ -1,14 +1,18 @@
|
|
package com.tzld.piaoquan.recommend.server.service.score4recall.strategy;
|
|
package com.tzld.piaoquan.recommend.server.service.score4recall.strategy;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.tzld.piaoquan.recommend.server.service.score.ScorerConfigInfo;
|
|
import com.tzld.piaoquan.recommend.server.service.score.ScorerConfigInfo;
|
|
import com.tzld.piaoquan.recommend.server.service.score4recall.AbstractScorer4Recall;
|
|
import com.tzld.piaoquan.recommend.server.service.score4recall.AbstractScorer4Recall;
|
|
import com.tzld.piaoquan.recommend.server.service.score4recall.model4recall.Model4RecallKeyValue;
|
|
import com.tzld.piaoquan.recommend.server.service.score4recall.model4recall.Model4RecallKeyValue;
|
|
|
|
+import com.tzld.piaoquan.recommend.server.util.ListMerger;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -32,74 +36,76 @@ public class BlessRecallScore extends AbstractScorer4Recall {
|
|
if (model == null || model.kv == null) {
|
|
if (model == null || model.kv == null) {
|
|
return new ArrayList<>();
|
|
return new ArrayList<>();
|
|
}
|
|
}
|
|
-// LocalDateTime now = LocalDateTime.now();
|
|
|
|
-// // 节日祝福-每年
|
|
|
|
-// List<Pair<Long, Double>> yearResult = new ArrayList<>();
|
|
|
|
-// String yearlyFestivalTimeRange = params.get("yearly_festival_time_range");
|
|
|
|
-// if (StringUtils.isBlank(yearlyFestivalTimeRange)) {
|
|
|
|
-// return new ArrayList<>();
|
|
|
|
-// }
|
|
|
|
-// JSONObject jsonObject = JSONObject.parseObject(yearlyFestivalTimeRange);
|
|
|
|
-// for (String festival : jsonObject.keySet()) {
|
|
|
|
-// try {
|
|
|
|
-// JSONArray jsonArray = jsonObject.getJSONArray(festival);
|
|
|
|
-// if (jsonArray == null) {
|
|
|
|
-// continue;
|
|
|
|
-// }
|
|
|
|
-// // if (isFestivalTime(now, timeRangeList)) {
|
|
|
|
-//// Pair<LocalDateTime, LocalDateTime> startTimeAndEndTime = getStartTimeAndEndTime(timeRangeList.get(0));
|
|
|
|
-//// if (startTimeAndEndTime == null) {
|
|
|
|
-//// continue;
|
|
|
|
-//// }
|
|
|
|
-// // 节日峰值设置为结束时间的当天的7点
|
|
|
|
-//// double weight = DynamicGaussianFunction.calculateValue(LocalDateTime.now(), startTimeAndEndTime.getLeft(),
|
|
|
|
-//// startTimeAndEndTime.getRight(), startTimeAndEndTime.getRight().withHour(7));
|
|
|
|
-// List<Pair<Long, Double>> festivalLists = model.kv.getOrDefault(festival, new ArrayList<>());
|
|
|
|
-// if (festivalLists.isEmpty()) {
|
|
|
|
-// continue;
|
|
|
|
-// }
|
|
|
|
-// festivalLists = festivalLists.stream().map(pair -> Pair.of(pair.getLeft(), 0.0))
|
|
|
|
-// .limit(Math.min(200, festivalLists.size()))
|
|
|
|
-// .collect(Collectors.toList());
|
|
|
|
-// yearResult.addAll(festivalLists);
|
|
|
|
-//// }
|
|
|
|
-// } catch (Exception e) {
|
|
|
|
-// e.printStackTrace();
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// List<Pair<Long, Double>> dayResult = new ArrayList<>();
|
|
|
|
-// // 每日祝福-每天固定时间段
|
|
|
|
-// String dailyFestivalTimeRange = params.get("daily_bless_time_range");
|
|
|
|
-// if (StringUtils.isBlank(dailyFestivalTimeRange)) {
|
|
|
|
-// return new ArrayList<>();
|
|
|
|
-// }
|
|
|
|
-// JSONObject dailyFestivalTimeRangeJson = JSONObject.parseObject(dailyFestivalTimeRange);
|
|
|
|
-// for (String bless : dailyFestivalTimeRangeJson.keySet()) {
|
|
|
|
-// try {
|
|
|
|
-// String timeRange = dailyFestivalTimeRangeJson.getString(bless);
|
|
|
|
-// if (isFestivalTime(now, Collections.singletonList(timeRange))) {
|
|
|
|
-// List<Pair<Long, Double>> festivalLists = model.kv.getOrDefault(bless, new ArrayList<>());
|
|
|
|
-// if (festivalLists.isEmpty()) {
|
|
|
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
|
+ // 节日祝福-每年
|
|
|
|
+ List<Pair<Long, Double>> yearResult = new ArrayList<>();
|
|
|
|
+ String yearlyFestivalTimeRange = params.get("yearly_festival_time_range");
|
|
|
|
+ if (StringUtils.isBlank(yearlyFestivalTimeRange)) {
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
+ }
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(yearlyFestivalTimeRange);
|
|
|
|
+ for (String festival : jsonObject.keySet()) {
|
|
|
|
+ try {
|
|
|
|
+ JSONArray jsonArray = jsonObject.getJSONArray(festival);
|
|
|
|
+ if (jsonArray == null) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ List<String> timeRangeList = jsonArray.toJavaList(String.class);
|
|
|
|
+ if (isFestivalTime(now, timeRangeList)) {
|
|
|
|
+// Pair<LocalDateTime, LocalDateTime> startTimeAndEndTime = getStartTimeAndEndTime(timeRangeList.get(0));
|
|
|
|
+// if (startTimeAndEndTime == null) {
|
|
// continue;
|
|
// continue;
|
|
// }
|
|
// }
|
|
-// festivalLists = festivalLists.stream().map(pair -> Pair.of(pair.getLeft(), 0.0))
|
|
|
|
-// .limit(Math.min(50, festivalLists.size()))
|
|
|
|
-// .collect(Collectors.toList());
|
|
|
|
-// dayResult.addAll(festivalLists);
|
|
|
|
-// }
|
|
|
|
-// } catch (Exception e) {
|
|
|
|
-// e.printStackTrace();
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
|
|
+ // 节日峰值设置为结束时间的当天的7点
|
|
|
|
+// double weight = DynamicGaussianFunction.calculateValue(LocalDateTime.now(), startTimeAndEndTime.getLeft(),
|
|
|
|
+// startTimeAndEndTime.getRight(), startTimeAndEndTime.getRight().withHour(7));
|
|
|
|
+ List<Pair<Long, Double>> festivalLists = model.kv.getOrDefault(festival, new ArrayList<>());
|
|
|
|
+ if (festivalLists.isEmpty()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ festivalLists = festivalLists.stream().map(pair -> Pair.of(pair.getLeft(), 0.0))
|
|
|
|
+ .limit(Math.min(200, festivalLists.size()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ yearResult.addAll(festivalLists);
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ List<Pair<Long, Double>> dayResult = new ArrayList<>();
|
|
|
|
+ // 每日祝福-每天固定时间段
|
|
|
|
+ String dailyFestivalTimeRange = params.get("daily_bless_time_range");
|
|
|
|
+ if (StringUtils.isBlank(dailyFestivalTimeRange)) {
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
+ }
|
|
|
|
+ JSONObject dailyFestivalTimeRangeJson = JSONObject.parseObject(dailyFestivalTimeRange);
|
|
|
|
+ for (String bless : dailyFestivalTimeRangeJson.keySet()) {
|
|
|
|
+ try {
|
|
|
|
+ String timeRange = dailyFestivalTimeRangeJson.getString(bless);
|
|
|
|
+ if (isFestivalTime(now, Collections.singletonList(timeRange))) {
|
|
|
|
+ List<Pair<Long, Double>> festivalLists = model.kv.getOrDefault(bless, new ArrayList<>());
|
|
|
|
+ if (festivalLists.isEmpty()) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ festivalLists = festivalLists.stream().map(pair -> Pair.of(pair.getLeft(), 0.0))
|
|
|
|
+ .limit(Math.min(200, festivalLists.size()))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ dayResult.addAll(festivalLists);
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
// 常规祝福类的小程序-任意时间
|
|
// 常规祝福类的小程序-任意时间
|
|
List<Pair<Long, Double>> anyResult = new ArrayList<>();
|
|
List<Pair<Long, Double>> anyResult = new ArrayList<>();
|
|
List<Pair<Long, Double>> festivalLists = model.kv.getOrDefault("祝福", new ArrayList<>());
|
|
List<Pair<Long, Double>> festivalLists = model.kv.getOrDefault("祝福", new ArrayList<>());
|
|
if (!festivalLists.isEmpty()) {
|
|
if (!festivalLists.isEmpty()) {
|
|
- festivalLists = festivalLists.stream().map(pair -> Pair.of(pair.getLeft(), 0.0))
|
|
|
|
|
|
+ festivalLists = festivalLists.stream().map(pair -> Pair.of(pair.getLeft(), 0.2))
|
|
|
|
+ .limit(Math.min(200, festivalLists.size()))
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
anyResult.addAll(festivalLists);
|
|
anyResult.addAll(festivalLists);
|
|
}
|
|
}
|
|
- return anyResult;
|
|
|
|
|
|
+ return ListMerger.mergeLists(yearResult, dayResult, anyResult);
|
|
}
|
|
}
|
|
|
|
|
|
public Pair<LocalDateTime, LocalDateTime> getStartTimeAndEndTime(String timeRangeList) {
|
|
public Pair<LocalDateTime, LocalDateTime> getStartTimeAndEndTime(String timeRangeList) {
|