package pmml;

import com.fibo.ddp.common.service.strategyx.aimodel.PMMLExecutor.PMMLExecutor;
import com.fibo.ddp.common.service.strategyx.aimodel.PMMLExecutor.impl.PMMLExecutorRFImpl;
import org.jpmml.evaluator.InputField;
import org.jpmml.evaluator.OutputField;
import org.jpmml.evaluator.TargetField;

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

public class PmmlTest {

    public static void main(String[] args)throws Exception{

        PMMLExecutor pmmlExecutor = new PMMLExecutorRFImpl();
        String file = "/Users/dugang/work/2025/risk/fibo-rule/ddp/ddp-runner-api/src/test/resources/demo001.pmml";
        // 加载模型文件
        org.jpmml.evaluator.Evaluator evaluator = pmmlExecutor.loadPmml(file);


        System.out.println("summary="+ evaluator.getSummary());

        List<InputField> inputFields  = evaluator.getInputFields();
        System.out.println("inputFields.size="+inputFields.size());
        for(InputField item:inputFields){
            System.out.println(item);
        }
        List<InputField> activeFields  = evaluator.getActiveFields();
        System.out.println("activeFields.size="+activeFields.size());
        for(InputField item:activeFields){
            System.out.println(item);
        }

        List<TargetField> targetFields =  evaluator.getTargetFields();
        System.out.println("targetFields.size="+targetFields.size());
        for(TargetField item:targetFields){
            System.out.println(item);
        }
        List<OutputField> outputFields = evaluator.getOutputFields();
        System.out.println("outputFields.size="+outputFields.size());
        for(OutputField item:outputFields){
            System.out.println(item);
        }




        Map<String, Object> input = new HashMap<>();
        input.put("x1",1.0);
        input.put("x2",2.0);

        double modelResult = pmmlExecutor.predict(evaluator, input);

        System.out.println("modelResult="+modelResult);


        input.put("x1","1.0");
        input.put("x2","2.0");
        modelResult = pmmlExecutor.predict(evaluator, input);
        System.out.println("modelResult="+modelResult);

        input.put("x1","1.7");
        input.put("x2","2.1");
        modelResult = pmmlExecutor.predict(evaluator, input);
        System.out.println("modelResult="+modelResult);





    }
}
