package com.tzld.piaoquan.recommend.server.implement.candidate;

import com.tzld.piaoquan.recommend.server.framework.candidiate.Candidate;
import com.tzld.piaoquan.recommend.server.framework.candidiate.QueueName;
import com.tzld.piaoquan.recommend.server.framework.common.User;
import com.tzld.piaoquan.recommend.server.framework.merger.IndexCandidateQueue;
import com.tzld.piaoquan.recommend.server.framework.merger.StrategyQueueConfig;
import com.tzld.piaoquan.recommend.server.framework.merger.StrategyQueueInfo;
import com.tzld.piaoquan.recommend.server.gen.recommend.RecommendRequest;

import java.math.BigDecimal;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class Global3hHotCandidate extends IndexCandidateQueue {

    public static final String ItemType = "video";

    public Global3hHotCandidate(StrategyQueueInfo strategyQueueInfo, StrategyQueueConfig strategyQueueConfig) {
        super(strategyQueueInfo, strategyQueueConfig);
    }

    @Override
    public int addCandidateKey(Map<String, Candidate> candidates, int recallNum, User user, RecommendRequest requestData, int requestIndex, int expId) {
        int currRecall = 0;
        Map<String, Candidate> simplifiedCandidates = new ConcurrentHashMap<String, Candidate>();


        BigDecimal recallNumBigDecimal = BigDecimal.valueOf(recallNum);
        int rosNum = recallNumBigDecimal.multiply(BigDecimal.valueOf(0.3)).intValue();
        int rovNum = recallNumBigDecimal.multiply(BigDecimal.valueOf(0.4)).intValue();
        int shortRovNum = recallNumBigDecimal.multiply(BigDecimal.valueOf(0.1)).intValue();
        int strNum = recallNumBigDecimal.multiply(BigDecimal.valueOf(0.2)).intValue();


        QueueName queueName = new QueueName(ItemType, "rov")
                .addMatch("type", "global3h");
        currRecall += addCandidateKey(simplifiedCandidates, queueName, rovNum, getStrategyQueueInfo().getQueueName());

        queueName = new QueueName(ItemType, "short_rov")
                .addMatch("type", "global3h");
        currRecall += addCandidateKey(simplifiedCandidates, queueName, shortRovNum, getStrategyQueueInfo().getQueueName());

        queueName = new QueueName(ItemType, "short_ros")
                .addMatch("type", "global3h");
        currRecall += addCandidateKey(simplifiedCandidates, queueName, rosNum, getStrategyQueueInfo().getQueueName());

        queueName = new QueueName(ItemType, "str")
                .addMatch("type", "global3h");
        currRecall += addCandidateKey(simplifiedCandidates, queueName, strNum, getStrategyQueueInfo().getQueueName());

        candidates.putAll(simplifiedCandidates);
        return currRecall;

    }

    @Override
    public String toString() {
        return "Global24hHotCandidate{" +
                "myCandidates=" + myCandidates +
                ", rankerItemsList=" + rankerItemsList +
                ", children=" + children +
                ", items=" + items +
                '}';
    }
}