package examples.dataloader;


import com.aliyun.odps.account.Account;
import com.aliyun.odps.account.AliyunAccount;
import com.aliyun.odps.data.Record;
import com.tzld.piaoquan.recommend.feature.domain.video.base.*;


import java.util.HashMap;
import java.util.Map;

public class RecommendSampleConstructor {

    private static final String BUCKET_NAME = "ali-recommend";
    private static final Map<String, String> ODPS_CONFIG = new HashMap<String, String>();

    static {
        ODPS_CONFIG.put("ENDPOINT", "http://service.cn.maxcompute.aliyun.com/api");
        ODPS_CONFIG.put("ACCESSID", "LTAIWYUujJAm7CbH");
        ODPS_CONFIG.put("ACCESSKEY", "RfSjdiWwED1sGFlsjXv0DlfTnZTG1P");
    }

    ;

    private static final Account account = new AliyunAccount(ODPS_CONFIG.get("ACCESSID"), ODPS_CONFIG.get("ACCESSKEY"));


    public static RequestContext constructRequestContext(Record record) {
        RequestContext requestContext = new RequestContext();
        requestContext.setApptype(record.getString("apptype"));
        requestContext.setMachineinfo_brand(record.getString("machineinfo_brand"));
        requestContext.setMachineinfo_model(record.getString("machineinfo_model"));
        requestContext.setMachineinfo_platform(record.getString("machineinfo_platform"));
        requestContext.setMachineinfo_sdkversion(record.getString("machineinfo_sdkversion"));
        requestContext.setMachineinfo_system(record.getString("machineinfo_system"));
        requestContext.setMachineinfo_wechatversion(record.getString("machineinfo_wechatversion"));
        requestContext.setDay(record.getString("ctx_day"));
        requestContext.setWeek(record.getString("ctx_week"));
        requestContext.setHour(record.getString("ctx_hour"));
        requestContext.setRegion(record.getString("ctx_region"));
        requestContext.setCity(record.getString("ctx_city"));
        return requestContext;
    }


    public static UserFeature constructUserFeature(Record record) {
        UserFeature userFeature = new UserFeature();
        userFeature.setUid(record.get("mid").toString());
        userFeature.setUser_cycle_bucket_7days(record.getString("u_cycle_bucket_7days"));
        userFeature.setUser_cycle_bucket_30days(record.getString("u_cycle_bucket_30days"));
        userFeature.setUser_share_bucket_30days(record.getString("u_share_bucket_30days"));


        // 1day features
        UserActionFeature user1dayActionFeature = new UserActionFeature();
        user1dayActionFeature.setExp_cnt(record.getString("u_1day_exp_cnt"));
        user1dayActionFeature.setClick_cnt(record.getString("u_1day_click_cnt"));
        user1dayActionFeature.setShare_cnt(record.getString("u_1day_share_cnt"));
        user1dayActionFeature.setReturn_cnt(record.getString("u_1day_return_cnt"));
        user1dayActionFeature.setCtr(record.getString("u_ctr_1day"));
        user1dayActionFeature.setStr(record.getString("u_str_1day"));
        user1dayActionFeature.setRov(record.getString("u_rov_1day"));
        user1dayActionFeature.setRos(record.getString("u_ros_1day"));
        userFeature.setDay1_cnt_features(user1dayActionFeature);

        // 3day features
        UserActionFeature user3dayActionFeature = new UserActionFeature();
        user3dayActionFeature.setExp_cnt(record.getString("u_3day_exp_cnt"));
        user3dayActionFeature.setClick_cnt(record.getString("u_3day_click_cnt"));
        user3dayActionFeature.setShare_cnt(record.getString("u_3day_share_cnt"));
        user3dayActionFeature.setReturn_cnt(record.getString("u_3day_return_cnt"));
        user3dayActionFeature.setCtr(record.getString("u_ctr_3day"));
        user3dayActionFeature.setStr(record.getString("u_str_3day"));
        user3dayActionFeature.setRov(record.getString("u_rov_3day"));
        user3dayActionFeature.setRos(record.getString("u_ros_3day"));
        userFeature.setDay3_cnt_features(user3dayActionFeature);

        // 7day features
        UserActionFeature user7dayActionFeature = new UserActionFeature();
        user7dayActionFeature.setExp_cnt(record.getString("u_7day_exp_cnt"));
        user7dayActionFeature.setClick_cnt(record.getString("u_7day_click_cnt"));
        user7dayActionFeature.setShare_cnt(record.getString("u_7day_share_cnt"));
        user7dayActionFeature.setReturn_cnt(record.getString("u_7day_return_cnt"));
        user7dayActionFeature.setCtr(record.getString("u_ctr_7day"));
        user7dayActionFeature.setStr(record.getString("u_str_7day"));
        user7dayActionFeature.setRov(record.getString("u_rov_7day"));
        user7dayActionFeature.setRos(record.getString("u_ros_7day"));
        userFeature.setDay7_cnt_features(user7dayActionFeature);

        // 3month features
        UserActionFeature user3monthActionFeature = new UserActionFeature();
        user3monthActionFeature.setExp_cnt(record.getString("u_3month_exp_cnt"));
        user3monthActionFeature.setClick_cnt(record.getString("u_3month_click_cnt"));
        user3monthActionFeature.setShare_cnt(record.getString("u_3month_share_cnt"));
        user3monthActionFeature.setReturn_cnt(record.getString("u_3month_return_cnt"));
        user3monthActionFeature.setCtr(record.getString("u_ctr_3month"));
        user3monthActionFeature.setStr(record.getString("u_str_3month"));
        user3monthActionFeature.setRov(record.getString("u_rov_3month"));
        user3monthActionFeature.setRos(record.getString("u_ros_3month"));
        userFeature.setMonth3_cnt_features(user3monthActionFeature);

        return userFeature;
    }


