List of usage examples for com.google.common.collect ImmutableTable rowKeySet
@Override
public ImmutableSet<R> rowKeySet()
From source file:org.sonar.server.setting.ws.Setting.java
private static List<Map<String, String>> buildPropertySetValuesAsMap(String propertyKey, List<PropertyDto> propertySets) { if (propertySets.isEmpty()) { return Collections.emptyList(); }//from ww w . j a v a 2s . c om ImmutableTable.Builder<String, String, String> tableBuilder = new ImmutableTable.Builder<>(); propertySets.forEach(property -> { String keyWithoutSettingKey = property.getKey().replace(propertyKey + ".", ""); List<String> setIdWithFieldKey = DOT_SPLITTER.splitToList(keyWithoutSettingKey); String setId = setIdWithFieldKey.get(0); String fieldKey = keyWithoutSettingKey.replaceFirst(setId + ".", ""); tableBuilder.put(setId, fieldKey, property.getValue()); }); ImmutableTable<String, String, String> table = tableBuilder.build(); return table.rowKeySet().stream().map(table::row).collect(Collectors.toList()); }
From source file:org.sonar.server.settings.ws.Setting.java
private static List<Map<String, String>> buildPropertySetValuesAsMap(String propertyKey, List<PropertyDto> propertySets) { if (propertySets.isEmpty()) { return Collections.emptyList(); }//from w w w. j a va 2 s . co m ImmutableTable.Builder<String, String, String> tableBuilder = new ImmutableTable.Builder<>(); propertySets.forEach(property -> { List<String> setIdWithFieldKey = DOT_SPLITTER .splitToList(property.getKey().replace(propertyKey + ".", "")); String setId = setIdWithFieldKey.get(0); String fieldKey = setIdWithFieldKey.get(1); tableBuilder.put(setId, fieldKey, property.getValue()); }); ImmutableTable<String, String, String> table = tableBuilder.build(); return table.rowKeySet().stream().map(table::row).collect(Collectors.toList()); }
From source file:net.sf.e4ftrace.handlers.AboutHandler.java
@Execute public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell) { try {//from w ww . ja v a 2 s. c o m long timeStart = System.currentTimeMillis(); ImmutableTable<Integer, Short, ITrace> data = traceService.fetch(active_trace_uri, 0); long delta = System.currentTimeMillis() - timeStart; UnmodifiableIterator<Integer> it = data.rowKeySet().iterator(); while (it.hasNext()) { int atomId = it.next(); String name = TraceBiMap.getStringValue(atomId); System.out.println("AboutHandler : name : " + name); } MessageDialog.openInformation(shell, "About", "time use to load : " + delta); } catch (ExecutionException e) { e.printStackTrace(); } }
From source file:org.opennms.netmgt.jasper.analytics.HWForecast.java
@Override public void filter(RowSortedTable<Integer, String, Double> table) throws RScriptException { Preconditions.checkArgument(table.containsColumn("Timestamp"), "Data source must have a 'Timestamp' column."); // Determine the index of the first and last non-NaN values // Assume the values between these are contiguous Point rowsWithValues = DataSourceUtils.getRowsWithValues(table, m_config.getInputColumn()); int firstRowWithValues = rowsWithValues.x; int lastRowWithValues = rowsWithValues.y; // Make sure we have some samples int numSampleRows = lastRowWithValues - firstRowWithValues; if (numSampleRows < 1) { LOG.error("Insufficent values in column for forecasting. Excluding forecast columns from data source."); return;/*from w w w.jav a 2s .c o m*/ } // Determine the step size Date lastTimestamp = new Date(table.get(lastRowWithValues, "Timestamp").longValue()); long stepInMs = (long) (table.get(lastRowWithValues, "Timestamp") - table.get(lastRowWithValues - 1, "Timestamp")); // Calculate the number of samples per period int numSamplesPerPeriod = (int) Math.floor(m_config.getPeriod() * 1000 / stepInMs); numSamplesPerPeriod = Math.max(1, numSamplesPerPeriod); // Calculate the number of steps to forecast int numForecasts = numSamplesPerPeriod * m_config.getNumPeriodsToForecast(); // Script arguments Map<String, Object> arguments = Maps.newHashMap(); arguments.put("columnToForecast", m_config.getInputColumn()); arguments.put("numSamplesPerSeason", numSamplesPerPeriod); arguments.put("numForecasts", numForecasts); arguments.put("confidenceLevel", m_config.getConfidenceLevel()); // Array indices in R start at 1 arguments.put("firstIndex", firstRowWithValues + 1); arguments.put("lastIndex", lastRowWithValues + 1); // Make the forecasts RScriptExecutor executor = new RScriptExecutor(); RScriptOutput output = executor.exec(PATH_TO_R_SCRIPT, new RScriptInput(table, arguments)); ImmutableTable<Integer, String, Double> outputTable = output.getTable(); // The output table contains the fitted values, followed // by the requested number of forecasted values int numOutputRows = outputTable.rowKeySet().size(); int numFittedValues = numOutputRows - numForecasts; // Add the fitted values to rows where the input column has values for (int i = 0; i < numFittedValues; i++) { int idxTarget = i + (numSampleRows - numFittedValues) + firstRowWithValues + 1; table.put(idxTarget, m_config.getOutputPrefix() + "Fit", outputTable.get(i, "fit")); } // Append the forecasted values and include the time stamp with the appropriate step for (int i = numFittedValues; i < numOutputRows; i++) { int idxForecast = i - numFittedValues + 1; int idxTarget = lastRowWithValues + idxForecast; table.put(idxTarget, m_config.getOutputPrefix() + "Fit", outputTable.get(i, "fit")); table.put(idxTarget, m_config.getOutputPrefix() + "Lwr", outputTable.get(i, "lwr")); table.put(idxTarget, m_config.getOutputPrefix() + "Upr", outputTable.get(i, "upr")); table.put(idxTarget, "Timestamp", (double) new Date(lastTimestamp.getTime() + stepInMs * idxForecast).getTime()); } }
From source file:org.opennms.netmgt.measurements.filters.impl.HWForecast.java
@Override public void filter(RowSortedTable<Long, String, Double> table) throws RScriptException { Preconditions.checkArgument(table.containsColumn(TIMESTAMP_COLUMN_NAME), String.format("Data source must have a '%s' column.", Filter.TIMESTAMP_COLUMN_NAME)); // Determine the index of the first and last non-NaN values // Assume the values between these are contiguous TableLimits limits = Utils.getRowsWithValues(table, m_inputColumn); // Make sure we have some samples long numSampleRows = limits.lastRowWithValues - limits.firstRowWithValues; if (numSampleRows < 1) { LOG.error(/*from w w w.j a va 2 s. co m*/ "Insufficient values in column for forecasting. Excluding forecast columns from data source."); return; } // Determine the step size Date lastTimestamp = new Date(table.get(limits.lastRowWithValues, TIMESTAMP_COLUMN_NAME).longValue()); long stepInMs = (long) (table.get(limits.lastRowWithValues, TIMESTAMP_COLUMN_NAME) - table.get(limits.lastRowWithValues - 1, Filter.TIMESTAMP_COLUMN_NAME)); // Calculate the number of samples per period int numSamplesPerPeriod = (int) Math.floor(m_periodInSeconds * 1000 / stepInMs); numSamplesPerPeriod = Math.max(1, numSamplesPerPeriod); // Calculate the number of steps to forecast int numForecasts = numSamplesPerPeriod * m_numPeriodsToForecast; // Script arguments Map<String, Object> arguments = Maps.newHashMap(); arguments.put("columnToForecast", m_inputColumn); arguments.put("numSamplesPerSeason", numSamplesPerPeriod); arguments.put("numForecasts", numForecasts); arguments.put("confidenceLevel", m_confidenceLevel); // Array indices in R start at 1 arguments.put("firstIndex", limits.firstRowWithValues + 1); arguments.put("lastIndex", limits.lastRowWithValues + 1); // Make the forecasts RScriptExecutor executor = new RScriptExecutor(); RScriptOutput output = executor.exec(PATH_TO_R_SCRIPT, new RScriptInput(table, arguments)); ImmutableTable<Long, String, Double> outputTable = output.getTable(); // The output table contains the fitted values, followed // by the requested number of forecasted values int numOutputRows = outputTable.rowKeySet().size(); int numFittedValues = numOutputRows - numForecasts; // Add the fitted values to rows where the input column has values for (long i = 0; i < numFittedValues; i++) { long idxTarget = i + (numSampleRows - numFittedValues) + limits.firstRowWithValues + 1; table.put(idxTarget, m_outputPrefix + "Fit", outputTable.get(i, "fit")); } // Append the forecasted values and include the time stamp with the appropriate step for (long i = numFittedValues; i < numOutputRows; i++) { long idxForecast = i - numFittedValues + 1; long idxTarget = limits.lastRowWithValues + idxForecast; if (m_confidenceLevel > 0) { table.put(idxTarget, m_outputPrefix + "Fit", outputTable.get(i, "fit")); table.put(idxTarget, m_outputPrefix + "Lwr", outputTable.get(i, "lwr")); table.put(idxTarget, m_outputPrefix + "Upr", outputTable.get(i, "upr")); } table.put(idxTarget, TIMESTAMP_COLUMN_NAME, (double) new Date(lastTimestamp.getTime() + stepInMs * idxForecast).getTime()); } }
From source file:net.sf.e4ftrace.ui.model.TraceModelImplFactory.java
public TraceImpl[] createFTraces(TraceService traceService, URI uri) throws ExecutionException { ImmutableTable<Integer, Short, ITrace> data = traceService.fetch(uri, 0); UnmodifiableIterator<Integer> it = data.rowKeySet().iterator(); ArrayList<TraceImpl> rList = Lists.<TraceImpl>newArrayList(); Random random = new Random(); /* While Tasks */ while (it.hasNext()) { int atomId = it.next(); String name = TraceBiMap.getStringValue(atomId); ImmutableMap<Short, ITrace> traces = data.row(atomId); UnmodifiableIterator<Short> ck = traces.keySet().iterator(); /* While Cores */ while (ck.hasNext()) { short cpuid = ck.next(); ITrace trace = traces.get(cpuid); TraceImpl traceImpl = new TraceImpl(name, name); Iterator<IEvent> ei = trace.getEventsIterator(); long prevStamp = 0; EventImpl prevEventImpl = null; TreeSet<Long> tsSet = Sets.<Long>newTreeSet(); /* While Events */ while (ei.hasNext()) { IEvent event = ei.next(); long timestamp = event.getTime(); tsSet.add(timestamp);//from w ww.j av a2s.c o m int type = random.nextInt(8) % 7; EventImpl eventImpl = new EventImpl(timestamp, traceImpl, getEventType(type)); if (prevStamp != 0) { long duration = timestamp - prevStamp; prevEventImpl.setDuration(duration); traceImpl.addTraceEvent(prevEventImpl); } prevStamp = timestamp; prevEventImpl = eventImpl; } long timeStart = tsSet.first(); long timeEnd = tsSet.last(); traceImpl.setStartTime(timeStart); traceImpl.setStopTime(timeEnd); rList.add(traceImpl); } } TraceImpl[] ra = rList.toArray(new TraceImpl[rList.size()]); return ra; }