package org.mwg.struct;

import org.junit.Test;
import org.mwg.Graph;
import org.mwg.GraphBuilder;
import org.mwg.Type;
import org.mwg.struct.action.NTreeInsertTo;
import org.mwg.struct.action.NTreeNearestN;
import org.mwg.struct.action.NTreeNearestNWithinRadius;
import org.mwg.struct.action.NTreeNearestWithinRadius;
import org.mwg.struct.distance.Distances;
import org.mwg.struct.tree.KDTree;
import org.mwg.task.Task;

import static org.mwg.task.Actions.*;

public class GeoIndexTaskTest {

    @Test
    public void test() {
        Graph g = new GraphBuilder().withMemorySize(100000).withPlugin(new StructPlugin()).build();
        g.connect(result -> {

            Task createGeoIndex = newTypedNode(KDTree.NAME)
                    .setProperty(KDTree.DISTANCE, Type.INT, Distances.GEODISTANCE + "")
                    .setProperty(KDTree.FROM, Type.STRING, "lat,long")
                    .asGlobalVar("geoIndex");

            Task createTenPoints = loop("0", "9", newNode().setProperty("lat", Type.DOUBLE, "1.{{i}}").setProperty("long", Type.DOUBLE, "2.{{i}}").addToGlobalVar("points"));

            newTask()
                    .subTask(createGeoIndex)
                    .subTask(createTenPoints)
                    .fromVar("points")
                    .action(NTreeInsertTo.NAME, "geoIndex")
                    .fromVar("geoIndex")
                    .action(NTreeNearestN.NAME, "1.5,2.5,3")
                    .print("{{result}}")
                    .action(NTreeNearestWithinRadius.NAME, "1.5,2.5,100000")
                    .print("{{result}}")
                    .action(NTreeNearestNWithinRadius.NAME, "1.5,2.5,3,10000000000000")
                    .print("{{result}}")
                    .execute(g, null);


            /*
            newNode()
                    .setProperty("name", Type.STRING, "toIndex")
                    .asVar("toIndex").newTypedNode(KDTree.NAME);
            //.action(KDT)


            NTree kdTree = (NTree) g.newTypedNode(0, 0, KDTree.NAME);
            kdTree.insert(new double[]{0.3, 0.5}, null, insertRes -> {
                System.out.println(insertRes);
            });

            System.out.println(kdTree);
*/


        });

    }

}

@@ -1013,17 +1013,18 @@
 OUBLE, %22
-1
+49
 .%7B%7Bi%7D%7D%22)
@@ -1058,17 +1058,17 @@
 OUBLE, %22
-2
+6
 .%7B%7Bi%7D%7D%22)
@@ -1398,23 +1398,30 @@
 .NAME, %22
-1.5,2.5
+49.6116,6.1319
 ,3%22)%0A   
@@ -1518,23 +1518,30 @@
 .NAME, %22
-1.5,2.5
+49.6116,6.1319
 ,100000%22
@@ -1648,27 +1648,26 @@
 E, %22
-1.5,2.5,3,100000000
+49.6116,6.1319,3,1
 0000
@@ -1750,18 +1750,16 @@
  null);%0A
-%0A%0A
         
@@ -1766,440 +1766,8 @@
     
-/*%0A            newNode()%0A                    .setProperty(%22name%22, Type.STRING, %22toIndex%22)%0A                    .asVar(%22toIndex%22).newTypedNode(KDTree.NAME);%0A            //.action(KDT)%0A%0A%0A            NTree kdTree = (NTree) g.newTypedNode(0, 0, KDTree.NAME);%0A            kdTree.insert(new double%5B%5D%7B0.3, 0.5%7D, null, insertRes -%3E %7B%0A                System.out.println(insertRes);%0A            %7D);%0A%0A            System.out.println(kdTree);%0A*/%0A
 %0A%0A  

add the two new NearestSample, still not working