package roart.ml;

import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;

import org.jfree.util.Log;

import roart.aggregate.Aggregator;
import roart.indicator.Indicator;
import roart.indicator.IndicatorMACD;
import roart.util.Constants;

public abstract class MLClassifyModel {
    public abstract int getId();
    
    public abstract String getName();
    
    //public abstract int addTitles(Object[] objs, int retindex, String title, String key, String subType, List<Integer> typeList, Map<Integer, String> mapTypes, MLDao dao);
    //@Override
    public int addTitles(Object[] objs, int retindex, Aggregator indicator, String title, String key, String subType, List<Integer> typeList0, Map<Integer, String> mapTypes0, MLClassifyDao dao) {
        List<Integer> typeList = indicator.getTypeList();
        Map<Integer, String> mapTypes = indicator.getMapTypes();
       for (int mapTypeInt : typeList) {
             String mapType = mapTypes.get(mapTypeInt);
            String val = "";
            //String lr = "" + DbSpark.eval("LogisticRegression ", title, "common");
            String lr = "";
            // TODO workaround
            try {
            val = "" + roundme(dao.eval(getId(), key, subType + mapType));
            } catch (Exception e) {
                Log.error("Exception fix later, refactor", e);
            }
            objs[retindex++] = title + Constants.WEBBR +  subType + getName() + mapType +val;
        }
        return retindex;
    }
    
    //public int addResults(Object[] fields, int retindex, String id, Aggregator indicator, Map<Integer, Map<String, Double[]>> commonIdTypeModelHistMap,String subType, List<Integer> typeList0, Map<Integer, String> mapTypes0 ) {
        public int addResults(Object[] fields, int retindex, String id, MLClassifyModel model, Aggregator indicator, Map<String, Map<String, Double[]>> mapResult, Map<Double, String> labelMapShort) {
        List<Integer> typeList = indicator.getTypeList();
        Map<Integer, String> mapTypes = indicator.getMapTypes();
        for (int mapTypeInt : typeList) {
            String mapType = mapTypes.get(mapTypeInt);
            Map<String, Double[]> resultMap1 = mapResult.get(mapType);
            Double[] type = null;
            if (resultMap1 != null) {
                resultMap1.get(id);
            } else {
                System.out.println("map null " + mapType);
            }
            fields[retindex++] = type != null ? labelMapShort.get(type[0]) : null;
        }
        return retindex;
 }

    public static String roundme(Double eval) {
        if (eval == null) {
            return null;
        }
        DecimalFormat df = new DecimalFormat("#.00");
        return df.format(eval);
    }

    public int getSizes(Aggregator indicator) {
        List<Integer> typeList = indicator.getTypeList();
        if (typeList == null) {
            return 0;
        }
        return typeList.size();
    }

    public abstract String getEngineName();

}

@@ -116,16 +116,73 @@
 til.Log;
+%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;
 %0A%0Aimport
@@ -352,16 +352,83 @@
 Model %7B%0A
+    private Logger log = LoggerFactory.getLogger(this.getClass());%0A
     publ
@@ -1424,17 +1424,17 @@
         
-L
+l
 og.error
@@ -2409,32 +2409,32 @@
 Map1 != null) %7B%0A
-
                 
@@ -2432,16 +2432,23 @@
         
+ type =
  resultM

Use proper log. It is good to actually set the var.