Search in sources :

Example 1 with JsonPrimitive

use of dontweave.gson.JsonPrimitive in project h2o-2 by h2oai.

the class TypeaheadFileRequest method serveHdfs.

protected JsonArray serveHdfs(String filter, int limit) {
    JsonArray array = new JsonArray();
    Configuration conf = PersistHdfs.CONF;
    if (conf == null)
        return array;
    try {
        Path p = new Path(filter);
        Path expand = p;
        if (!filter.endsWith("/"))
            expand = p.getParent();
        FileSystem fs = FileSystem.get(p.toUri(), conf);
        for (FileStatus file : fs.listStatus(expand)) {
            Path fp = file.getPath();
            if (fp.toString().startsWith(p.toString())) {
                array.add(new JsonPrimitive(fp.toString()));
            }
            if (array.size() == limit)
                break;
        }
    } catch (Throwable xe) {
    }
    return array;
}
Also used : JsonArray(dontweave.gson.JsonArray) Configuration(org.apache.hadoop.conf.Configuration) JsonPrimitive(dontweave.gson.JsonPrimitive)

Example 2 with JsonPrimitive

use of dontweave.gson.JsonPrimitive in project h2o-2 by h2oai.

the class TypeaheadHdfsPathRequest method serve.

@Override
protected JsonArray serve(String filter, int limit) {
    JsonArray array = new JsonArray();
    Configuration conf = PersistHdfs.CONF;
    if (conf == null)
        return array;
    try {
        Path p = new Path(filter);
        Path expand = p;
        if (!filter.endsWith("/"))
            expand = p.getParent();
        FileSystem fs = FileSystem.get(p.toUri(), conf);
        for (FileStatus file : fs.listStatus(expand)) {
            Path fp = file.getPath();
            if (fp.toString().startsWith(p.toString())) {
                array.add(new JsonPrimitive(fp.toString()));
            }
            if (array.size() == limit)
                break;
        }
    } catch (Throwable xe) {
    }
    return array;
}
Also used : JsonArray(dontweave.gson.JsonArray) Configuration(org.apache.hadoop.conf.Configuration) JsonPrimitive(dontweave.gson.JsonPrimitive)

Example 3 with JsonPrimitive

use of dontweave.gson.JsonPrimitive in project h2o-2 by h2oai.

the class ConfusionMatrix method toJson.

public JsonArray toJson() {
    JsonArray res = new JsonArray();
    JsonArray header = new JsonArray();
    header.add(new JsonPrimitive("Actual / Predicted"));
    for (int i = 0; i < _arr.length; ++i) header.add(new JsonPrimitive("class " + i));
    header.add(new JsonPrimitive("Error"));
    res.add(header);
    for (int i = 0; i < _arr.length; ++i) {
        JsonArray row = new JsonArray();
        row.add(new JsonPrimitive("class " + i));
        long s = 0;
        for (int j = 0; j < _arr.length; ++j) {
            s += _arr[i][j];
            row.add(new JsonPrimitive(_arr[i][j]));
        }
        double err = s - _arr[i][i];
        err /= s;
        row.add(new JsonPrimitive(err));
        res.add(row);
    }
    JsonArray totals = new JsonArray();
    totals.add(new JsonPrimitive("Totals"));
    long S = 0;
    long DS = 0;
    for (int i = 0; i < _arr.length; ++i) {
        long s = 0;
        for (int j = 0; j < _arr.length; ++j) s += _arr[j][i];
        totals.add(new JsonPrimitive(s));
        S += s;
        DS += _arr[i][i];
    }
    double err = (S - DS) / (double) S;
    totals.add(new JsonPrimitive(err));
    res.add(totals);
    return res;
}
Also used : JsonArray(dontweave.gson.JsonArray) JsonPrimitive(dontweave.gson.JsonPrimitive)

Example 4 with JsonPrimitive

use of dontweave.gson.JsonPrimitive in project h2o-2 by h2oai.

the class TypeaheadFileRequest method serveS3.

protected JsonArray serveS3(String filter, int limit) {
    JsonArray array = new JsonArray();
    try {
        AmazonS3 s3 = PersistS3.getClient();
        filter = Strings.nullToEmpty(filter);
        for (Bucket b : s3.listBuckets()) {
            if (b.getName().startsWith(filter))
                array.add(new JsonPrimitive(b.getName()));
            if (array.size() == limit)
                break;
        }
    } catch (IllegalArgumentException xe) {
    }
    return array;
}
Also used : JsonArray(dontweave.gson.JsonArray) AmazonS3(com.amazonaws.services.s3.AmazonS3) Bucket(com.amazonaws.services.s3.model.Bucket) JsonPrimitive(dontweave.gson.JsonPrimitive)

Example 5 with JsonPrimitive

use of dontweave.gson.JsonPrimitive in project h2o-2 by h2oai.

the class TypeaheadFileRequest method serveFile.

protected JsonArray serveFile(String filter, int limit) {
    File base = null;
    String filterPrefix = "";
    if (!filter.isEmpty()) {
        File file = new File(filter);
        if (file.isDirectory()) {
            base = file;
        } else {
            base = file.getParentFile();
            filterPrefix = file.getName().toLowerCase();
        }
    }
    if (base == null)
        base = new File(".");
    JsonArray array = new JsonArray();
    File[] files = base.listFiles();
    if (files == null)
        return array;
    for (File file : files) {
        if (file.isHidden())
            continue;
        if (file.getName().toLowerCase().startsWith(filterPrefix))
            array.add(new JsonPrimitive(file.getPath()));
        if (array.size() == limit)
            break;
    }
    return array;
}
Also used : JsonArray(dontweave.gson.JsonArray) JsonPrimitive(dontweave.gson.JsonPrimitive) File(java.io.File)

Aggregations

JsonArray (dontweave.gson.JsonArray)8 JsonPrimitive (dontweave.gson.JsonPrimitive)8 AmazonS3 (com.amazonaws.services.s3.AmazonS3)2 Bucket (com.amazonaws.services.s3.model.Bucket)2 Configuration (org.apache.hadoop.conf.Configuration)2 JsonElement (dontweave.gson.JsonElement)1 JsonObject (dontweave.gson.JsonObject)1 File (java.io.File)1