public class JsonTuples
extends java.lang.Object
The Json Tuple sensor "samples" have a standard collection of properties.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
KEY_AGG_BEGIN_TS |
static java.lang.String |
KEY_AGG_COUNT |
static java.lang.String |
KEY_ID |
static java.lang.String |
KEY_READING |
static java.lang.String |
KEY_TS |
Constructor and Description |
---|
JsonTuples() |
Modifier and Type | Method and Description |
---|---|
static com.google.gson.JsonElement |
getStatistic(com.google.gson.JsonObject jo,
Statistic stat)
Get a statistic value from a sample.
|
static com.google.gson.JsonElement |
getStatistic(com.google.gson.JsonObject jo,
java.lang.String valueKey,
Statistic stat)
Get a statistic value from a sample.
|
static Function<com.google.gson.JsonObject,java.lang.String> |
keyFn()
The partition key function for wrapped sensor samples.
|
static BiFunction<java.util.List<com.google.gson.JsonObject>,java.lang.String,com.google.gson.JsonObject> |
statistics(Statistic... statistics)
Create a function that computes the specified statistics on the list of
samples and returns a new sample containing the result.
|
static <T> com.google.gson.JsonObject |
wrap(org.apache.commons.math3.util.Pair<java.lang.Long,T> sample,
java.lang.String id)
Create a JsonObject wrapping a raw
Pair<Long msec,T reading>> sample. |
static <T> TStream<com.google.gson.JsonObject> |
wrap(TStream<org.apache.commons.math3.util.Pair<java.lang.Long,T>> stream,
java.lang.String id)
Create a stream of JsonObject wrapping a stream of
raw
Pair<Long msec,T reading>> samples. |
public static final java.lang.String KEY_ID
public static final java.lang.String KEY_TS
public static final java.lang.String KEY_READING
public static final java.lang.String KEY_AGG_BEGIN_TS
public static final java.lang.String KEY_AGG_COUNT
public static <T> com.google.gson.JsonObject wrap(org.apache.commons.math3.util.Pair<java.lang.Long,T> sample, java.lang.String id)
Pair<Long msec,T reading>>
sample.T
- Tuple typesample
- the raw sampleid
- the sensor's Idpublic static <T> TStream<com.google.gson.JsonObject> wrap(TStream<org.apache.commons.math3.util.Pair<java.lang.Long,T>> stream, java.lang.String id)
Pair<Long msec,T reading>>
samples.T
- Tuple typestream
- the raw input streamid
- the sensor's Idpublic static Function<com.google.gson.JsonObject,java.lang.String> keyFn()
The KEY_ID
property is returned for the key.
public static com.google.gson.JsonElement getStatistic(com.google.gson.JsonObject jo, Statistic stat)
Same as getStatistic(jo, JsonTuples.KEY_READING, stat)
.
jo
- the samplestat
- the Statistic of interestjava.lang.RuntimeException
- of the stat isn't presentpublic static com.google.gson.JsonElement getStatistic(com.google.gson.JsonObject jo, java.lang.String valueKey, Statistic stat)
Convenience for working with samples containing a property
whose value is one or more Statistic
as created by
JsonAnalytics.aggregate()
jo
- the samplevalueKey
- the name of the property containing the JsonObject of Statisticsstat
- the Statistic of interestjava.lang.RuntimeException
- of the stat isn't presentpublic static BiFunction<java.util.List<com.google.gson.JsonObject>,java.lang.String,com.google.gson.JsonObject> statistics(Statistic... statistics)
The single tuple contains the specified statistics computed over
all of the JsonTuple.KEY_READING
values from List<JsonObject>
.
The resulting sample contains the properties:
value=factor
)JsonAnalytics.aggregate()
Sample use:
TStream<JsonObject> s = ...
// reduce s by a factor of 100 with stats MEAN and STDEV
TStream<JsonObject> reduced = s.batch(100, statistics(Statistic.MEAN, Statistic.STDDEV));
statistics
- the statistics to calculate over the windowTStream<JsonObject>
for the reduced stream
Copyright © 2016 The Apache Software Foundation. All Rights Reserved - bbe71fa-20161201-1641