Browse Source

finished roi api

gufengshou1 1 year ago
parent
commit
2c524ad15f

+ 7 - 0
ad-engine-server/src/main/java/com/tzld/piaoquan/ad/engine/server/Application.java

@@ -1,12 +1,14 @@
 package com.tzld.piaoquan.ad.engine.server;
 
 import com.ctrip.framework.apollo.spring.annotation.EnableApolloConfig;
+import com.tzld.piaoquan.recommend.feature.client.FeatureClient;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
 import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
 import org.springframework.cloud.openfeign.EnableFeignClients;
+import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.EnableAspectJAutoProxy;
 import org.springframework.scheduling.annotation.EnableScheduling;
@@ -27,4 +29,9 @@ public class Application {
     public static void main(String[] args) {
         SpringApplication.run(Application.class, args);
     }
+
+    @Bean
+    public FeatureClient featureClient() {
+        return new FeatureClient();
+    }
 }

+ 2 - 5
ad-engine-server/src/main/java/com/tzld/piaoquan/ad/engine/server/controller/PredictController.java

@@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import java.util.Map;
+import java.util.*;
 
 @RestController
 @RequestMapping("/predict")
@@ -27,12 +27,9 @@ public class PredictController {
     }
 
 
-    @RequestMapping("/test")
-    public String adPredictByAbTestModel(){
-        return "success"+System.currentTimeMillis();
-    }
     @RequestMapping("/roi/model")
     public Map<String,Object> adPredictByRoiModel(@RequestBody RoiPredictModelRequestParam param){
         return predictModelService.adRecommendPredictByRoiModel(param);
     }
+
 }

+ 3 - 0
ad-engine-server/src/main/resources/application-dev.yml

@@ -6,6 +6,9 @@ eureka:
     serviceUrl:
       defaultZone: http://deveureka-internal.piaoquantv.com/eureka/
 
+datalog: .
+
+
 spring:
   datasource:
     jdbcUrl: jdbc:mysql://rm-bp1k5853td1r25g3n690.mysql.rds.aliyuncs.com:3306/longvideo?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowMultiQueries=true

+ 1 - 2
ad-engine-server/src/main/resources/application.yml

@@ -75,8 +75,7 @@ mybatis:
   configuration:
     log-impl: org.apache.ibatis.logging.slf4j.Slf4jImpl
 
-#datalog: /datalog
-datalog: /Users/gufengshou/Documents/yiqi_project
+datalog: /datalog
 
 logging:
   file:

+ 7 - 0
ad-engine-server/src/main/resources/feeds_score_config_baseline.conf

@@ -0,0 +1,7 @@
+scorer-config = {
+  related-score-config = {
+    scorer-name = "com.tzld.piaoquan.recommend.server.service.score.VlogShareLRScorer"
+    scorer-priority = 99
+    model-path = "model/model_new.txt"
+  }
+}

+ 5 - 1
ad-engine-service/pom.xml

@@ -28,7 +28,11 @@
             <artifactId>protobuf-java</artifactId>
             <version>3.12.0</version>
         </dependency>
-
+        <dependency>
+            <groupId>com.tzld.piaoquan</groupId>
+            <artifactId>recommend-feature-client</artifactId>
+            <version>1.0.0</version>
+        </dependency>
 
     </dependencies>
 </project>

+ 125 - 0
ad-engine-service/src/main/java/com/tzld/piaoquan/ad/engine/service/score/FeatureRemoteService.java

