in src/main/java/com/google/solutions/df/log/aggregations/common/fraud/detection/PredictTransform.java [273:298]
public void processElement(ProcessContext c) throws IOException {
HttpContent content = new ByteArrayContent(contentType, c.element().getBytes());
HttpRequestFactory requestFactory = httpTransport.createRequestFactory(credential);
HttpRequest request = requestFactory.buildRequest(method.getHttpMethod(), url, content);
String response = request.execute().parseAsString();
JsonArray convertedObject =
json.fromJson(response, JsonObject.class).getAsJsonArray("predictions");
LOG.debug("Response Size {} rows", convertedObject.size());
convertedObject.forEach(
element -> {
JsonObject jo = element.getAsJsonObject();
String transactionId = jo.get("transactionId").getAsJsonArray().get(0).getAsString();
Double logistic = jo.get("logistic").getAsJsonArray().get(0).getAsDouble();
if (logistic >= probability) {
Row row =
Row.withSchema(Util.prerdictonOutputSchema)
.addValues(transactionId, logistic, element.toString())
.build();
LOG.debug("Predict Output {}", row.toString());
numberOfOutliersFound.inc();
c.output(row);
}
});
}