use of org.spf4j.tsdb2.avro.Aggregation in project spf4j by zolyfarkas.
the class TimeSeriesRecord method accumulate.
/**
* Temporary, until better implementation.
* @param accumulator
* @param r2
*/
@Beta
default void accumulate(final TimeSeriesRecord r2) {
Schema recSchema = getSchema();
Iterator<Schema.Field> it = recSchema.getFields().iterator();
it.next();
put(0, r2.get(0));
while (it.hasNext()) {
Schema.Field nf = it.next();
int pos = nf.pos();
Aggregation agg;
String prop = nf.schema().getProp(AGGREGATION_TYPE_PROP);
if (prop != null) {
agg = Aggregation.valueOf(prop);
} else {
agg = inferAggregationFromName(nf, recSchema);
}
switch(agg) {
case SUM:
put(pos, ((Long) get(pos)) + ((Long) r2.get(pos)));
break;
case MIN:
put(pos, Math.min((Long) get(pos), ((Long) r2.get(pos))));
break;
case MAX:
put(pos, Math.max((Long) get(pos), ((Long) r2.get(pos))));
break;
case FIRST:
break;
case LAST:
case UNKNOWN:
put(pos, ((Long) r2.get(pos)));
break;
default:
throw new UnsupportedOperationException("Unsupported aggregation: " + agg);
}
}
}
use of org.spf4j.tsdb2.avro.Aggregation in project spf4j by zolyfarkas.
the class TimeSeriesRecord method accumulateObservations.
@Beta
static void accumulateObservations(final Schema recSchema, final Observation r1, final Observation r2) {
r1.setRelTimeStamp(r2.getRelTimeStamp());
r1.setTableDefId(-1L);
Iterator<Schema.Field> it = recSchema.getFields().iterator();
it.next();
List<Long> r1d = r1.getData();
List<Long> r2d = r2.getData();
while (it.hasNext()) {
Schema.Field nf = it.next();
int pos = nf.pos();
Aggregation agg;
String prop = nf.schema().getProp(AGGREGATION_TYPE_PROP);
if (prop != null) {
agg = Aggregation.valueOf(prop);
} else {
agg = inferAggregationFromName(nf, recSchema);
}
int apos = pos - 1;
switch(agg) {
case SUM:
r1d.set(apos, r1d.get(apos) + r2d.get(apos));
break;
case MIN:
r1d.set(apos, Math.min(r1d.get(apos), r2d.get(apos)));
break;
case MAX:
r1d.set(apos, Math.max(r1d.get(apos), r2d.get(apos)));
break;
case FIRST:
break;
case LAST:
case UNKNOWN:
r1d.set(apos, r2d.get(apos));
break;
default:
throw new UnsupportedOperationException("Unsupported aggregation: " + agg);
}
}
}
use of org.spf4j.tsdb2.avro.Aggregation in project spf4j by zolyfarkas.
the class RecorderFactory method createDirectRecorder.
public static MultiMeasurementRecorder createDirectRecorder(final Object measuredEntity, final String description, final String[] measurementNames, final String[] measurementUnits) {
Aggregation[] aggs = new Aggregation[measurementNames.length];
Arrays.fill(aggs, Aggregation.UNKNOWN);
DirectStoreMultiAccumulator mr = new DirectStoreMultiAccumulator(new MeasurementsInfoImpl(measuredEntity, description, measurementNames, measurementUnits, aggs, MeasurementType.UNTYPED), MEASUREMENT_STORE);
mr.registerJmx();
return mr;
}
use of org.spf4j.tsdb2.avro.Aggregation in project spf4j by zolyfarkas.
the class RecorderFactory method createDirectRecorder.
public static MultiMeasurementRecorder createDirectRecorder(final Object measuredEntity, final String description, final String[] measurementNames, final String[] measurementUnits, final MeasurementType type) {
Aggregation[] aggs = new Aggregation[measurementNames.length];
Arrays.fill(aggs, Aggregation.UNKNOWN);
DirectStoreMultiAccumulator mr = new DirectStoreMultiAccumulator(new MeasurementsInfoImpl(measuredEntity, description, measurementNames, measurementUnits, aggs, type), MEASUREMENT_STORE);
mr.registerJmx();
return mr;
}
use of org.spf4j.tsdb2.avro.Aggregation in project spf4j by zolyfarkas.
the class TableDefs method from.
public static TableDef from(final MeasurementsInfo measurement, final int sampleTimeMillis, final long id) {
int numberOfMeasurements = measurement.getNumberOfMeasurements();
List<ColumnDef> columns = new ArrayList<>(numberOfMeasurements);
for (int i = 0; i < numberOfMeasurements; i++) {
String mname = measurement.getMeasurementName(i);
String unit = measurement.getMeasurementUnit(i);
Aggregation aggregation = measurement.getMeasurementAggregation(i);
ColumnDef cd = new ColumnDef(mname, Type.LONG, unit, "", aggregation);
columns.add(cd);
}
return new TableDef(id, measurement.getMeasuredEntity().toString(), "", columns, sampleTimeMillis, measurement.getMeasurementType());
}
Aggregations