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

import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Model4RecallTomson extends AbstractModel {
    private static final Logger LOGGER = LoggerFactory.getLogger(Model4RecallTomson.class);
    public Map<Long, Pair<Double, Double>> kv;
    public Model4RecallTomson() {
        //配置不同环境的hdfs conf
        this.kv = new HashMap<>();
    }

    @Override
    public boolean loadFromStream(InputStreamReader in) throws IOException {
        BufferedReader input = new BufferedReader(in);
        String line = null;
        while ((line = input.readLine()) != null) {
            String[] items = line.split("\t");
            if (items.length < 12) {
                continue;
            }
            try{
                Long key = Long.valueOf(items[0].trim());
                Double v1 = Double.valueOf(items[1].trim());
                Double v2 = Double.valueOf(items[10].trim());
                Pair<Double, Double> pair = Pair.of(v2, v1); // left是good， right是wrong。
                kv.put(key, pair);
            }catch (Exception e){
                LOGGER.error(String.format("something is wrong with line: %s", line), e);
            }
        }
        input.close();
        in.close();
        return true;
    }


}
