package com.tzld.piaoquan.ad.engine.service.predict.model.threshold;

import com.tzld.piaoquan.ad.engine.service.predict.container.RandWContainer;
import com.tzld.piaoquan.ad.engine.service.predict.param.ThresholdPredictModelParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

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

@Component
public class RandomImmersionPredictModel extends ThresholdPredictModel {
    private final static Logger log = LoggerFactory.getLogger(RandomImmersionPredictModel.class);

    @Override
    String initName() {
        return "immersion";
    }


    @Override
    public Map<String, Object> predict(ThresholdPredictModelParam modelParam) {
        int hash=modelParam.getMid().hashCode();
        hash=hash<0?-hash:hash;
        double score=(hash+ RandWContainer.getRandW())%100/100d;
        double threshold=Double.parseDouble(
                modelParam.getExtraParam().getOrDefault(modelParam.getAppType()+"_"+modelParam.getUserExtraFuture("shareType").toString().replace("return","").replace("mids",""),-1
                ).toString());
        if(threshold<0d){
            threshold=Double.parseDouble(
                    modelParam.getExtraParam().getOrDefault("default_threshold","0.5")
                    .toString());
        }
        Map<String, Object> result = new HashMap<>();
        result.put("ad_predict", score<threshold?2:1);
        result.put("score", score);
        result.put("threshold", threshold);
        result.put("model", "immersion");

        return result;
    }

}
