use of dontweave.gson.JsonArray 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;
}
use of dontweave.gson.JsonArray 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;
}
use of dontweave.gson.JsonArray in project h2o-2 by h2oai.
the class TypeaheadHexKeyRequest method serve.
protected JsonArray serve(String filter, int limit, long timetolerance) {
JsonArray array = new JsonArray();
int len = 0;
// Gather some keys that pass all filters
for (H2O.KeyInfo kinfo : H2O.KeySnapshot.globalSnapshot(2000)._keyInfos) {
if (// Have a filter?
filter != null && kinfo._key.toString().indexOf(filter) == -1)
// Ignore this filtered-out key
continue;
// Wrong type?
if (!matchesType(kinfo))
continue;
// Generic override
if (!shouldIncludeKey(kinfo))
continue;
array.add(new JsonPrimitive(kinfo._key.toString()));
if (array.size() == limit)
break;
}
return array;
}
use of dontweave.gson.JsonArray in project h2o-2 by h2oai.
the class TypeaheadS3BucketRequest method serve.
@Override
protected JsonArray serve(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;
}
use of dontweave.gson.JsonArray in project h2o-2 by h2oai.
the class SpeeDRFModel method buildCM.
public void buildCM(StringBuilder sb) {
int tasks = this.N;
int finished = this.size();
int modelSize = tasks * 25 / 100;
modelSize = modelSize == 0 || finished == tasks ? finished : modelSize * (finished / modelSize);
if (confusion != null && confusion.valid() && modelSize > 0) {
//finished += 1;
JsonObject cm = new JsonObject();
JsonArray cmHeader = new JsonArray();
JsonArray matrix = new JsonArray();
cm.addProperty(JSON_CM_TYPE, oobee ? "OOB" : "training");
cm.addProperty(JSON_CM_CLASS_ERR, confusion.classError());
cm.addProperty(JSON_CM_ROWS_SKIPPED, confusion.skippedRows());
cm.addProperty(JSON_CM_ROWS, confusion.rows());
// create the header
for (String s : cfDomain(confusion, 1024)) cmHeader.add(new JsonPrimitive(s));
cm.add(JSON_CM_HEADER, cmHeader);
// add the matrix
final int nclasses = confusion.dimension();
JsonArray classErrors = new JsonArray();
for (int crow = 0; crow < nclasses; ++crow) {
JsonArray row = new JsonArray();
int classHitScore = 0;
for (int ccol = 0; ccol < nclasses; ++ccol) {
row.add(new JsonPrimitive(confusion.matrix(crow, ccol)));
if (crow != ccol)
classHitScore += confusion.matrix(crow, ccol);
}
// produce infinity members in case of 0.f/0
classErrors.add(new JsonPrimitive((float) classHitScore / (classHitScore + confusion.matrix(crow, crow))));
matrix.add(row);
}
cm.add(JSON_CM_CLASSES_ERRORS, classErrors);
cm.add(JSON_CM_MATRIX, matrix);
cm.addProperty(JSON_CM_TREES, modelSize);
// Signal end only and only if all trees were generated and confusion matrix is valid
DocGen.HTML.section(sb, "Confusion Matrix:");
if (cm.has(JSON_CM_MATRIX)) {
sb.append("<dl class='dl-horizontal'>");
sb.append("<dt>classification error</dt><dd>").append(String.format("%5.5f %%", 100 * cm.get(JSON_CM_CLASS_ERR).getAsFloat())).append("</dd>");
long rows = cm.get(JSON_CM_ROWS).getAsLong();
long skippedRows = cm.get(JSON_CM_ROWS_SKIPPED).getAsLong();
sb.append("<dt>used / skipped rows </dt><dd>").append(String.format("%d / %d (%3.1f %%)", rows, skippedRows, (double) skippedRows * 100 / (skippedRows + rows))).append("</dd>");
sb.append("<dt>trees used</dt><dd>").append(cm.get(JSON_CM_TREES).getAsInt()).append("</dd>");
sb.append("</dl>");
sb.append("<table class='table table-striped table-bordered table-condensed'>");
sb.append("<tr style='min-width: 60px;'><th style='min-width: 60px;'>Actual \\ Predicted</th>");
JsonArray header = (JsonArray) cm.get(JSON_CM_HEADER);
for (JsonElement e : header) sb.append("<th style='min-width: 60px;'>").append(e.getAsString()).append("</th>");
sb.append("<th style='min-width: 60px;'>Error</th></tr>");
int classes = header.size();
long[] totals = new long[classes];
JsonArray matrix2 = (JsonArray) cm.get(JSON_CM_MATRIX);
long sumTotal = 0;
long sumError = 0;
for (int crow = 0; crow < classes; ++crow) {
JsonArray row = (JsonArray) matrix2.get(crow);
long total = 0;
long error = 0;
sb.append("<tr style='min-width: 60px;'><th style='min-width: 60px;'>").append(header.get(crow).getAsString()).append("</th>");
for (int ccol = 0; ccol < classes; ++ccol) {
long num = row.get(ccol).getAsLong();
total += num;
totals[ccol] += num;
if (ccol == crow) {
sb.append("<td style='background-color:LightGreen; min-width: 60px;'>");
} else {
sb.append("<td styile='min-width: 60px;'>");
error += num;
}
sb.append(num);
sb.append("</td>");
}
sb.append("<td style='min-width: 60px;'>");
sb.append(String.format("%.05f = %,d / %d", (double) error / total, error, total));
sb.append("</td></tr>");
sumTotal += total;
sumError += error;
}
sb.append("<tr style='min-width: 60px;'><th style='min-width: 60px;'>Totals</th>");
for (long total : totals) sb.append("<td style='min-width: 60px;'>").append(total).append("</td>");
sb.append("<td style='min-width: 60px;'><b>");
sb.append(String.format("%.05f = %,d / %d", (double) sumError / sumTotal, sumError, sumTotal));
sb.append("</b></td></tr>");
sb.append("</table>");
} else {
sb.append("<div class='alert alert-info'>");
sb.append("Confusion matrix is being computed into the key:</br>");
sb.append(cm.get(JSON_CONFUSION_KEY).getAsString());
sb.append("</div>");
}
}
}
Aggregations