@@ -0,0 +1,125 @@
+//package com.tzld.piaoquan.ad.engine.service.score;
+//
+//import com.tzld.piaoquan.ad.engine.commons.base.AdActionFeature;
+//import com.tzld.piaoquan.ad.engine.commons.base.UserAdFeature;
+//import com.tzld.piaoquan.recommend.feature.client.FeatureClient;
+//import com.tzld.piaoquan.recommend.feature.model.feature.UserActionFeatureProto;
+//import com.tzld.piaoquan.recommend.feature.model.feature.UserFeatureProto;
+//import com.tzld.piaoquan.recommend.feature.model.feature.VideoFeatureProto;
+//import lombok.extern.slf4j.Slf4j;
+//import org.apache.commons.lang.StringUtils;
+//import org.apache.commons.lang.math.NumberUtils;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.stereotype.Component;
+//import org.springframework.util.CollectionUtils;
+//
+//import java.util.Collections;
+//import java.util.List;
+//import java.util.Map;
+//
+//
+///**
+// * @author dyp
+// */
+//@Component
+//@Slf4j
+//public class FeatureRemoteService {
+//
+//    @Autowired
+//    private FeatureClient client;
+//
+//    // 有性能问题再增加localCache
+//    public UserAdFeature getUserFeature(String uid) {
+//        if (StringUtils.isBlank(uid)) {
+//            return null;
+//        }
+//        UserFeatureProto proto = client.getUserFeature(uid);
+//        UserAdFeature adFeature=convert(proto);
+//
+//        return convert(proto);
+//    }
+//
+//    private UserAdFeature convert(UserFeatureProto proto) {
+//        if (proto == null) {
+//            return null;
+//        }
+//        UserAdFeature feature = new UserAdFeature();
+//        //todo
+//        feature.setUser_type(proto.getUid());
+//        if (proto.hasDay1CntFeature()) {
+//            feature.setDay1_cnt_features(convert(proto.getDay1CntFeature()));
+//        }
+//        if (proto.hasDay3CntFeature()) {
+//            feature.setDay3_cnt_features(convert(proto.getDay3CntFeature()));
+//        }
+//        if (proto.hasDay7CntFeature()) {
+//            feature.setDay7_cnt_features(convert(proto.getDay7CntFeature()));
+//        }
+//        if (proto.hasMonth3CntFeature()) {
+//            feature.setMonth3_cnt_features(convert(proto.getMonth3CntFeature()));
+//        }
+//
+//
+//        return feature;
+//    }
+//
+//    private AdActionFeature convert(UserActionFeatureProto proto) {
+//        AdActionFeature feature = new AdActionFeature();
+//        feature.setAdView(proto.get());
+//        feature.setCtr(proto.getCtr());
+//        feature.setExp_cnt(proto.getExpCnt());
+//        feature.setReturn_cnt(proto.getReturnCnt());
+//        feature.setRov(proto.getRov());
+//        feature.setShare_cnt(proto.getShareCnt());
+//        feature.setStr(proto.getStr());
+//        return feature;
+//    }
+//
+//    public ItemFeature getVideoFeature(Long videoId) {
+//        if (videoId == null) {
+//            return null;
+//        }
+//        VideoFeatureProto proto = client.getVideoFeature(videoId);
+//        return convert(proto);
+//    }
+//
+//    public Map<Long, ItemFeature> getVideoFeatureMap(List<Long> videoIds) {
+//        if (CollectionUtils.isEmpty(videoIds)) {
+//            return Collections.emptyMap();
+//        }
+//        List<VideoFeatureProto> protoList = client.getAllVideoFeature(videoIds);
+//        return CommonCollectionUtils.toMap(protoList, p -> NumberUtils.toLong(p.getVideoId(), 0L), this::convert);
+//    }
+//
+//
+//    private ItemFeature convert(VideoFeatureProto proto) {
+//        if (proto == null) {
+//            return null;
+//        }
+//        ItemFeature feature = new ItemFeature();
+//
+//        feature.setPlayLength(proto.getPlayLength());
+//        feature.setTags(proto.getTags());
+//        feature.setTotalTime(proto.getTotalTime());
+//        feature.setUpId(proto.getUpId());
+//        feature.setVideoId(proto.getVideoId());
+//        feature.setDaysSinceUpload(proto.getDaysSinceUpload());
+//
+//
+//        if (proto.hasVideoDay1CntFeature()) {
+//            feature.setDay1_cnt_features(convert(proto.getVideoDay1CntFeature()));
+//        }
+//        if (proto.hasVideoDay3CntFeature()) {
+//            feature.setDay3_cnt_features(convert(proto.getVideoDay3CntFeature()));
+//        }
+//        if (proto.hasVideoDay7CntFeature()) {
+//            feature.setDay7_cnt_features(convert(proto.getVideoDay7CntFeature()));
+//        }
+//        if (proto.hasVideoMonth3CntFeature()) {
+//            feature.setMonth3_cnt_features(convert(proto.getVideoMonth3CntFeature()));
+//        }
+//        return feature;
+//    }
+//
+//
+//}