package com.tzld.piaoquan.recommend.server.common.base;

import com.google.common.collect.Maps;
import com.tzld.piaoquan.recommend.feature.domain.video.base.ItemFeature;
import com.tzld.piaoquan.recommend.server.model.Video;
import lombok.Data;

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


@Data
public class RankItem implements Comparable<RankItem> {

    // featureMap中保存所有的特征
    public Map<String, Float> featureMap = new HashMap<>();
    public Map<String, Float> norFeatureMap = new HashMap<>();
    public Map<String, Float> rosFeatureMap = new HashMap<>();
    // 所有特征，包括视频、用户等等
    public Map<String, Float> allFeatureMap = new HashMap<>();
    public Map<String, Double> featureMapDouble = new HashMap<>();
    public Map<String, String> featureMapString = new HashMap<>();
    public String id;
    public Map<String, Double> scoresMap = new HashMap<>();
    public Map<String, String> itemBasicFeature = new HashMap<>();
    public Map<String, Map<String, Double>> itemRealTimeFeature = new HashMap<>();
    public Map<String, Map<String, Double>> itemRealTimeRootFeature = new HashMap<>();
    public long videoId;
    private double score; // 记录最终的score
    private Video video;
    private double scoreRos; // 记录ros的score
    private double scoreStr; // 记录str的score
    private double scoreRov; // 记录rov的score
    private double vovScore; // 记录vov的score

    // 记录Item侧用到的特征
    private ItemFeature itemFeature;

    // 记录召回信息
    private String queue;

    // title
    private String title;

    // 多样性过滤因子
    // 排序因子
    private Map<String, Double> rankItemCategories = Maps.newHashMap();
    private Map<String, Double> rankItemSubCategories = Maps.newHashMap();
    private Map<String, Double> rankItemUserTags = Maps.newHashMap();
    private Map<String, Double> rankItemTitleTags = Maps.newHashMap();


    // 排序侧信息
    private Map<String, Double> rankerScore = Maps.newHashMap();
    private Map<String, Integer> rankerIndex = Maps.newHashMap();


    public RankItem(Video video) {
        this.id = String.valueOf(video.getVideoId());
        this.videoId = video.getVideoId();
        this.score = 0.0;
        this.scoreRos = 0.0;
        this.scoreStr = 0.0;
        this.video = video;
    }

    public RankItem(Long videoId) {
        this.id = videoId.toString();
        this.videoId = videoId;
        this.score = 0.0;
    }

    @Override
    public int compareTo(RankItem o) {
        if (o == null) {
            return -1;
        }
        if (score > o.score) {
            return -1;
        } else if (score < o.score) {
            return 1;
        } else {
            return 0;
        }
    }

}
