package eu.amidst.dataGeneration;

import eu.amidst.core.datastream.Attributes;
import eu.amidst.core.datastream.DataInstance;
import eu.amidst.core.datastream.DataStream;
import eu.amidst.core.io.DataStreamLoader;

import java.util.concurrent.TimeUnit;

/**
 * The script to generate this data can be found in Dropbox under (as it should not be made public)
 *
 * Created by ana@cs.aau.dk on 03/12/15.
 */
public class GenerateCajaMarLikeData {

    public void testGeneratedDataWithRScript(){
        DataStream<DataInstance> dataIDA = DataStreamLoader.openFromFile(
                "./extensions/uai2016/doc-experiments/dataGenerationForFlink/IDAlikeData/MONTH1.arff");
        Attributes attributes = dataIDA.stream().findFirst().get().getAttributes();
        System.out.println(attributes.toString());
        System.out.println("DEFAULT[0] = "+dataIDA.stream().findFirst().get().getValue(
                attributes.getAttributeByName("DEFAULT")));

        DataStream<DataInstance> dataSCAI = DataStreamLoader.openFromFile(
                "./extensions/uai2016/doc-experiments/dataGenerationForFlink/SCAIlikeData/MONTH2.arff");
        attributes = dataSCAI.stream().findFirst().get().getAttributes();
        System.out.println(attributes.toString());
        System.out.println("AGE[0] = "+dataSCAI.stream().findFirst().get().getValue(
                attributes.getAttributeByName("AGE")));
    }
    public static void main(String[] args) throws Exception{

        GenerateCajaMarLikeData generateCajaMarLikeData = new GenerateCajaMarLikeData();

        /*
         * The 1st parameter is the number of files (per month)
         * The 2nd parameter is the length of the sequence, i.e., # of clients
         */
        Runtime.getRuntime().exec("Rscript ./extensions/uai2016/doc-experiments/dataGenerationForFlink/" +
                "data_generator_IDA.R 3 10");

        Runtime.getRuntime().exec("Rscript ./extensions/uai2016/doc-experiments/dataGenerationForFlink/" +
                "data_generator_SCAI.R 3 10");

        TimeUnit.SECONDS.sleep(5);

        generateCajaMarLikeData.testGeneratedDataWithRScript();


    }
}

@@ -28,16 +28,72 @@
 ation;%0A%0A
+import eu.amidst.core.classifiers.NaiveBayesClassifier;%0A
 import e
@@ -264,16 +264,90 @@
 Loader;%0A
+import eu.amidst.core.models.BayesianNetwork;%0A%0Aimport java.io.IOException;
 %0Aimport 
@@ -570,16 +570,571 @@
 Data %7B%0A%0A
+    public void generateDataFromRScript() throws IOException%7B%0A                /*%0A         * The 1st parameter is the number of files (per month)%0A         * The 2nd parameter is the length of the sequence, i.e., # of clients%0A         */%0A        Runtime.getRuntime().exec(%22Rscript ./extensions/uai2016/doc-experiments/dataGenerationForFlink/%22 +%0A                %22data_generator_IDA.R 3 1000%22);%0A%0A        Runtime.getRuntime().exec(%22Rscript ./extensions/uai2016/doc-experiments/dataGenerationForFlink/%22 +%0A                %22data_generator_SCAI.R 3 1000%22);%0A    %7D%0A%0A
     publ
@@ -2085,174 +2085,127 @@
 ));%0A
+%0A
     
-%7D%0A
     
-public static void main(String%5B%5D args) throws Exception%7B%0A%0A        GenerateCajaMarLikeData generateCajaMarLikeData = new GenerateCajaMarLikeData
+// Learn NB classifier for IDA data%0A%0A        NaiveBayesClassifier model = new NaiveBayesClassifier
 ();%0A
-%0A
         
 /*%0A 
@@ -2204,328 +2204,602 @@
     
-/*%0A         * The 1st parameter is the number of files (per month)%0A         * The 2nd parameter is the length of the sequence, i.e., # of clients%0A         */%0A        Runtime.getRuntime().exec(%22Rscript ./extensions/uai2016/doc-experiments/dataGenerationForFlink/%22 +%0A                %22data_generator_IDA.R 3 10%22
+model.setClassName(%22DEFAULT%22);%0A        model.setParallelMode(true);%0A        model.learn(dataIDA, 1000);%0A        BayesianNetwork nbClassifierIDA = model.getBNModel();%0A        System.out.println(%22%5CnNB classifier for IDA data learnt succesfully%5Cn%22);%0A        System.out.println(nbClassifierIDA.toString());%0A%0A        System.out.println(%22%5Cn-------------------------------------------%5Cn%22);%0A%0A        // Learn NB classifier for SCAI data%0A%0A        model = new NaiveBayesClassifier();%0A        model.setClassName(%22DEFAULT%22);%0A        model.setParallelMode(true);%0A        model.learn(dataIDA, 1000
 );%0A
-%0A
         
 Runt
@@ -2798,151 +2798,416 @@
     
-Runtime.getRuntime().exec(%22Rscript ./extensions/uai2016/doc-experiments/dataGenerationForFlink/%22 +%0A                %22data_generator_SCAI.R 3 10%22
+BayesianNetwork nbClassifierSCAI = model.getBNModel();%0A        System.out.println(%22%5CnNB classifier for SCAI data learnt succesfully%5Cn%22);%0A        System.out.println(nbClassifierSCAI.toString());%0A    %7D%0A    public static void main(String%5B%5D args) throws Exception%7B%0A%0A        GenerateCajaMarLikeData generateCajaMarLikeData = new GenerateCajaMarLikeData();%0A%0A        generateCajaMarLikeData.generateDataFromRScript(
 );%0A%0A

Test if data is correctly created by learning a NB classifier