Search in sources :

Example 1 with ChainFunction

use of com.srotya.sidewinder.core.functions.list.ChainFunction in project sidewinder by srotya.

the class TestChainFunction method testTwoFunctions.

@Test
public void testTwoFunctions() throws Exception {
    SeriesOutput series = new SeriesOutput("cpu", "test", Arrays.asList(Tag.newBuilder().setTagKey("t").setTagValue("1").build(), Tag.newBuilder().setTagKey("t").setTagValue("2").build()));
    List<DataPoint> dps = new ArrayList<>();
    long baseTs = 1486617103629L;
    for (int i = 0; i < 4; i++) {
        dps.add(new DataPoint(baseTs + 30_000 * i, 1));
    }
    series.setDataPoints(dps);
    series.setFp(false);
    List<SeriesOutput> seriesList = Arrays.asList(series);
    ChainFunction cf = new ChainFunction();
    WindowedAggregator rwa = new WindowedMean();
    rwa.init(new Object[] { 70, "smean" });
    WindowedAggregator rwa2 = new WindowedMean();
    rwa2.init(new Object[] { 200, "smean" });
    cf.init(new Function[] { rwa, rwa2 });
    List<SeriesOutput> apply = cf.apply(seriesList);
    List<DataPoint> result = apply.get(0).getDataPoints();
    assertEquals(1, result.size());
    assertEquals(1, result.get(0).getLongValue());
}
Also used : DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ChainFunction(com.srotya.sidewinder.core.functions.list.ChainFunction) ArrayList(java.util.ArrayList) WindowedAggregator(com.srotya.sidewinder.core.functions.list.WindowedAggregator) WindowedMean(com.srotya.sidewinder.core.functions.list.BasicWindowedFunctions.WindowedMean) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Example 2 with ChainFunction

use of com.srotya.sidewinder.core.functions.list.ChainFunction in project sidewinder by srotya.

the class TestChainFunction method testSingleFunction.

@Test
public void testSingleFunction() throws Exception {
    SeriesOutput series = new SeriesOutput("cpu", "test", Arrays.asList(Tag.newBuilder().setTagKey("t").setTagValue("1").build(), Tag.newBuilder().setTagKey("t").setTagValue("2").build()));
    List<DataPoint> dps = new ArrayList<>();
    long baseTs = 1486617103629L;
    for (int i = 0; i < 4; i++) {
        dps.add(new DataPoint(baseTs + 30_000 * i, 1));
    }
    series.setDataPoints(dps);
    series.setFp(false);
    List<SeriesOutput> seriesList = Arrays.asList(series);
    ChainFunction cf = new ChainFunction();
    WindowedAggregator rwa = new WindowedMean();
    rwa.init(new Object[] { 70, "smean" });
    cf.init(new Function[] { rwa });
    List<SeriesOutput> apply = cf.apply(seriesList);
    List<DataPoint> result = apply.get(0).getDataPoints();
    assertEquals(2, result.size());
}
Also used : DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ChainFunction(com.srotya.sidewinder.core.functions.list.ChainFunction) ArrayList(java.util.ArrayList) WindowedAggregator(com.srotya.sidewinder.core.functions.list.WindowedAggregator) WindowedMean(com.srotya.sidewinder.core.functions.list.BasicWindowedFunctions.WindowedMean) SeriesOutput(com.srotya.sidewinder.core.storage.SeriesOutput) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Example 3 with ChainFunction

use of com.srotya.sidewinder.core.functions.list.ChainFunction in project sidewinder by srotya.

the class MiscUtils method createFunctionChain.

public static Function createFunctionChain(String[] parts, int startIndex) throws InstantiationException, IllegalAccessException, Exception {
    Function[] arguments = new Function[parts.length - startIndex];
    for (int k = startIndex, p = 0; k < parts.length; k++, p++) {
        String[] args = parts[k].split(",");
        Class<? extends Function> lookupFunction = FunctionTable.get().lookupFunction(args[0]);
        if (lookupFunction == null) {
            throw new BadRequestException("Unknown function:" + args[0]);
        }
        Function instance = (Function) lookupFunction.newInstance();
        if (args.length - 1 < instance.getNumberOfArgs()) {
            throw new BadRequestException("Insufficient arguments for aggregation function, needed:" + instance.getNumberOfArgs() + ", found:" + (args.length - 1));
        }
        Object[] ary = new Object[args.length - 1];
        for (int i = 1; i < args.length; i++) {
            Matcher matcher = NUMBER.matcher(args[i]);
            if (matcher.matches()) {
                if (matcher.group(1) != null) {
                    ary[i - 1] = Double.parseDouble(args[i]);
                } else {
                    ary[i - 1] = Integer.parseInt(args[i]);
                }
            } else {
                ary[i - 1] = args[i];
            }
        }
        instance.init(ary);
        arguments[p] = instance;
    }
    ChainFunction function = new ChainFunction();
    function.init(arguments);
    return function;
}
Also used : ChainFunction(com.srotya.sidewinder.core.functions.list.ChainFunction) Function(com.srotya.sidewinder.core.functions.list.Function) Matcher(java.util.regex.Matcher) ChainFunction(com.srotya.sidewinder.core.functions.list.ChainFunction) BadRequestException(javax.ws.rs.BadRequestException) ByteString(com.srotya.sidewinder.core.storage.ByteString) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Point(com.srotya.sidewinder.core.rpc.Point)

Aggregations

ChainFunction (com.srotya.sidewinder.core.functions.list.ChainFunction)3 DataPoint (com.srotya.sidewinder.core.storage.DataPoint)3 WindowedMean (com.srotya.sidewinder.core.functions.list.BasicWindowedFunctions.WindowedMean)2 WindowedAggregator (com.srotya.sidewinder.core.functions.list.WindowedAggregator)2 SeriesOutput (com.srotya.sidewinder.core.storage.SeriesOutput)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Function (com.srotya.sidewinder.core.functions.list.Function)1 Point (com.srotya.sidewinder.core.rpc.Point)1 ByteString (com.srotya.sidewinder.core.storage.ByteString)1 Matcher (java.util.regex.Matcher)1 BadRequestException (javax.ws.rs.BadRequestException)1