package com.tzld.piaoquan.recommend.server.service.score4recall.strategy;

import com.tzld.piaoquan.recommend.server.service.score4recall.AbstractScorer4Recall;
import com.tzld.piaoquan.recommend.server.service.score.ScorerConfigInfo;
import com.tzld.piaoquan.recommend.server.service.score4recall.model4recall.Model4RecallKeyValue;
import org.apache.commons.lang3.tuple.Pair;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;


public class RegionRecallScorerV1 extends AbstractScorer4Recall {

    public RegionRecallScorerV1(ScorerConfigInfo configInfo) {
        super(configInfo);
    }
    @Override
    public void loadModel() {
        doLoadModel(Model4RecallKeyValue.class);
    }

    @Override
    public List<Pair<Long, Double>> recall(Map<String, String> params){
        // todo zhangbo 这里要写实现功能
        Model4RecallKeyValue model = (Model4RecallKeyValue) this.getModel();
        String key = params.getOrDefault("region_province", "中国");
        List<Pair<Long, Double>> lists = model.kv.getOrDefault(key, new ArrayList<>());
        if (lists.isEmpty()){
            lists = model.kv.getOrDefault("中国", new ArrayList<>());
        }
        String sort = params.getOrDefault("sort", "");
        if ("1".equals(sort)){
            lists.sort(Comparator.comparingDouble(o -> -o.getRight()));
        }

        return lists.subList(0, Math.min(400, lists.size()));
    }


}