Class JsonAnalytics
- java.lang.Object
-
- quarks.analytics.math3.json.JsonAnalytics
-
public class JsonAnalytics extends java.lang.Object
Apache Common Math analytics for streams with JSON tuples.
-
-
Constructor Summary
Constructors Constructor and Description JsonAnalytics()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static <K extends com.google.gson.JsonElement>
TStream<com.google.gson.JsonObject>aggregate(TWindow<com.google.gson.JsonObject,K> window, java.lang.String resultPartitionProperty, java.lang.String valueProperty, JsonUnivariateAggregate... aggregates)
Aggregate against a singleNumeric
variable contained in an JSON object.static <K extends com.google.gson.JsonElement>
TStream<com.google.gson.JsonObject>aggregate(TWindow<com.google.gson.JsonObject,K> window, java.lang.String resultPartitionProperty, java.lang.String resultProperty, ToDoubleFunction<com.google.gson.JsonObject> valueGetter, JsonUnivariateAggregate... aggregates)
Aggregate against a singleNumeric
variable contained in an JSON object.static <K extends com.google.gson.JsonElement>
BiFunction<java.util.List<com.google.gson.JsonObject>,K,com.google.gson.JsonObject>aggregateList(java.lang.String resultPartitionProperty, java.lang.String resultProperty, ToDoubleFunction<com.google.gson.JsonObject> valueGetter, JsonUnivariateAggregate... aggregates)
Create a Function that aggregates against a singleNumeric
variable contained in an JSON object.
-
-
-
Method Detail
-
aggregate
public static <K extends com.google.gson.JsonElement> TStream<com.google.gson.JsonObject> aggregate(TWindow<com.google.gson.JsonObject,K> window, java.lang.String resultPartitionProperty, java.lang.String valueProperty, JsonUnivariateAggregate... aggregates)
Aggregate against a singleNumeric
variable contained in an JSON object. The returned stream contains a tuple for each execution performed against a window partition. The tuple is aJsonObject
containing:- Partition key of type
K
as a property with keyresultPartitionProperty
. - Aggregation results as a
JsonObject
as a property with keyvalueProperty
. This results object contains the results of all aggregations defined byaggregates
againstdouble
property with keyvalueProperty
.
EachJsonUnivariateAggregate
declares how it represents its aggregation in this result object.
For example if the window contains these three tuples (pseudo JSON) for partition 3:
{id=3,reading=2.0}, {id=3,reading=2.6}, {id=3,reading=1.8}
the resulting aggregation for the stream returned by:
aggregate(window, "id", "reading", Statistic.MIN, Statistic.MAX)
would contain this tuple with the maximum and minimum values in thereading
JSON object:
{id=3, reading={MIN=1.8, MAX=1.8}}
- Type Parameters:
K
- Partition type- Parameters:
window
- Window to aggregate over.resultPartitionProperty
- Property to store the partition key in tuples on the returned stream.valueProperty
- JSON property containing the value to aggregate.aggregates
- Which aggregations to be performed.- Returns:
- Stream that will contain aggregations.
- Partition key of type
-
aggregate
public static <K extends com.google.gson.JsonElement> TStream<com.google.gson.JsonObject> aggregate(TWindow<com.google.gson.JsonObject,K> window, java.lang.String resultPartitionProperty, java.lang.String resultProperty, ToDoubleFunction<com.google.gson.JsonObject> valueGetter, JsonUnivariateAggregate... aggregates)
Aggregate against a singleNumeric
variable contained in an JSON object. The returned stream contains a tuple for each execution performed against a window partition. The tuple is aJsonObject
containing:- Partition key of type
K
as a property with keyresultPartitionProperty
. - Aggregation results as a
JsonObject
as a property with keyresultProperty
. This results object contains the results of all aggregations defined byaggregates
against value returned byvalueGetter
.
EachJsonUnivariateAggregate
declares how it represents its aggregation in this result object.
- Type Parameters:
K
- Partition type- Parameters:
window
- Window to aggregate over.resultPartitionProperty
- Property to store the partition key in tuples on the returned stream.resultProperty
- Property to store the aggregations in tuples on the returned stream.valueGetter
- How to obtain the single variable from input tuples.aggregates
- Which aggregations to be performed.- Returns:
- Stream that will contain aggregations.
- Partition key of type
-
aggregateList
public static <K extends com.google.gson.JsonElement> BiFunction<java.util.List<com.google.gson.JsonObject>,K,com.google.gson.JsonObject> aggregateList(java.lang.String resultPartitionProperty, java.lang.String resultProperty, ToDoubleFunction<com.google.gson.JsonObject> valueGetter, JsonUnivariateAggregate... aggregates)
Create a Function that aggregates against a singleNumeric
variable contained in an JSON object. Callingapply(List<JsonObject>)
on the returnedBiFunction
returns aJsonObject
containing:- Partition key of type
K
as a property with keyresultPartitionProperty
. - Aggregation results as a
JsonObject
as a property with keyvalueProperty
. This results object contains the results of all aggregations defined byaggregates
against the value returned byvalueGetter
.
EachJsonUnivariateAggregate
declares how it represents its aggregation in this result object.
For example if the list contains these three tuples (pseudo JSON) for partition 3:
{id=3,reading=2.0}, {id=3,reading=2.6}, {id=3,reading=1.8}
the resulting aggregation for the JsonObject returned by:
aggregateList("id", "reading", Statistic.MIN, Statistic.MAX).apply(list, 3)
would be this tuple with the maximum and minimum values in thereading
JSON object:
{id=3, reading={MIN=1.8, MAX=1.8}}
- Type Parameters:
K
- Partition type- Parameters:
resultPartitionProperty
- Property to store the partition key in tuples on the returned stream.resultProperty
- Property to store the aggregations in the returned JsonObject.valueGetter
- How to obtain the single variable from input tuples.aggregates
- Which aggregations to be performed.- Returns:
- Function that performs the aggregations.
- Partition key of type
-
-