List of usage examples for com.google.common.collect RowSortedTable rowKeySet
@Override SortedSet<R> rowKeySet();
This method returns a SortedSet , instead of the Set specified in the Table interface.
From source file:org.opennms.netmgt.integrations.R.RScriptExecutor.java
/** * Convert the table to a CSV string./* w ww.j ava2s . c o m*/ */ protected static StringBuilder toCsv(final RowSortedTable<Long, String, Double> table) throws IOException { final String columnNames[] = table.columnKeySet().toArray(new String[] {}); final StringBuilder sb = new StringBuilder(); final CSVPrinter printer = CSVFormat.RFC4180.withHeader(columnNames).print(sb); for (long rowIndex : table.rowKeySet()) { for (String columnName : columnNames) { Double value = table.get(rowIndex, columnName); if (value == null) { value = Double.NaN; } printer.print(value); } printer.println(); } return sb; }
From source file:org.opennms.netmgt.jasper.analytics.Chomp.java
@Override public void filter(RowSortedTable<Integer, String, Double> dsAsTable) throws Exception { int numRowsInTable = dsAsTable.rowKeySet().size(); int lastRowToKeep = numRowsInTable; int firstRowToKeep = lastRowToKeep; // Determine the index of the first row with a timestamp // on/after the cutoff date for (int k : dsAsTable.rowKeySet()) { if (dsAsTable.get(k, "Timestamp") >= m_config.getCutoffDate()) { firstRowToKeep = k;/* www. j av a 2 s .com*/ break; } } if (m_config.getStripNaNs()) { // Excluding the Timestamp column, determine the // index of the first and last rows which don't contain // completely NaN values Set<String> columnNamesNoTs = Sets.newHashSet(dsAsTable.columnKeySet()); columnNamesNoTs.remove("Timestamp"); Point rowsWithValues = DataSourceUtils.getRowsWithValues(dsAsTable, columnNamesNoTs.toArray(new String[0])); firstRowToKeep = Math.max(firstRowToKeep, rowsWithValues.x); lastRowToKeep = Math.min(lastRowToKeep, rowsWithValues.y); } Set<String> columnNames = Sets.newHashSet(dsAsTable.columnKeySet()); // Remove all of the trailing rows for (int i = lastRowToKeep + 1; i < numRowsInTable; i++) { for (String columnName : columnNames) { dsAsTable.remove(i, columnName); } } // Remove all of the leading rows for (int i = 0; i < firstRowToKeep; i++) { for (String columnName : columnNames) { dsAsTable.remove(i, columnName); } } // Bump up the indices on the remaining rows if (firstRowToKeep > 0) { int j = 0; for (int i = firstRowToKeep; i <= lastRowToKeep; i++) { for (String columnName : columnNames) { Double value = dsAsTable.get(i, columnName); if (value != null) { dsAsTable.put(j, columnName, value); } dsAsTable.remove(i, columnName); } j++; } } }
From source file:org.opennms.netmgt.measurements.filters.impl.Chomp.java
@Override public void filter(RowSortedTable<Long, String, Double> qrAsTable) throws Exception { int numRowsInTable = qrAsTable.rowKeySet().size(); long lastRowToKeep = numRowsInTable; long firstRowToKeep = lastRowToKeep; // Determine the index of the first row with a timestamp // on/after the cutoff date for (long k : qrAsTable.rowKeySet()) { if (qrAsTable.get(k, TIMESTAMP_COLUMN_NAME) >= m_cutoffDate) { firstRowToKeep = k;// ww w . jav a 2 s . c o m break; } } if (m_stripNaNs) { // Excluding the timestamp column, determine the // index of the first and last rows which don't contain // completely NaN values Set<String> columnNamesNoTs = Sets.newHashSet(qrAsTable.columnKeySet()); columnNamesNoTs.remove(TIMESTAMP_COLUMN_NAME); TableLimits limits = Utils.getRowsWithValues(qrAsTable, columnNamesNoTs.toArray(new String[0])); firstRowToKeep = Math.max(firstRowToKeep, limits.firstRowWithValues); lastRowToKeep = Math.min(lastRowToKeep, limits.lastRowWithValues); } Set<String> columnNames = Sets.newHashSet(qrAsTable.columnKeySet()); // Remove all of the trailing rows for (long i = lastRowToKeep + 1; i < numRowsInTable; i++) { for (String columnName : columnNames) { qrAsTable.remove(i, columnName); } } // Remove all of the leading rows for (long i = 0; i < firstRowToKeep; i++) { for (String columnName : columnNames) { qrAsTable.remove(i, columnName); } } // Bump up the indices on the remaining rows if (firstRowToKeep > 0) { long j = 0; for (long i = firstRowToKeep; i <= lastRowToKeep; i++) { for (String columnName : columnNames) { Double value = qrAsTable.get(i, columnName); if (value != null) { qrAsTable.put(j, columnName, value); } qrAsTable.remove(i, columnName); } j++; } } }
From source file:demo.project.ExportTable.java
/** * @param w// w ww . j ava 2 s . com * @param ranker */ private void dumpHeader(PrintWriter w, ColumnRanker ranker) { w.append("Item"); RowSortedTable<Integer, Integer, String> headers = TreeBasedTable.create(); int r = 0; int c = 0; for (Iterator<ARankColumnModel> it = table.getColumnsOf(ranker); it.hasNext();) { ARankColumnModel col = it.next(); headers.put(r, c++, col.getLabel()); if (col instanceof ACompositeRankColumnModel) c = addAll(headers, r, c, (ACompositeRankColumnModel) col); } for (int row : headers.rowKeySet()) { for (int j = 0; j < c; ++j) { String l = headers.get(row, j); w.append('\t'); if (l != null) w.append(l); } w.println(); } }
From source file:org.opennms.netmgt.jasper.analytics.StripNaNs.java
@Override public void filter(RowSortedTable<Integer, String, Double> dsAsTable) throws Exception { // Excluding the Timestamp column, determine the // index of the first and last rows which don't contain // completely NaN values Set<String> columnNames = Sets.newHashSet(dsAsTable.columnKeySet()); columnNames.remove("Timestamp"); Point rowsWithValues = DataSourceUtils.getRowsWithValues(dsAsTable, columnNames.toArray(new String[0])); int firstRowWithValues = rowsWithValues.x; int lastRowWithValues = rowsWithValues.y; int numRowsInTable = dsAsTable.rowKeySet().size(); columnNames = Sets.newHashSet(dsAsTable.columnKeySet()); // Remove all of the trailing NaN rows for (int i = lastRowWithValues + 1; i < numRowsInTable; i++) { for (String columnName : columnNames) { dsAsTable.remove(i, columnName); }/* w ww .j a v a 2 s . co m*/ } // Remove all of the leading NaN rows for (int i = 0; i < firstRowWithValues; i++) { for (String columnName : columnNames) { dsAsTable.remove(i, columnName); } } // Bump up the indices on the remaining rows if (firstRowWithValues > 0) { int j = 0; for (int i = firstRowWithValues; i <= lastRowWithValues; i++) { for (String columnName : columnNames) { Double value = dsAsTable.get(i, columnName); if (value != null) { dsAsTable.put(j, columnName, value); } dsAsTable.remove(i, columnName); } j++; } } }
From source file:org.opennms.netmgt.jasper.analytics.OutlierFilter.java
@Override public void filter(RowSortedTable<Integer, String, Double> dsAsTable) throws RScriptException { String columnToFilter = m_config.getInputColumn(); Map<String, Object> arguments = Maps.newHashMap(); arguments.put("columnToFilter", columnToFilter); arguments.put("probability", m_config.getProbability()); RScriptExecutor executor = new RScriptExecutor(); RScriptOutput output = executor.exec(PATH_TO_R_SCRIPT, new RScriptInput(dsAsTable, arguments)); ImmutableTable<Integer, String, Double> outputTable = output.getTable(); // Replace all of the values in the given column with those returned // by the script int numRowsInTable = dsAsTable.rowKeySet().size(); for (int i = 0; i < numRowsInTable; i++) { dsAsTable.put(i, columnToFilter, outputTable.get(i, columnToFilter)); }//from w w w. ja v a 2 s.c o m }