    public static ItemFeature constructItemFeature(Record record) {
        ItemFeature itemFeature = new ItemFeature();
        itemFeature.setVideoId(record.getString("videoid"));
        itemFeature.setUpId(record.getString("uid"));
        // itemFeature.setTitleLength(record.getString("i_title_len"));
        itemFeature.setPlayLength(record.getString("i_play_len"));
        itemFeature.setTotalTime(record.getString("total_time"));
        itemFeature.setDaysSinceUpload(record.getString("i_days_since_upload"));

        UserActionFeature user1dayActionFeature = new UserActionFeature();
        user1dayActionFeature.setExp_cnt(record.getString("i_1day_exp_cnt"));
        user1dayActionFeature.setClick_cnt(record.getString("i_1day_click_cnt"));
        user1dayActionFeature.setShare_cnt(record.getString("i_1day_share_cnt"));
        user1dayActionFeature.setReturn_cnt(record.getString("i_1day_return_cnt"));
        user1dayActionFeature.setCtr(record.getString("i_ctr_1day"));
        user1dayActionFeature.setStr(record.getString("i_str_1day"));
        user1dayActionFeature.setRov(record.getString("i_rov_1day"));
        user1dayActionFeature.setRos(record.getString("i_ros_1day"));
        itemFeature.setDay1_cnt_features(user1dayActionFeature);

        UserActionFeature user3dayActionFeature = new UserActionFeature();
        user3dayActionFeature.setExp_cnt(record.getString("i_3day_exp_cnt"));
        user3dayActionFeature.setClick_cnt(record.getString("i_3day_click_cnt"));
        user3dayActionFeature.setShare_cnt(record.getString("i_3day_share_cnt"));
        user3dayActionFeature.setReturn_cnt(record.getString("i_3day_return_cnt"));
        user3dayActionFeature.setCtr(record.getString("i_ctr_3day"));
        user3dayActionFeature.setStr(record.getString("i_str_3day"));
        user3dayActionFeature.setRov(record.getString("i_rov_3day"));
        user3dayActionFeature.setRos(record.getString("i_ros_3day"));
        itemFeature.setDay3_cnt_features(user1dayActionFeature);

        UserActionFeature user7dayActionFeature = new UserActionFeature();
        user7dayActionFeature.setExp_cnt(record.getString("i_7day_exp_cnt"));
        user7dayActionFeature.setClick_cnt(record.getString("i_7day_click_cnt"));
        user7dayActionFeature.setShare_cnt(record.getString("i_7day_share_cnt"));
        user7dayActionFeature.setReturn_cnt(record.getString("i_7day_return_cnt"));
        user7dayActionFeature.setCtr(record.getString("i_ctr_7day"));
        user7dayActionFeature.setStr(record.getString("i_str_7day"));
        user7dayActionFeature.setRov(record.getString("i_rov_7day"));
        user7dayActionFeature.setRos(record.getString("i_ros_7day"));
        itemFeature.setDay7_cnt_features(user1dayActionFeature);

        UserActionFeature user3monthActionFeature = new UserActionFeature();
        user3monthActionFeature.setExp_cnt(record.getString("i_3month_exp_cnt"));
        user3monthActionFeature.setClick_cnt(record.getString("i_3month_click_cnt"));
        user3monthActionFeature.setShare_cnt(record.getString("i_3month_share_cnt"));
        user3monthActionFeature.setReturn_cnt(record.getString("i_3month_return_cnt"));
        user3monthActionFeature.setCtr(record.getString("i_ctr_3month"));
        user3monthActionFeature.setStr(record.getString("i_str_3month"));
        user3monthActionFeature.setRov(record.getString("i_rov_3month"));
        user3monthActionFeature.setRos(record.getString("i_ros_3month"));
        itemFeature.setMonth3_cnt_features(user3monthActionFeature);
        return itemFeature;
    }


}