package com.tzld.piaoquan.ad.engine.service.predict.container;

import com.tzld.piaoquan.ad.engine.service.predict.model.threshold.ThresholdPredictModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;


import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

@Component
public class ThresholdModelContainer {

    private final static Logger log = LoggerFactory.getLogger(ThresholdModelContainer.class);

    @Autowired
    private ApplicationContext applicationContext;
    @Value("${ad.predict.t-digest.position:0.52}")
    private double position;

    public static Map<String, ThresholdPredictModel> modelMap = new HashMap<>();


    private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);

    @PostConstruct
    public void init() {
        Map<String, ThresholdPredictModel> beanMap = applicationContext.getBeansOfType(ThresholdPredictModel.class);
        beanMap.forEach((s, model) -> {
            modelMap.put(model.getName(), model);
        });

    }

    public static ThresholdPredictModel getThresholdPredictModel(String modelName) {
        return modelMap.getOrDefault(modelName, getBasicPredictModel());
    }

    public static ThresholdPredictModel getBasicPredictModel() {
        return modelMap.get("basic");
    }


}
