quarks.analytics.math3.json

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 single Numeric 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 single Numeric 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 single Numeric variable contained in an JSON object.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JsonAnalytics

        public JsonAnalytics()
    • 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 single Numeric variable contained in an JSON object. The returned stream contains a tuple for each execution performed against a window partition. The tuple is a JsonObject containing:
        • Partition key of type K as a property with key resultPartitionProperty.
        • Aggregation results as a JsonObject as a property with key valueProperty. This results object contains the results of all aggregations defined by aggregates against double property with key valueProperty.
          Each JsonUnivariateAggregate 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 the reading 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.
      • 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 single Numeric variable contained in an JSON object. The returned stream contains a tuple for each execution performed against a window partition. The tuple is a JsonObject containing:
        • Partition key of type K as a property with key resultPartitionProperty.
        • Aggregation results as a JsonObject as a property with key resultProperty. This results object contains the results of all aggregations defined by aggregates against value returned by valueGetter.
          Each JsonUnivariateAggregate 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.
      • 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 single Numeric variable contained in an JSON object. Calling apply(List<JsonObject>) on the returned BiFunction returns a JsonObject containing:
        • Partition key of type K as a property with key resultPartitionProperty.
        • Aggregation results as a JsonObject as a property with key valueProperty. This results object contains the results of all aggregations defined by aggregates against the value returned by valueGetter.
          Each JsonUnivariateAggregate 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 the reading 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.

Copyright IBM 2015,2016 - 2f6ad0e-20160307-0902