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);



            String vehicle_array[] = {"vehicle1", "vehicle2", "vehicle3" , "vehicle4", "vehicle5", "vehicle6"};

            String type_vehicle_array[] = {"Plane", "Car", "Train", "Plane", "Car", "Train"};

            Double gps_array_vehicle[][] = {{0.0, 0.0, 5.0 , 5.0},{1.5, 0.0, 2.0 , 3.0},{0.0, 1.5, 4.0 , 1.0},{5.0, 2.0, 4.5 , 3.0},{3.0, 3.5, 0.0 , 0.0},{1.0, 2.0, 3.0 , 4.5}};

            int timepoint_array[] ={0,1,2,3,4,5,6};  //the timestamp is a long and represents the time concept



            newTask()
                    .loop("0", "5",
                            newTask()
                                    .then(createNode())
                                    .then(travelInTime("0"))
                                    .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"))
                                    //.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}}")))
                    .execute(g, null);

            newTask()
                    .loop("0", "4",
                            newTask()
                                    .then(createNode())
                                    .then(travelInTime("0"))
                                    .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"))
                                    //.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}}")))
                    .execute(g, null);




        });
    }
}
@@ -788,510 +788,8 @@
 ;%0A%0A%0A
-%0A            String vehicle_array%5B%5D = %7B%22vehicle1%22, %22vehicle2%22, %22vehicle3%22 , %22vehicle4%22, %22vehicle5%22, %22vehicle6%22%7D;%0A%0A            String type_vehicle_array%5B%5D = %7B%22Plane%22, %22Car%22, %22Train%22, %22Plane%22, %22Car%22, %22Train%22%7D;%0A%0A            Double gps_array_vehicle%5B%5D%5B%5D = %7B%7B0.0, 0.0, 5.0 , 5.0%7D,%7B1.5, 0.0, 2.0 , 3.0%7D,%7B0.0, 1.5, 4.0 , 1.0%7D,%7B5.0, 2.0, 4.5 , 3.0%7D,%7B3.0, 3.5, 0.0 , 0.0%7D,%7B1.0, 2.0, 3.0 , 4.5%7D%7D;%0A%0A            int timepoint_array%5B%5D =%7B0,1,2,3,4,5,6%7D;  //the timestamp is a long and represents the time concept%0A%0A%0A%0A
     
@@ -797,32 +797,53 @@
        newTask()
+     //add node train
 %0A               
@@ -1005,33 +1005,37 @@
 n(travelInTime(%22
-0
+%7B%7Bi%7D%7D
 %22))%0A            
@@ -1558,24 +1558,88 @@
 , %22Train%22))%0A
+                                    .defineAsVar(%22nodes_train%22)%0A
             
@@ -2217,33 +2217,186 @@
 n(%22%7B%7Bresult%7D%7D%22))
-)
+%0A%0A                                    .then(readVar(%22nodes_train%22))%0A                                    .then(addToGlobalIndex(%22index_vehicle%22,%22type%22)))%0A%0A
 %0A               
@@ -2433,32 +2433,50 @@
        newTask()
+    //add node car
 %0A               
@@ -2646,17 +2646,24 @@
 InTime(%22
-0
+%7B%7B=2*i%7D%7D
 %22))%0A    
@@ -3193,24 +3193,86 @@
 NG, %22Car%22))%0A
+                                    .defineAsVar(%22nodes_car%22)%0A
             
@@ -3786,32 +3786,33 @@
 E, %22%7B%7B=i-2%7D%7D%22))%0A
+%0A
                 
@@ -3863,51 +3863,474 @@
 %7D%22))
-)%0A                    .execute(g, null);%0A%0A%0A
+%0A                                    .then(readVar(%22nodes_car%22))%0A                                    .then(addToGlobalIndex(%22index_vehicle%22,%22type%22)))%0A%0A%0A                    .execute(g, null);%0A%0A            newTask()    //reading index%0A                    .then(travelInTime(%225%22))%0A                    .then(indexNames())%0A                    .then(readGlobalIndex(%22index_vehicle%22))%0A                    .then(println(%22%7B%7Bresult%7D%7D%22))%0A%0A                    .execute(g, null);
 %0A%0A  

Add globalIndex for type vehicle