|
@@ -8,6 +8,7 @@ import com.tzld.piaoquan.recommend.server.model.MachineInfo;
|
|
|
import com.tzld.piaoquan.recommend.server.remote.FeatureV2RemoteService;
|
|
|
import com.tzld.piaoquan.recommend.server.service.rank.RankParam;
|
|
|
import com.tzld.piaoquan.recommend.server.service.rank.bo.UserShareReturnProfile;
|
|
|
+import com.tzld.piaoquan.recommend.server.util.FeatureUtils;
|
|
|
import com.tzld.piaoquan.recommend.server.util.JSONUtils;
|
|
|
import lombok.Data;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -31,107 +32,6 @@ public class FeatureService {
|
|
|
private static final Set<String> hotSceneSet = new HashSet<>(Arrays.asList("1008", "1007", "1058", "1074", "1010"));
|
|
|
private static final Set<String> hotSceneTypeSet = new HashSet<>(Arrays.asList("1008", "1007"));
|
|
|
|
|
|
- /**
|
|
|
- * @return k1:视频、k2:表、k3:特征、v:特征值
|
|
|
- */
|
|
|
- public Feature getFeature(String mid, List<String> vidList, String appType,
|
|
|
- String province, String headVid) {
|
|
|
-
|
|
|
-
|
|
|
- List<FeatureKeyProto> protos = new ArrayList<>();
|
|
|
-
|
|
|
- for (String vid : vidList) {
|
|
|
- // TODO 补充其他特征
|
|
|
- // vid
|
|
|
- // protos.add(genWithVid("alg_vid_feature_all_exp", vid));
|
|
|
- protos.add(genWithVid("alg_vid_feature_all_exp_v2", vid));
|
|
|
- protos.add(genWithVid("alg_vid_feature_all_share", vid));
|
|
|
- protos.add(genWithVid("alg_vid_feature_all_return", vid));
|
|
|
- // protos.add(genWithVid("alg_vid_feature_exp2share", vid));
|
|
|
- protos.add(genWithVid("alg_vid_feature_exp2share_v2", vid));
|
|
|
- protos.add(genWithVid("alg_vid_feature_share2return", vid));
|
|
|
- // protos.add(genWithVid("alg_vid_feature_feed_noflow_exp", vid));
|
|
|
- protos.add(genWithVid("alg_vid_feature_feed_noflow_exp_v2", vid));
|
|
|
- // protos.add(genWithVid("alg_vid_feature_feed_noflow_root_share", vid));
|
|
|
- protos.add(genWithVid("alg_vid_feature_feed_noflow_root_share_v2", vid));
|
|
|
- // protos.add(genWithVid("alg_vid_feature_feed_noflow_root_return", vid));
|
|
|
- protos.add(genWithVid("alg_vid_feature_feed_noflow_root_return_v2", vid));
|
|
|
- // protos.add(genWithVid("alg_vid_feature_feed_flow_exp", vid));
|
|
|
- protos.add(genWithVid("alg_vid_feature_feed_flow_exp_v2", vid));
|
|
|
- // protos.add(genWithVid("alg_vid_feature_feed_flow_root_share", vid));
|
|
|
- protos.add(genWithVid("alg_vid_feature_feed_flow_root_share_v2", vid));
|
|
|
- // protos.add(genWithVid("alg_vid_feature_feed_flow_root_return", vid));
|
|
|
- protos.add(genWithVid("alg_vid_feature_feed_flow_root_return_v2", vid));
|
|
|
-
|
|
|
- protos.add(genWithVid("alg_vid_feature_basic_info", vid));
|
|
|
- // vid + apptype
|
|
|
-
|
|
|
- // vid + province
|
|
|
- // protos.add(genWithVidAndProvince("alg_vid_feature_feed_province_exp", vid, province));
|
|
|
- protos.add(genWithVidAndProvince("alg_vid_feature_feed_province_exp_v2", vid, province));
|
|
|
- // protos.add(genWithVidAndProvince("alg_vid_feature_feed_province_root_share", vid, province));
|
|
|
- protos.add(genWithVidAndProvince("alg_vid_feature_feed_province_root_share_v2", vid, province));
|
|
|
- // protos.add(genWithVidAndProvince("alg_vid_feature_feed_province_root_return", vid, province));
|
|
|
- protos.add(genWithVidAndProvince("alg_vid_feature_feed_province_root_return_v2", vid, province));
|
|
|
-
|
|
|
- // vid + headvid
|
|
|
- protos.add(genWithVidAndHeadVid("alg_recsys_feature_cf_i2i_new", vid, headVid));
|
|
|
- //protos.add(genWithVidAndHeadVid("alg_recsys_feature_cf_i2i_new_v2", vid, headVid));
|
|
|
- }
|
|
|
-
|
|
|
- // 头部视频的基础信息
|
|
|
- protos.add(genWithVid("alg_vid_feature_basic_info", headVid));
|
|
|
-
|
|
|
- // user
|
|
|
- protos.add(genWithMid("alg_mid_feature_play", mid));
|
|
|
- protos.add(genWithMid("alg_mid_feature_share_and_return", mid));
|
|
|
- protos.add(genWithMid("alg_mid_feature_play_tags", mid));
|
|
|
- protos.add(genWithMid("alg_mid_feature_return_tags", mid));
|
|
|
- protos.add(genWithMid("alg_mid_feature_share_tags", mid));
|
|
|
- // protos.add(genWithMid("alg_mid_feature_feed_exp_share_tags", mid));
|
|
|
- protos.add(genWithMid("alg_mid_feature_feed_exp_share_tags_v2", mid));
|
|
|
- // protos.add(genWithMid("alg_mid_feature_feed_exp_return_tags", mid));
|
|
|
- protos.add(genWithMid("alg_mid_feature_feed_exp_return_tags_v2", mid));
|
|
|
- protos.add(genWithMid("alg_mid_feature_sharecf", mid));
|
|
|
- protos.add(genWithMid("alg_mid_feature_returncf", mid));
|
|
|
-
|
|
|
-
|
|
|
- Map<String, String> result = remoteService.getFeature(protos);
|
|
|
-
|
|
|
- Feature feature = new Feature();
|
|
|
-
|
|
|
- result.entrySet().forEach(e -> {
|
|
|
-
|
|
|
- String[] uk = StringUtils.split(e.getKey(), ":");
|
|
|
- String prefix = uk[0];
|
|
|
- String table = uk[1];
|
|
|
- Map<String, String> colMap = JSONUtils.fromJson(e.getValue(), new TypeToken<Map<String, String>>() {
|
|
|
- }, Collections.emptyMap());
|
|
|
- String featureStr = colMap.get("feature");
|
|
|
-
|
|
|
- switch (prefix) {
|
|
|
- case "v":
|
|
|
- String vid = uk[2];
|
|
|
- Map<String, Map<String, String>> tableFeatureMap = feature.getVideoFeature().getOrDefault(vid, new HashMap<>());
|
|
|
- tableFeatureMap.put(table, JSONUtils.fromJson(featureStr, new TypeToken<Map<String, String>>() {
|
|
|
- }, Collections.emptyMap()));
|
|
|
- feature.getVideoFeature().put(vid, tableFeatureMap);
|
|
|
- break;
|
|
|
- case "u":
|
|
|
- feature.getUserFeature().put(table, JSONUtils.fromJson(featureStr, new TypeToken<Map<String, String>>() {
|
|
|
- }, Collections.emptyMap()));
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
-
|
|
|
-
|
|
|
- return feature;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
public Map<String, Map<String, Map<String, String>>> getVideoBaseInfo(String headVid, List<String> vidList) {
|
|
|
List<FeatureKeyProto> protos = new ArrayList<>();
|
|
|
if (null != headVid && !headVid.isEmpty()) {
|
|
@@ -144,86 +44,9 @@ public class FeatureService {
|
|
|
return feature.getVideoFeature();
|
|
|
}
|
|
|
|
|
|
- public Feature getNewFeature(String province, String mid, String sceneType, String headVid,
|
|
|
- Map<String, Map<String, Map<String, String>>> videoBaseInfoMap, List<String> vidList) {
|
|
|
- List<FeatureKeyProto> protos = new ArrayList<>();
|
|
|
- String i2iSceneType = "other";
|
|
|
- if (hotSceneSet.contains(sceneType)) {
|
|
|
- i2iSceneType = sceneType;
|
|
|
- }
|
|
|
- for (String vid : vidList) {
|
|
|
- // ********************* old vid ******************
|
|
|
- protos.add(genWithVid("alg_vid_feature_all_exp_v2", vid));
|
|
|
- protos.add(genWithVid("alg_vid_feature_all_share", vid));
|
|
|
- protos.add(genWithVid("alg_vid_feature_all_return", vid));
|
|
|
- protos.add(genWithVid("alg_vid_feature_exp2share_v2", vid));
|
|
|
- protos.add(genWithVid("alg_vid_feature_share2return", vid));
|
|
|
- protos.add(genWithVid("alg_vid_feature_feed_noflow_exp_v2", vid));
|
|
|
- protos.add(genWithVid("alg_vid_feature_feed_noflow_root_share_v2", vid));
|
|
|
- protos.add(genWithVid("alg_vid_feature_feed_noflow_root_return_v2", vid));
|
|
|
- protos.add(genWithVid("alg_vid_feature_feed_flow_exp_v2", vid));
|
|
|
- protos.add(genWithVid("alg_vid_feature_feed_flow_root_share_v2", vid));
|
|
|
- protos.add(genWithVid("alg_vid_feature_feed_flow_root_return_v2", vid));
|
|
|
-
|
|
|
- // vid + province
|
|
|
- protos.add(genWithVidAndProvince("alg_vid_feature_feed_province_exp_v2", vid, province));
|
|
|
- protos.add(genWithVidAndProvince("alg_vid_feature_feed_province_root_share_v2", vid, province));
|
|
|
- protos.add(genWithVidAndProvince("alg_vid_feature_feed_province_root_return_v2", vid, province));
|
|
|
-
|
|
|
- // headvid + vid
|
|
|
- // protos.add(genWithKeyMap("alg_recsys_feature_cf_i2i_new_v2", vid, ImmutableMap.of("vid_a", headVid, "vid_b", vid)));
|
|
|
-
|
|
|
- // ********************* new vid ******************
|
|
|
- protos.add(genWithKeyMap("alg_vid_feature_day", vid, ImmutableMap.of("vid", vid)));
|
|
|
- protos.add(genWithKeyMap("alg_sence_type_feature", vid, ImmutableMap.of("sence_type", sceneType, "videoid", vid)));
|
|
|
- protos.add(genWithKeyMap("alg_videoid_feature", vid, ImmutableMap.of("videoid", vid)));
|
|
|
- // protos.add(genWithKeyMap("alg_recsys_feature_cf_i2i_scene_rov", vid, ImmutableMap.of("sence_type", i2iSceneType, "vid_a", headVid, "vid_b", vid)));
|
|
|
- // protos.add(genWithKeyMap("alg_recsys_feature_cf_i2i_scene_ros", vid, ImmutableMap.of("sence_type", i2iSceneType, "vid_a", headVid, "vid_b", vid)));
|
|
|
- // protos.add(genWithKeyMap("alg_recsys_feature_weak_cf_i2i_scene_rov", vid, ImmutableMap.of("sence_type", i2iSceneType, "vid_a", headVid, "vid_b", vid)));
|
|
|
- // protos.add(genWithKeyMap("alg_recsys_feature_weak_cf_i2i_scene_ros", vid, ImmutableMap.of("sence_type", i2iSceneType, "vid_a", headVid, "vid_b", vid)));
|
|
|
- if (null != videoBaseInfoMap && videoBaseInfoMap.containsKey(vid)) {
|
|
|
- Map<String, Map<String, String>> videoInfo = videoBaseInfoMap.get(vid);
|
|
|
- if (null != videoInfo && videoInfo.containsKey("alg_vid_feature_basic_info")) {
|
|
|
- Map<String, String> baseInfo = videoInfo.get("alg_vid_feature_basic_info");
|
|
|
- if (null != baseInfo) {
|
|
|
- String cate1 = baseInfo.get("cate1_list");
|
|
|
- if (null != cate1 && !cate1.isEmpty()) {
|
|
|
- protos.add(genWithKeyMap("alg_cate1_feature", vid, ImmutableMap.of("cate1", cate1)));
|
|
|
- protos.add(genWithKeyMap("alg_cate1_feature_day", vid, ImmutableMap.of("cate1", cate1)));
|
|
|
- }
|
|
|
- String cate2 = baseInfo.get("cate2");
|
|
|
- if (null != cate2 && !cate2.isEmpty()) {
|
|
|
- protos.add(genWithKeyMap("alg_cate2_feature", vid, ImmutableMap.of("cate2", cate2)));
|
|
|
- protos.add(genWithKeyMap("alg_cate2_feature_day", vid, ImmutableMap.of("cate2", cate2)));
|
|
|
- }
|
|
|
- String vidSource = baseInfo.get("vid_source");
|
|
|
- if (null != vidSource && !vidSource.isEmpty()) {
|
|
|
- protos.add(genWithKeyMap("alg_vid_source_feature", vid, ImmutableMap.of("vid_source", vidSource)));
|
|
|
- protos.add(genWithKeyMap("alg_video_source_feature_day", vid, ImmutableMap.of("video_source", vidSource)));
|
|
|
- }
|
|
|
- String videoUnionid = baseInfo.get("title_time_w_h_unionid");
|
|
|
- if (null != videoUnionid && !videoUnionid.isEmpty()) {
|
|
|
- protos.add(genWithKeyMap("alg_video_unionid_feature_day", vid, ImmutableMap.of("video_unionid", videoUnionid)));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // user
|
|
|
- protos.add(genWithMid("alg_mid_feature_play", mid));
|
|
|
- protos.add(genWithMid("alg_mid_feature_share_and_return", mid));
|
|
|
- protos.add(genWithMid("alg_mid_feature_play_tags", mid));
|
|
|
- protos.add(genWithMid("alg_mid_feature_return_tags", mid));
|
|
|
- protos.add(genWithMid("alg_mid_feature_share_tags", mid));
|
|
|
- protos.add(genWithMid("alg_mid_feature_feed_exp_share_tags_v2", mid));
|
|
|
- protos.add(genWithMid("alg_mid_feature_feed_exp_return_tags_v2", mid));
|
|
|
- protos.add(genWithMid("alg_mid_feature_sharecf", mid));
|
|
|
- protos.add(genWithMid("alg_mid_feature_returncf", mid));
|
|
|
-
|
|
|
- return getFeatureByProto(protos);
|
|
|
- }
|
|
|
-
|
|
|
+ /**
|
|
|
+ * @return k1:视频、k2:表、k3:特征、v:特征值
|
|
|
+ */
|
|
|
public Feature getFeatureV3(RankParam param, Map<String, Map<String, Map<String, String>>> videoBaseInfoMap, List<String> vidList) {
|
|
|
String mid = param.getMid();
|
|
|
String mergeMid = getMergeMid(param.getUid(), mid);
|
|
@@ -324,6 +147,89 @@ public class FeatureService {
|
|
|
return getFeatureByProto(protos);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @return k1:视频、k2:表、k3:特征、v:特征值
|
|
|
+ */
|
|
|
+ public Feature getFeatureV4(RankParam param, Map<String, String> headInfo, Map<String, Map<String, Map<String, String>>> videoBaseInfoMap, List<String> vidList) {
|
|
|
+ String mid = param.getMid();
|
|
|
+ String mergeMid = getMergeMid(param.getUid(), mid);
|
|
|
+ String headVid = String.valueOf(param.getHeadVid());
|
|
|
+ String province = param.getProvince().replaceAll("省$", "");
|
|
|
+ String apptype = param.getAppType() + "";
|
|
|
+ String orgHotScene = String.valueOf(param.getHotSceneType());
|
|
|
+ String brand = "";
|
|
|
+ if (null != param.getMachineInfo()) {
|
|
|
+ MachineInfo machineInfo = param.getMachineInfo();
|
|
|
+ if (null != machineInfo.getBrand()) {
|
|
|
+ brand = machineInfo.getBrand();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String hotSceneType = orgHotScene;
|
|
|
+ if (!hotSceneTypeSet.contains(hotSceneType)) {
|
|
|
+ hotSceneType = "other";
|
|
|
+ }
|
|
|
+ String senceType = orgHotScene;
|
|
|
+ if (!hotSceneSet.contains(senceType)) {
|
|
|
+ senceType = "other";
|
|
|
+ }
|
|
|
+ String userChannel = "-1";
|
|
|
+ if (null != param.getChannelName() && !param.getChannelName().isEmpty()) {
|
|
|
+ userChannel = param.getChannelName();
|
|
|
+ }
|
|
|
+ String userLayer = "非0层";
|
|
|
+ if (FeatureUtils.firstLevel(param.getUserShareDepth())) {
|
|
|
+ userLayer = "0层";
|
|
|
+ }
|
|
|
+ String unionid = "-1";
|
|
|
+ if (null != headInfo) {
|
|
|
+ unionid = headInfo.getOrDefault("title_time_w_h_unionid", unionid);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<FeatureKeyProto> protos = new ArrayList<>();
|
|
|
+ // vid
|
|
|
+ for (String vid : vidList) {
|
|
|
+ protos.add(genWithKeyMap("alg_recsys_feature_video_clean_stat", vid, ImmutableMap.of("vid", vid)));
|
|
|
+ protos.add(genWithKeyMap("alg_vid_global_feature_20250212", vid, ImmutableMap.of("vid", vid)));
|
|
|
+ protos.add(genWithKeyMap("alg_vid_recommend_exp_feature_20250212", vid, ImmutableMap.of("vid", vid)));
|
|
|
+ protos.add(genWithKeyMap("alg_vid_recommend_flowpool_exp_feature_20250212", vid, ImmutableMap.of("vid", vid)));
|
|
|
+ protos.add(genWithKeyMap("alg_vid_apptype_recommend_exp_feature_20250212", vid, ImmutableMap.of("vid", vid, "apptype", apptype)));
|
|
|
+ protos.add(genWithKeyMap("alg_vid_province_recommend_exp_feature_20250212", vid, ImmutableMap.of("vid", vid, "province", province)));
|
|
|
+ protos.add(genWithKeyMap("alg_vid_brand_recommend_exp_feature_20250212", vid, ImmutableMap.of("vid", vid, "brand", brand)));
|
|
|
+ protos.add(genWithKeyMap("alg_vid_hotsencetype_recommend_exp_feature_20250212", vid, ImmutableMap.of("vid", vid, "hotsencetype", hotSceneType)));
|
|
|
+
|
|
|
+ protos.add(genWithKeyMap("scene_type_vid_cf_feature_20250212", vid, ImmutableMap.of("sence_type", senceType, "vid_a", headVid, "vid_b", vid)));
|
|
|
+ protos.add(genWithKeyMap("vid_click_cf_feature_20250212", vid, ImmutableMap.of("vid_a", headVid, "vid_b", vid)));
|
|
|
+ protos.add(genWithKeyMap("alg_recsys_feature_cf_i2i_v2", vid, ImmutableMap.of("vid_a", headVid, "vid_b", vid)));
|
|
|
+ protos.add(genWithKeyMap("alg_recsys_feature_video_recommend_channel_layer", vid, ImmutableMap.of("channel", userChannel, "layer", userLayer, "vid", vid)));
|
|
|
+ protos.add(genWithKeyMap("alg_recsys_feature_video_recommend_channel_layer_head", vid, ImmutableMap.of("channel", userChannel, "layer", userLayer, "unionid", unionid, "vid", vid)));
|
|
|
+ if (null != videoBaseInfoMap) {
|
|
|
+ Map<String, Map<String, String>> videoInfo = videoBaseInfoMap.getOrDefault(vid, new HashMap<>());
|
|
|
+ Map<String, String> baseInfo = videoInfo.getOrDefault("alg_vid_feature_basic_info", new HashMap<>());
|
|
|
+ String merge_cate1 = baseInfo.getOrDefault("merge_first_level_cate", "unknown").trim();
|
|
|
+ protos.add(genWithKeyMap("alg_merge_cate1_recommend_exp_feature_20250212", vid, ImmutableMap.of("merge_cate1", merge_cate1)));
|
|
|
+
|
|
|
+ String merge_cate2 = baseInfo.getOrDefault("merge_second_level_cate", "unknown").trim();
|
|
|
+ protos.add(genWithKeyMap("alg_merge_cate2_recommend_exp_feature_20250212", vid, ImmutableMap.of("merge_cate2", merge_cate2)));
|
|
|
+
|
|
|
+ String channel = baseInfo.getOrDefault("channel", "unknown").trim();
|
|
|
+ protos.add(genWithKeyMap("alg_channel_recommend_exp_feature_20250212", vid, ImmutableMap.of("channel", channel)));
|
|
|
+
|
|
|
+ String festive = baseInfo.getOrDefault("festive_label2", "unknown").trim();
|
|
|
+ protos.add(genWithKeyMap("alg_festive_recommend_exp_feature_20250212", vid, ImmutableMap.of("festive", festive)));
|
|
|
+
|
|
|
+ String videoUnionid = baseInfo.getOrDefault("title_time_w_h_unionid", "unknown");
|
|
|
+ protos.add(genWithKeyMap("alg_video_unionid_recommend_exp_feature_20250212", vid, ImmutableMap.of("video_unionid", videoUnionid)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // user
|
|
|
+ protos.add(genWithMid("alg_mid_feature_return_tags", mid));
|
|
|
+ protos.add(genWithMid("alg_mid_feature_share_tags", mid));
|
|
|
+ protos.add(genWithMid("mid_global_feature_20250212", mid));
|
|
|
+ protos.add(genWithMid("alg_recsys_feature_user_share_return_stat", mergeMid));
|
|
|
+
|
|
|
+ return getFeatureByProto(protos);
|
|
|
+ }
|
|
|
+
|
|
|
public Feature getFeatureByNewLabel(String appType, String hotSceneType, String province, String brand, String mid, String headVideoId, List<String> vidList, Map<String, Map<String, Map<String, String>>> videoBaseInfoMap) {
|
|
|
|
|
|
List<FeatureKeyProto> protos = new ArrayList<>();
|