use of org.opennms.netmgt.measurements.model.FilterDef in project opennms by OpenNMS.
the class PercentileTest method canCaculatePercentile.
@Test
public void canCaculatePercentile() throws Exception {
FilterDef filterDef = new FilterDef("Percentile", "inputColumn", "X", "outputColumn", "Y", "quantile", Double.valueOf(quantile).toString());
RowSortedTable<Long, String, Double> table = TreeBasedTable.create();
// Add some values to the table
for (int k = 0; k < values.length; k++) {
table.put(Long.valueOf(k), Filter.TIMESTAMP_COLUMN_NAME, (double) k * 1000);
table.put(Long.valueOf(k), "X", values[k]);
}
// Apply the filter
getFilterEngine().filter(filterDef, table);
// Verify
Assert.assertEquals(values.length, table.rowKeySet().size());
for (long k = 0; k < values.length; k++) {
Assert.assertEquals((double) k * 1000, table.get(k, Filter.TIMESTAMP_COLUMN_NAME), 0.0001);
Assert.assertEquals(expected, table.get(k, "Y"), 0.0001);
}
}
use of org.opennms.netmgt.measurements.model.FilterDef in project opennms by OpenNMS.
the class MeasurementsRestServiceWithJrbIT method canApplyFilters.
@Test
public void canApplyFilters() {
QueryRequest request = new QueryRequest();
request.setStart(1414602000000L);
request.setEnd(1418046400000L);
request.setStep(1000L);
request.setMaxRows(700);
Source ifInOctets = new Source();
ifInOctets.setResourceId("node[1].interfaceSnmp[eth0-04013f75f101]");
ifInOctets.setAttribute("ifInOctets");
ifInOctets.setAggregation("MAX");
ifInOctets.setLabel("ifInOctets");
request.setSources(Lists.newArrayList(ifInOctets));
// Apply a chomp filter - cutting some of the first row off, and the trailing NaNs
FilterDef chompFilter = new FilterDef("Chomp", "cutoffDate", "1414630000.0", "stripNaNs", "true");
request.setFilters(Lists.newArrayList(chompFilter));
LOG.debug(JaxbUtils.marshal(request));
QueryResponse response = m_svc.query(request);
// Verify the values for the first and last rows
final Map<String, double[]> columns = response.columnsWithLabels();
double[] ifInOctetsColumn = columns.get("ifInOctets");
assertEquals(67872.22455490529, ifInOctetsColumn[0], 0.0001);
assertEquals(1649961.9593111263, ifInOctetsColumn[ifInOctetsColumn.length - 1], 0.0001);
}
use of org.opennms.netmgt.measurements.model.FilterDef in project opennms by OpenNMS.
the class ChompTest method canStripNaNs.
@Test
public void canStripNaNs() throws Exception {
FilterDef filterDef = new FilterDef("Chomp", "stripNaNs", "true");
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);
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);
table.put(k, "X", (double) k);
}
// Add some more NaNs
for (; k < 100; k++) {
table.put(k, Filter.TIMESTAMP_COLUMN_NAME, (double) k);
table.put(k, "X", Double.NaN);
}
// Apply the filter
getFilterEngine().filter(filterDef, table);
// Verify
Assert.assertEquals(80, table.rowKeySet().size());
for (long i = 0; i < 80; i++) {
Assert.assertEquals((double) (i + 10), table.get(i, Filter.TIMESTAMP_COLUMN_NAME), 0.0001);
Assert.assertEquals((double) (i + 10), table.get(i, "X"), 0.0001);
}
}
use of org.opennms.netmgt.measurements.model.FilterDef in project opennms by OpenNMS.
the class HWForecastIT method canForecastValues.
@Test
public void canForecastValues() throws Exception {
FilterDef filterDef = new FilterDef("HoltWinters", "outputPrefix", "HW", "inputColumn", "X", "numPeriodsToForecast", "12", "periodInSeconds", "1", "confidenceLevel", "0.95");
// 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, "X", 1.0d);
}
// Make the forecasts
getFilterEngine().filter(filterDef, table);
// Original size + 12 forecasts
Assert.assertEquals(112, table.rowKeySet().size());
// The timestamps should be continuous
for (long i = 0; i < 112; i++) {
Assert.assertEquals((double) (i * 1000), table.get(i, Filter.TIMESTAMP_COLUMN_NAME), 0.0001);
}
// The forecasted value should be constant
for (long i = 100; i < 112; i++) {
Assert.assertEquals(1.0d, table.get(i, "HWFit"), 0.0001);
Assert.assertEquals(1.0d, table.get(i, "HWLwr"), 0.0001);
Assert.assertEquals(1.0d, table.get(i, "HWUpr"), 0.0001);
}
}
use of org.opennms.netmgt.measurements.model.FilterDef in project opennms by OpenNMS.
the class OutlierFilterIT method canInterpolateLargeGaps.
@Test
public void canInterpolateLargeGaps() throws Exception {
FilterDef filterDef = new FilterDef("Outlier", "inputColumn", "Y", "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) i);
table.put(i, "Y", Double.NaN);
}
// Add a value near the middle, and near the ned
table.put(42L, "Y", 1.0d);
table.put(95L, "Y", 1.0d);
// Apply the filter
getFilterEngine().filter(filterDef, table);
// Verify
for (long i = 0; i < 42; i++) {
Assert.assertEquals((double) i, table.get(i, "X"), 0.0001);
Assert.assertEquals(Double.NaN, table.get(i, "Y"), 0.0001);
}
for (long i = 42; i < 96; i++) {
Assert.assertEquals((double) i, table.get(i, "X"), 0.0001);
Assert.assertEquals(1.0d, table.get(i, "Y"), 0.0001);
}
for (long i = 96; i < 100; i++) {
Assert.assertEquals((double) i, table.get(i, "X"), 0.0001);
Assert.assertEquals(Double.NaN, table.get(i, "Y"), 0.0001);
}
}
Aggregations