package greycat.samples.gps;

import greycat.*;
import greycat.Type;
import greycat.Graph;
import greycat.GraphBuilder;
import greycat.Node;
import greycat.internal.task.math.MathExpressionEngine;
import greycat.internal.task.math.CoreMathExpressionEngine;
import static greycat.Tasks.*;
import static greycat.internal.task.CoreActions.*;

import static greycat.Tasks.newTask;


/**
 * Created by Quentin on 08/06/2017.
 */
public class Data2 {


    public static void main(String[] args) {

        //Create a minimal graph with the default configuration
        Graph g = new GraphBuilder().build();

        //Connect the graph
        g.connect(isConnected -> {
            //Display that the graph database is connected!
            System.out.println("Connected : " + isConnected);


            newTask()     //add node train
                    .loop("0", "5",
                            newTask()
                                    .then(createNode())
                                    .then(travelInTime("{{i}}"))
                                    .then(setAttribute("longitude", Type.DOUBLE, "{{i}}"))
                                    .then(setAttribute("latitude", Type.DOUBLE, "{{i}}"))
                                    .then(println("{{result}}"))
                                    .defineAsVar("data_gps")

                                    .then(createNode())
                                    .then(setAttribute("name", Type.STRING, "TGV_{{i}}"))
                                    .then(setAttribute("type", Type.STRING, "Train"))
                                    .defineAsVar("nodes_train")
                                    //.then(println("{{result}}"))

                                    .then(addVarToRelation("has_gps", "data_gps"))
                                    .then(println("{{result}}"))

                                    .then(readVar("data_gps"))
                                    .then(travelInTime("{{=4*i}}"))
                                    .then(setAttribute("longitude", Type.DOUBLE, "{{=i+2}}"))
                                    .then(setAttribute("latitude", Type.DOUBLE, "{{=i-2}}"))
                                    .then(println("{{result}}"))

                                    .then(readVar("nodes_train"))
                                    .then(addToGlobalIndex("index_vehicle","type")))


                    .execute(g, null);

            newTask()    //add node car
                    .loop("0", "4",
                            newTask()
                                    .then(createNode())
                                    .then(travelInTime("{{=2*i}}"))
                                    .then(setAttribute("longitude", Type.DOUBLE, "{{i}}"))
                                    .then(setAttribute("latitude", Type.DOUBLE, "{{i}}"))
                                    .then(println("{{result}}"))
                                    .defineAsVar("data_gps")

                                    .then(createNode())
                                    .then(setAttribute("name", Type.STRING, "Audi_{{i}}"))
                                    .then(setAttribute("type", Type.STRING, "Car"))
                                    .defineAsVar("nodes_car")
                                    //.then(println("{{result}}"))

                                    .then(addVarToRelation("has_gps", "data_gps"))
                                    .then(println("{{result}}"))

                                    .then(readVar("data_gps"))
                                    .then(travelInTime("{{=3*i}}"))
                                    .then(setAttribute("longitude", Type.DOUBLE, "{{=i+1}}"))
                                    .then(setAttribute("latitude", Type.DOUBLE, "{{=i-2}}"))

                                    .then(println("{{result}}"))
                                    .then(readVar("nodes_car"))
                                    .then(addToGlobalIndex("index_vehicle","type")))


                    .execute(g, null);

            newTask()    //reading index
                    .then(travelInTime("5"))
                    .then(indexNames())
                    .then(readGlobalIndex("index_vehicle"))
                    .then(println("{{result}}"))

                    .execute(g, null);

        });
    }
}
@@ -23,16 +23,72 @@
 s.gps;%0A%0A
+import com.sun.org.apache.bcel.internal.generic.Select;%0A
 import g
@@ -302,24 +302,77 @@
 sionEngine;%0A
+%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 import stati
@@ -2469,32 +2469,33 @@
 %22index_vehicle%22,
+ 
 %22type%22)))%0A%0A%0A    
@@ -4109,16 +4109,17 @@
 ehicle%22,
+ 
 %22type%22))
@@ -4154,32 +4154,84 @@
 cute(g, null);%0A%0A
+%0A            List%3CObject%3E coord = new ArrayList();%0A%0A
             newT
@@ -4397,16 +4397,31 @@
 vehicle%22
+, %22type%22, %22Car%22
 ))%0A     
@@ -4441,72 +4441,758 @@
   .t
-hen(println(%22%7B%7Bresult%7D%7D%22))%0A%0A                    .execute(g, null
+raverse(%22has_gps%22)%0A                    //.traverse(%22has_gps%22,%22latitude%22,%222.0%22)%0A                    //.attribute(%22latitude%22)%0A                    .then(println(%22%7B%7Bresult%7D%7D%22))%0A//                    .execute(g, new Callback%3CTaskResult%3E() %7B%0A//                        @Override%0A//                        public void on(TaskResult taskResult) %7B%0A//                            for (int i = 0; i %3C taskResult.size(); i++) %7B%0A//                                Object coord = taskResult.get(i);%0A//                            %7D%0A//                         %7D%0A//                    %7D);%0A%0A                    .execute(g, null);%0A%0A%0A            System.out.println(coord);%0A%0A            g.disconnect(result -%3E %7B%0A                System.out.println(%22Goodbye !%22);%0A            %7D
 );%0A%0A

Add filter per type and traverse and attribute + Try print in a list the result