
package io.sigpipe.sing.adapters;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;

import io.sigpipe.sing.dataset.Metadata;
import io.sigpipe.sing.graph.FeaturePath;
import io.sigpipe.sing.graph.MetadataGraph;
import io.sigpipe.sing.serialization.SerializationInputStream;
import io.sigpipe.sing.serialization.Serializer;

public class ReadMetaBlob {

    public static void main(String[] args) throws Exception {
        File bundle = new File(args[0]);

        System.out.println("Reading metadata blob...");
        FileInputStream fIn = new FileInputStream(bundle);
        BufferedInputStream bIn = new BufferedInputStream(fIn);
        SerializationInputStream in = new SerializationInputStream(bIn);

        int num = in.readInt();
        System.out.println("Records: " + num);

        MetadataGraph mdg = new MetadataGraph();

        for (int i = 0; i < num; ++i) {
            float lat = in.readFloat();
            float lon = in.readFloat();
            byte[] payload = in.readField();

            Metadata m = Serializer.deserialize(Metadata.class, payload);
            FeaturePath<String> path = new FeaturePath<>(
                    "x", m.getAttributes().toArray());
            mdg.addPath(path);
            System.out.print('.');
        }

        in.close();
    }

}

@@ -117,16 +117,42 @@
 tStream;
+%0Aimport java.util.Scanner;
 %0A%0Aimport
@@ -213,25 +213,31 @@
 ing.
-graph.FeaturePath
+dataset.feature.Feature
 ;%0Aim
@@ -263,28 +263,100 @@
 g.graph.
-MetadataGrap
+DataContainer;%0Aimport io.sigpipe.sing.graph.Path;%0Aimport io.sigpipe.sing.graph.Sketc
 h;%0Aimpor
@@ -461,16 +461,105 @@
 ializer;
+%0Aimport io.sigpipe.sing.stat.FeatureSurvey;%0Aimport io.sigpipe.sing.util.PerformanceTimer;
 %0A%0Apublic
@@ -1030,50 +1030,82 @@
     
-MetadataGraph mdg = new MetadataGraph
+Sketch s = new Sketch();%0A%0A        FeatureSurvey fs = new FeatureSurvey
 ();%0A
-%0A
     
@@ -1340,16 +1340,17 @@
 yload);%0A
+%0A
         
@@ -1357,53 +1357,78 @@
     
+for (
 Feature
-Path%3CString%3E path = new FeaturePath%3C%3E(
+ feat : m.getAttributes()) %7B%0A                fs.add(feat);
 %0A   
@@ -1436,24 +1436,27 @@
         
+%7D%0A%0A
         
 %22x%22, m.g
@@ -1451,13 +1451,30 @@
     
-%22x%22, 
+    Path p = new Path(
 m.ge
@@ -1515,71 +1515,746 @@
     
-mdg.addPath(path);%0A            System.out.print('.');%0A        %7D
+//PerformanceTimer pt = new PerformanceTimer(%22go%22);%0A            //pt.start();%0A            s.addPath(p);%0A            //pt.stopAndPrint();%0A            if (i %25 1000 == 0) %7B%0A                System.out.print('.');%0A            %7D%0A        %7D%0A        System.gc();%0A%0A        Scanner scan=new Scanner(System.in);%0A        scan.nextInt();%0A%0A        System.out.println(s.getRoot().numLeaves());%0A        System.out.println(s.getRoot().numDescendants());%0A        System.out.println(s.getRoot().numDescendantEdges());%0A%0A        scan.nextInt();%0A%0A        //fs.printAll();%0A        PerformanceTimer serpt = new PerformanceTimer(%22serialize%22);%0A        serpt.start();%0A        Serializer.persistCompressed(s.getRoot(), %22testvertex.bin%22);%0A        serpt.stopAndPrint();
 %0A%0A  
@@ -2277,11 +2277,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

Add sketch tests (temporary)