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 07/06/2017.
 */
public class Data {


    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"};

            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

            for(int i=0; i < vehicle_array.length; i++) {

                Node data_gps = g.newNode(0, timepoint_array[0]); //the second param is the time
                data_gps.set("longitude", Type.DOUBLE, gps_array_vehicle[i][0]); //set the value of the sensor
                data_gps.set("latitude", Type.DOUBLE, gps_array_vehicle[i][1]); //set the value of the sensor

                Node vehicle = g.newNode(0, timepoint_array[0]); //the second param is the time
                vehicle.set("type", Type.STRING, "vehicle");
                vehicle.set("name", Type.STRING, vehicle_array[i]);

                vehicle.addToRelation("has_gps", data_gps); //add the sensor0 to the relation sensors of room0

                System.out.println(vehicle.toString());
                System.out.println(data_gps.toString());

                data_gps.travelInTime(timepoint_array[i+1], (Node data_gps_Ti) -> {

                    int j=0;
                    data_gps_Ti.set("longitude", Type.DOUBLE, gps_array_vehicle[j][2]);
                    data_gps_Ti.set("latitude", Type.DOUBLE, gps_array_vehicle[j][3]);
                    j=j+1;
                    System.out.println(data_gps_Ti.toString());
                });
            }
        });
    }
}

@@ -891,24 +891,119 @@
 ehicle6%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
             
@@ -1808,17 +1808,29 @@
 NG, 
-%22
+type_
 vehicle
-%22
+_array%5Bi%5D
 );%0A 
@@ -2119,24 +2119,25 @@
 String());%0A%0A
+%0A
             
@@ -2528,33 +2528,572 @@
 %7D);%0A
-            %7D%0A        %7D);
+%0A%0A                g.index(0,0,%22vehicles%22, vehicleIndex -%3E %7B%0A                    vehicleIndex.addToIndex(vehicle, %22type%22);%0A%0A                    vehicleIndex.find(vehicles -%3E %7B%0A                        System.out.println(%22found: %22+vehicles.length+%22 node!%22);%0A                        for (Node vehi : vehicles) %7B%0A                            System.out.println(vehi);%0A                        %7D%0A                    %7D,%22type%22,%22Train%22);%0A                %7D);%0A            %7D%0A        %7D);%0A%0A        g.disconnect(result -%3E %7B%0A            System.out.println(%22Goodbye !%22);%0A        %7D);%0A
 %0A   

Index vehicle by type