Search in sources :

Example 6 with FilterDef

use of org.opennms.netmgt.measurements.model.FilterDef in project opennms by OpenNMS.

the class OutlierFilterIT method doesntFailWhenDsOnlyContainsNaNs.

@Test
public void doesntFailWhenDsOnlyContainsNaNs() throws Exception {
    FilterDef filterDef = new FilterDef("Outlier", "inputColumn", "X", "probability", "0.99");
    // Fill with NaNs
    RowSortedTable<Long, String, Double> table = TreeBasedTable.create();
    for (long i = 0; i < 100; i++) {
        table.put(i, "X", Double.NaN);
    }
    // Apply the filter
    getFilterEngine().filter(filterDef, table);
    // No exception should be thrown
    // Now add a single value
    table.put(42L, "X", 3.14);
    // Apply the filter
    getFilterEngine().filter(filterDef, table);
// No exception should be thrown
}
Also used : FilterDef(org.opennms.netmgt.measurements.model.FilterDef) Test(org.junit.Test)

Example 7 with FilterDef

use of org.opennms.netmgt.measurements.model.FilterDef in project opennms by OpenNMS.

the class FilterEngine method filter.

/**
 * Successively applies all of the filters.
 */
public void filter(final List<FilterDef> filterDefinitions, final RowSortedTable<Long, String, Double> table) throws FilterException {
    Preconditions.checkNotNull(filterDefinitions, "filterDefinitions argument");
    Preconditions.checkNotNull(table, "table argument");
    for (FilterDef filterDef : filterDefinitions) {
        Filter filter = getFilter(filterDef);
        if (filter == null) {
            throw new FilterException("No filter implementation found for {}", filterDef.getName());
        }
        try {
            filter.filter(table);
        } catch (Throwable t) {
            throw new FilterException(t, "An error occurred while applying filter {}", t.getMessage());
        }
    }
}
Also used : FilterDef(org.opennms.netmgt.measurements.model.FilterDef) FilterException(org.opennms.netmgt.measurements.api.exceptions.FilterException)

Example 8 with FilterDef

use of org.opennms.netmgt.measurements.model.FilterDef in project opennms by OpenNMS.

the class TrendLineIT method canTrend.

@Test
public void canTrend() throws Exception {
    FilterDef filterDef = new FilterDef("Trend", "outputColumn", "Z", "inputColumn", "Y", "secondsAhead", "1", "polynomialOrder", "5");
    // Use constant values for the Y column
    RowSortedTable<Long, String, Double> table = TreeBasedTable.create();
    for (long i = 0; i < 100; i++) {
        table.put(i, Filter.TIMESTAMP_COLUMN_NAME, (double) (i * 1000));
        table.put(i, "Y", 1.0d);
    }
    // Apply the filter
    getFilterEngine().filter(filterDef, table);
    // The Z column should be constant
    for (long i = 1; i <= 100; i++) {
        Assert.assertEquals((double) i * 1000, table.get(i, Filter.TIMESTAMP_COLUMN_NAME), 0.0001);
        Assert.assertEquals(1.0d, table.get(i, "Z"), 0.0001);
    }
}
Also used : FilterDef(org.opennms.netmgt.measurements.model.FilterDef) Test(org.junit.Test)

Example 9 with FilterDef

use of org.opennms.netmgt.measurements.model.FilterDef in project opennms by OpenNMS.

the class ChompTest method canCutoffRows.

@Test
public void canCutoffRows() throws Exception {
    FilterDef filterDef = new FilterDef("Chomp", "cutoffDate", "60000", "stripNaNs", "false");
    RowSortedTable<Long, String, Double> table = TreeBasedTable.create();
    long k = 0;
    // Add some NaNs to the table
    for (; k < 10; k++) {
        table.put(k, Filter.TIMESTAMP_COLUMN_NAME, (double) k * 1000);
        table.put(k, "X", Double.NaN);
    }
    // Add some values to the table
    for (; k < 90; k++) {
        table.put(k, Filter.TIMESTAMP_COLUMN_NAME, (double) k * 1000);
        table.put(k, "X", (double) k);
    }
    // Verify the initial size
    Assert.assertEquals(90, table.rowKeySet().size());
    // Apply the filter
    getFilterEngine().filter(filterDef, table);
    // Verify
    Assert.assertEquals(30, table.rowKeySet().size());
    for (long i = 0; i < 5; i++) {
        Assert.assertEquals((double) (i + 60) * 1000, table.get(i, Filter.TIMESTAMP_COLUMN_NAME), 0.0001);
        Assert.assertEquals((double) (i + 60), table.get(i, "X"), 0.0001);
    }
}
Also used : FilterDef(org.opennms.netmgt.measurements.model.FilterDef) Test(org.junit.Test)

Example 10 with FilterDef

use of org.opennms.netmgt.measurements.model.FilterDef in project opennms by OpenNMS.

the class ChompTest method doesntFailOnEmtpyDs.

@Test
public void doesntFailOnEmtpyDs() throws Exception {
    FilterDef filterDef = new FilterDef("Chomp");
    RowSortedTable<Long, String, Double> table = TreeBasedTable.create();
    getFilterEngine().filter(filterDef, table);
}
Also used : FilterDef(org.opennms.netmgt.measurements.model.FilterDef) Test(org.junit.Test)

Aggregations

FilterDef (org.opennms.netmgt.measurements.model.FilterDef)15 Test (org.junit.Test)13 Source (org.opennms.netmgt.measurements.model.Source)2 HashMap (java.util.HashMap)1 FilterException (org.opennms.netmgt.measurements.api.exceptions.FilterException)1 ValidationException (org.opennms.netmgt.measurements.api.exceptions.ValidationException)1 Expression (org.opennms.netmgt.measurements.model.Expression)1 QueryRequest (org.opennms.netmgt.measurements.model.QueryRequest)1 QueryResponse (org.opennms.netmgt.measurements.model.QueryResponse)1